-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new "quickstart" samples. #174
Changes from 1 commit
331c184
78c821b
16982ac
8196545
0158ed9
09e2cb1
9340a8b
ac14b65
27e54e5
fd64f8b
124566c
59f9085
21eaaa6
d187637
8850d29
dc00f27
b7bda05
a772cd1
ff6a9c4
eda129e
4a2c81f
bc4e224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2016 Google Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<phpunit bootstrap="test/bootstrap.php"> | ||
<testsuites> | ||
<testsuite name="Google BigQuery Quickstart Tests"> | ||
<directory>test</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
<filter> | ||
<whitelist> | ||
<file>quickstart.php</file> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Copyright 2015 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
class quickstartTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testQuickstart() | ||
{ | ||
$datasetId = 'my_new_dataset_' . time(); | ||
$file = sys_get_temp_dir() . '/quickstart_quickstart.php'; | ||
$contents = file_get_contents(__DIR__ . '/../quickstart.php'); | ||
$contents = str_replace( | ||
['my_new_dataset', '__DIR__'], | ||
[$datasetId, sprintf('"%s/.."', __DIR__)], | ||
$contents | ||
); | ||
file_put_contents($file, $contents); | ||
|
||
// Invoke quickstart.php | ||
$dataset = include $file; | ||
|
||
// Make sure it looks correct | ||
$this->assertInstanceOf('Google\Cloud\BigQuery\Dataset', $dataset); | ||
$this->assertEquals($datasetId, $dataset->id()); | ||
$dataset->delete(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2016 Google Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<phpunit bootstrap="test/bootstrap.php"> | ||
<testsuites> | ||
<testsuite name="Google Datastore Quickstart Tests"> | ||
<directory>test</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
<filter> | ||
<whitelist> | ||
<file>quickstart.php</file> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,17 @@ | |
# Imports the Google Cloud client library | ||
use Google\Cloud\Datastore\DatastoreClient; | ||
|
||
# Your Google Cloud Platform project ID | ||
$projectId = 'YOUR_PROJECT_ID'; | ||
|
||
# Instantiates a client | ||
$datastoreClient = new DatastoreClient([ | ||
'projectId' => $projectId | ||
]); | ||
$datastore = new DatastoreClient(); | ||
|
||
# The kind of the entity to retrieve | ||
$kind = 'Task'; | ||
# The id of the entity to retrieve | ||
$id = 1234567890; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit controversial to manually assign the numeric id (since you need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we call "lookup" instead of "upsert" here, and maybe use a name instead of ID, would that be more appropriate? $kind = 'Person';
$name = 'Bob';
$key = $datastore->key($kind, $name);
$entity = $datastore->lookup($key); |
||
# The Datastore key for the entity | ||
$taskKey = $datastoreClient->key($kind, $id); | ||
$taskKey = $datastore->key($kind, $id); | ||
|
||
# Retrieves the entity | ||
$dataset = $datastoreClient->lookup($taskKey); | ||
$entity = $datastore->entity($taskKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't retrieve the entity, it just creates a local There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right. What do you think we should do for this test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd create the key with named id and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other language samples do what this sample does. But I agree this is not a good sample. @jmdobry thoughts on changing this to an |
||
# [END datastore_quickstart] | ||
return $entity; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Copyright 2015 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
class quickstartTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testQuickstart() | ||
{ | ||
$file = sys_get_temp_dir() . '/datastore_quickstart.php'; | ||
$contents = file_get_contents(__DIR__ . '/../quickstart.php'); | ||
$contents = str_replace( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need to replace anything There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh, good point |
||
['__DIR__'], | ||
[sprintf('"%s/.."', __DIR__)], | ||
$contents | ||
); | ||
file_put_contents($file, $contents); | ||
|
||
// Invoke quickstart.php | ||
$entity = include $file; | ||
|
||
// Make sure it looks correct | ||
$this->assertInstanceOf('Google\Cloud\Datastore\Entity', $entity); | ||
|
||
$key = $entity->key(); | ||
$path = $key->path(); | ||
$this->assertEquals('Task', $path[0]['kind']); | ||
$this->assertEquals(1234567890, $path[0]['id']); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"require": { | ||
"php": ">=5.4", | ||
"google/cloud": "0.9" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it more appropriate to call
delete()
intearDown
or something?