Skip to content
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

Move shared testing code into core #822

Merged
merged 43 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8143806
manual changes
michaelbausor Dec 22, 2017
d7742e4
Grpc trait rename
michaelbausor Dec 22, 2017
e267e07
Rename key storage trait
michaelbausor Dec 22, 2017
233156e
Rename stub
michaelbausor Dec 22, 2017
f393c70
Rename impl
michaelbausor Dec 22, 2017
da1dc86
Rename snippet tests
michaelbausor Dec 22, 2017
902be47
Rename stub
michaelbausor Dec 23, 2017
307f0ed
Rename SystemTestCase
michaelbausor Dec 23, 2017
44a1c7e
Rename DeletionQueue
michaelbausor Dec 23, 2017
7029491
Move fixtures
michaelbausor Dec 28, 2017
d589514
Rename stub and impl
michaelbausor Dec 28, 2017
6d52f27
Fix locking and fixtures
michaelbausor Dec 28, 2017
a1f8aec
Fixes
michaelbausor Dec 28, 2017
e5c3569
Merge branch 'master' into move-shared-into-core
michaelbausor Jan 5, 2018
0b0f30e
Restructure MockGlobals, update fixtures
michaelbausor Jan 5, 2018
84b2b22
Fix phpcs errors
michaelbausor Jan 5, 2018
d929d42
Fix snippet tests
michaelbausor Jan 5, 2018
2669893
Merge branch 'master' into move-shared-into-core
michaelbausor Jan 5, 2018
668295a
Add comments to support doc building
michaelbausor Jan 5, 2018
75722a2
Exclude MockValues from side effects phpcs rule
michaelbausor Jan 5, 2018
7134422
Update StubTrait
michaelbausor Jan 10, 2018
e7b1fc7
Remove Storage dependency from StreamableUploaderTest
michaelbausor Jan 10, 2018
71cb2b0
Move code out of dev
michaelbausor Jan 10, 2018
4f87b74
Add snippet testing of parser
michaelbausor Jan 10, 2018
e8751c3
Update Iam
michaelbausor Jan 11, 2018
520cf29
Handle servicebuilder tests
michaelbausor Jan 11, 2018
e76b08f
Add internal and experimental annotations
michaelbausor Jan 11, 2018
c6e4837
Add README to testing directory
michaelbausor Jan 11, 2018
9673c49
Merge branch 'master' into move-shared-into-core
michaelbausor Jan 11, 2018
a60255b
Fix phpcs errors
michaelbausor Jan 12, 2018
c2d88c3
Fix import for doc gen
michaelbausor Jan 12, 2018
5a9d835
Add comments to new code in Core/Testing
michaelbausor Jan 12, 2018
d74c478
Merge branch 'master' into move-shared-into-core
michaelbausor Jan 23, 2018
da17de0
Update after merge
michaelbausor Jan 23, 2018
a8e503a
Merge branch 'master' into move-shared-into-core
michaelbausor Jan 30, 2018
19b6867
Address PR comments
michaelbausor Jan 30, 2018
803368d
Merge branch 'master' into move-shared-into-core
michaelbausor Jan 30, 2018
5f6d92a
Fix reference to impl
michaelbausor Jan 31, 2018
ec12d53
Address PR feedback
michaelbausor Jan 31, 2018
e98e0c6
Exclude Core/Testing from unit tests
michaelbausor Jan 31, 2018
a12ce04
Remove extra space
michaelbausor Jan 31, 2018
d99d600
Merge branch 'master' into move-shared-into-core
michaelbausor Jan 31, 2018
8200a4b
Rename Functions to TestHelpers
michaelbausor Jan 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@
"Google\\Cloud\\Tests\\System\\": "tests/system",
"Google\\Cloud\\Tests\\Unit\\": "tests/unit"
},
"files": [
"dev/src/Functions.php"
],
"classmap": [
"tests/conformance-fixtures"
]
Expand All @@ -127,4 +124,4 @@
]
}
}
}
}
59 changes: 0 additions & 59 deletions dev/src/Functions.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Google\Cloud\Tests;
namespace Google\Cloud\Core\Testing;

use Prophecy\Argument\Token\TokenInterface;
use Prophecy\Util\StringUtil;
Expand Down
78 changes: 78 additions & 0 deletions src/Core/Testing/Functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* Copyright 2017 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.
*/

namespace Google\Cloud\Core\Testing;

class Functions

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

{
/**
* Create a test stub which extends a real class and allows overriding of private properties.
*
* @param string $extends The fully-qualified name of the class to extend.
* @param array $args An array of constructor arguments to use when creating the stub.
* @param array $props A list of private properties on which to enable overrriding.
* @return mixed
*/
public static function stub($extends, array $args = [], array $props = [])
{
if (empty($props)) {
$props = ['connection'];
}

$tpl = 'class %s extends %s {private $___props = \'%s\'; use \Google\Cloud\Dev\StubTrait; }';

$name = 'Stub' . sha1($extends);

if (!class_exists($name)) {
eval(sprintf($tpl, $name, $extends, json_encode($props)));
}

$reflection = new \ReflectionClass($name);
return $reflection->newInstanceArgs($args);
}

/**
* Get a trait implementation.
*
* @param string $trait The fully-qualified name of the trait to implement.
* @return mixed
*/
public static function impl($trait, array $props = [])
{
$properties = [];
foreach ($props as $prop) {
$properties[] = 'private $' . $prop . ';';
}

$tpl = 'class %s {
use %s;
use \Google\Cloud\Dev\StubTrait;
private $___props = \'%s\';
%s
public function call($fn, array $args = []) { return call_user_func_array([$this, $fn], $args); }
}';

$name = 'Trait' . sha1($trait . json_encode($props));

if (!class_exists($name)) {
eval(sprintf($tpl, $name, $trait, json_encode($props), implode("\n", $properties)));
}

return new $name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

namespace Google\Cloud\Tests;
namespace Google\Cloud\Core\Testing;

/**
* Provides checks for whether to run gRPC tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

namespace Google\Cloud\Tests;
namespace Google\Cloud\Core\Testing;

use Google\Cloud\Storage\EncryptionTrait;
use phpseclib\Crypt\RSA;
Expand Down
21 changes: 21 additions & 0 deletions src/Core/Testing/Lock/Functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* Copyright 2017 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.
*/

use Google\Cloud\Core\Testing\Lock\MockValues;


Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
<?php

/**
* Copyright 2017 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.
*/

namespace Google\Cloud\Core\Lock {

class MockValues
{
public static $flockReturnValue;
Expand All @@ -12,17 +29,18 @@ class MockValues
public static function initialize()
{
self::$flockReturnValue = true;
self::$fopenReturnValue = function($file, $mode) {
self::$fopenReturnValue = function ($file, $mode) {
return \fopen($file, $mode);
};
self::$sem_acquireReturnValue = true;
self::$sem_releaseReturnValue = true;
self::$sem_getReturnValue = function($key) {
self::$sem_getReturnValue = function ($key) {
return \sem_get($key);
};
}
}


function flock($handle, $type)
{
return MockValues::$flockReturnValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

namespace Google\Cloud\Dev\Snippet;
namespace Google\Cloud\Core\Testing\Snippet;

use Google\Cloud\Dev\Snippet\Container;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

namespace Google\Cloud\Tests\System;
namespace Google\Cloud\Core\Testing\System;

use Google\Cloud\Core\Exception\NotFoundException;
use Google\Cloud\Core\ExponentialBackoff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* limitations under the License.
*/

namespace Google\Cloud\Tests\System;
namespace Google\Cloud\Core\Testing\System;

use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\Core\ExponentialBackoff;
use Google\Cloud\PubSub\PubSubClient;
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Tests\System\DeletionQueue;
use Google\Cloud\Core\Testing\System\DeletionQueue;
use PHPUnit\Framework\TestCase;

class SystemTestCase extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/conformance/FirestoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FirestoreTest extends TestCase

public function setUp()
{
$this->client = \Google\Cloud\Dev\stub(FirestoreClient::class, [
$this->client = \Google\Cloud\Core\Testing\Functions::stub(FirestoreClient::class, [
[
'projectId' => 'projectID'
]
Expand Down
4 changes: 2 additions & 2 deletions tests/snippets/BigQuery/BigQueryClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use Google\Cloud\BigQuery\ValueMapper;
use Google\Cloud\Core\Int64;
use Google\Cloud\Core\Iterator\ItemIterator;
use Google\Cloud\Dev\Snippet\SnippetTestCase;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;
use Prophecy\Argument;

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ class BigQueryClientTest extends SnippetTestCase
public function setUp()
{
$this->connection = $this->prophesize(ConnectionInterface::class);
$this->client = \Google\Cloud\Dev\stub(BigQueryTestClient::class);
$this->client = \Google\Cloud\Core\Testing\Functions::stub(BigQueryTestClient::class);
$this->client->___setProperty('connection', $this->connection->reveal());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/BigQuery/BytesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace Google\Cloud\Tests\Snippets\BigQuery;

use Google\Cloud\BigQuery\Bytes;
use Google\Cloud\Dev\Snippet\SnippetTestCase;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;
use Prophecy\Argument;

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/snippets/BigQuery/CopyJobConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\BigQuery\CopyJobConfiguration;
use Google\Cloud\Dev\Snippet\SnippetTestCase;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;

/**
* @group bigquery
Expand Down Expand Up @@ -70,7 +70,7 @@ public function testSetters($method, $expected, $bq = null)

public function setterDataProvider()
{
$bq = \Google\Cloud\Dev\stub(BigQueryClient::class, [
$bq = \Google\Cloud\Core\Testing\Functions::stub(BigQueryClient::class, [
['projectId' => self::PROJECT_ID]
]);

Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/BigQuery/DatasetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Google\Cloud\BigQuery\Table;
use Google\Cloud\BigQuery\ValueMapper;
use Google\Cloud\Core\Iterator\ItemIterator;
use Google\Cloud\Dev\Snippet\SnippetTestCase;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;
use Prophecy\Argument;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/BigQuery/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace Google\Cloud\Tests\Snippets\BigQuery;

use Google\Cloud\BigQuery\Date;
use Google\Cloud\Dev\Snippet\SnippetTestCase;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;
use Prophecy\Argument;

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/snippets/BigQuery/ExtractJobConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\BigQuery\ExtractJobConfiguration;
use Google\Cloud\BigQuery\Table;
use Google\Cloud\Dev\Snippet\SnippetTestCase;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;

/**
* @group bigquery
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testSetters($method, $expected, $bq = null)

public function setterDataProvider()
{
$bq = \Google\Cloud\Dev\stub(BigQueryClient::class, [
$bq = \Google\Cloud\Core\Testing\Functions::stub(BigQueryClient::class, [
['projectId' => self::PROJECT_ID]
]);

Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/BigQuery/InsertResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace Google\Cloud\Tests\Snippets\BigQuery;

use Google\Cloud\BigQuery\InsertResponse;
use Google\Cloud\Dev\Snippet\SnippetTestCase;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;
use Prophecy\Argument;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/BigQuery/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Google\Cloud\BigQuery\Job;
use Google\Cloud\BigQuery\QueryResults;
use Google\Cloud\BigQuery\ValueMapper;
use Google\Cloud\Dev\Snippet\SnippetTestCase;
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;
use Prophecy\Argument;

/**
Expand Down
Loading