-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
404 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./tests/system/bootstrap.php" colors="true"> | ||
<testsuites> | ||
<testsuite> | ||
<directory>tests/system</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
<exclude> | ||
<directory suffix=".php">src/*/V[!a-zA-Z]*</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* Copyright 2016 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. | ||
*/ | ||
|
||
namespace Google\Cloud\Tests\System\PubSub; | ||
|
||
class ManageIAMPoliciesTest extends PubSubTestCase | ||
{ | ||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testManageTopicIAM($client) | ||
{ | ||
$topic = $client->createTopic(uniqid(self::TESTING_PREFIX)); | ||
self::$deletionQueue[] = $topic; | ||
$this->assertIam($topic->iam()); | ||
} | ||
|
||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testManageSubscriptionIAM($client) | ||
{ | ||
$topic = $client->createTopic(uniqid(self::TESTING_PREFIX)); | ||
self::$deletionQueue[] = $topic; | ||
$sub = $client->subscribe(uniqid(self::TESTING_PREFIX), $topic->name()); | ||
self::$deletionQueue[] = $sub; | ||
|
||
$this->assertIam($sub->iam()); | ||
} | ||
|
||
private function assertIam($iam) | ||
{ | ||
$policy = [ | ||
'bindings' => [ | ||
[ | ||
'role' => 'roles/pubsub.admin', | ||
'members' => [ | ||
'user:[email protected]' | ||
] | ||
] | ||
] | ||
]; | ||
$iam->setPolicy($policy); | ||
$actualPolicy = $iam->reload(); | ||
|
||
$this->assertEquals($policy['bindings'][0], $actualPolicy['bindings'][0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright 2016 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. | ||
*/ | ||
|
||
namespace Google\Cloud\Tests\System\PubSub; | ||
|
||
class ManageSubscriptionsTest extends PubSubTestCase | ||
{ | ||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testCreateAndListSubscriptions($client) | ||
{ | ||
$topicName = uniqid(self::TESTING_PREFIX); | ||
$topic = $client->createTopic($topicName); | ||
$subsToCreate = [ | ||
uniqid(self::TESTING_PREFIX), | ||
uniqid(self::TESTING_PREFIX) | ||
]; | ||
|
||
foreach ($subsToCreate as $subToCreate) { | ||
self::$deletionQueue[] = $client->subscribe($subToCreate, $topicName); | ||
} | ||
|
||
$subs = $client->subscriptions(); | ||
$subsByTopic = $topic->subscriptions(); | ||
|
||
$this->assertSubsFound($subs, $subsToCreate); | ||
$this->assertSubsFound($subsByTopic, $subsToCreate); | ||
} | ||
|
||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testReloadSub($client) | ||
{ | ||
$topicName = uniqid(self::TESTING_PREFIX); | ||
$topic = $client->createTopic($topicName); | ||
self::$deletionQueue[] = $topic; | ||
$shortName = uniqid(self::TESTING_PREFIX); | ||
$this->assertFalse($topic->subscription($shortName)->exists()); | ||
$sub = $client->subscribe($shortName, $topic->name()); | ||
self::$deletionQueue[] = $sub; | ||
|
||
$this->assertTrue($topic->subscription($shortName)->exists()); | ||
$this->assertEquals($sub->name(), $sub->reload()['name']); | ||
} | ||
|
||
private function assertSubsFound($subs, $expectedSubs) | ||
{ | ||
$foundSubs = []; | ||
foreach ($subs as $sub) { | ||
$sName = end(explode('/', $sub->name())); | ||
foreach ($expectedSubs as $key => $expectedSub) { | ||
if ($sName === $expectedSub) { | ||
$foundSubs[$key] = $sName; | ||
} | ||
} | ||
} | ||
|
||
$this->assertEquals($expectedSubs, $foundSubs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright 2016 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. | ||
*/ | ||
|
||
namespace Google\Cloud\Tests\System\PubSub; | ||
|
||
class ManageTopicsTest extends PubSubTestCase | ||
{ | ||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testCreateAndListTopics($client) | ||
{ | ||
$foundTopics = []; | ||
$topicsToCreate = [ | ||
uniqid(self::TESTING_PREFIX), | ||
uniqid(self::TESTING_PREFIX) | ||
]; | ||
|
||
foreach ($topicsToCreate as $topicToCreate) { | ||
self::$deletionQueue[] = $client->createTopic($topicToCreate); | ||
} | ||
|
||
$topics = $client->topics(); | ||
|
||
foreach ($topics as $topic) { | ||
$tName = end(explode('/', $topic->name())); | ||
foreach ($topicsToCreate as $key => $topicToCreate) { | ||
if ($tName === $topicToCreate) { | ||
$foundTopics[$key] = $tName; | ||
} | ||
} | ||
} | ||
|
||
$this->assertEquals($topicsToCreate, $foundTopics); | ||
} | ||
|
||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testReloadTopic($client) | ||
{ | ||
$shortName = uniqid(self::TESTING_PREFIX); | ||
$this->assertFalse($client->topic($shortName)->exists()); | ||
$topic = $client->createTopic($shortName); | ||
self::$deletionQueue[] = $topic; | ||
|
||
$this->assertTrue($client->topic($shortName)->exists()); | ||
$this->assertEquals($topic->name(), $topic->reload()['name']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* 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. | ||
*/ | ||
|
||
namespace Google\Cloud\Tests\System\PubSub; | ||
|
||
use Google\Cloud\ExponentialBackoff; | ||
use Google\Cloud\PubSub\PubSubClient; | ||
|
||
class PubSubTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
const TESTING_PREFIX = 'gcloud_testing_'; | ||
|
||
protected static $deletionQueue = []; | ||
protected static $grpcClient; | ||
protected static $restClient; | ||
protected static $topic; | ||
private static $hasSetUp = false; | ||
|
||
public function clientProvider() | ||
{ | ||
self::setUpBeforeClass(); | ||
|
||
return [ | ||
[self::$restClient], | ||
[self::$grpcClient] | ||
]; | ||
} | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
if (self::$hasSetUp) { | ||
return; | ||
} | ||
|
||
$keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); | ||
self::$restClient = new PubSubClient([ | ||
'keyFilePath' => $keyFilePath, | ||
'transport' => 'rest' | ||
]); | ||
self::$grpcClient = new PubSubClient([ | ||
'keyFilePath' => $keyFilePath, | ||
'transport' => 'grpc' | ||
]); | ||
self::$hasSetUp = true; | ||
} | ||
|
||
public static function tearDownFixtures() | ||
{ | ||
$backoff = new ExponentialBackoff(8); | ||
|
||
foreach (self::$deletionQueue as $item) { | ||
$backoff->execute(function () use ($item) { | ||
$item->delete(); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.