diff --git a/composer.json b/composer.json index cae3c958cb48..5606dbc21c5b 100644 --- a/composer.json +++ b/composer.json @@ -69,7 +69,8 @@ }, "autoload-dev": { "psr-4": { - "Google\\Cloud\\Dev\\": "dev/src" + "Google\\Cloud\\Dev\\": "dev/src", + "Google\\Cloud\\Tests\\System\\": "tests/system" } }, "scripts": { diff --git a/phpunit.system.xml b/phpunit.system.xml new file mode 100644 index 000000000000..fe00c67b1d96 --- /dev/null +++ b/phpunit.system.xml @@ -0,0 +1,16 @@ + + + + + tests/system + + + + + src + + src/*/V[!a-zA-Z]* + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f8f890f5319c..8afd82d909fa 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,8 @@ - + - tests + tests/unit diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index d21c14df8c2f..000000000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,3 +0,0 @@ -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:gcloud.php.tests@gmail.com' + ] + ] + ] + ]; + $iam->setPolicy($policy); + $actualPolicy = $iam->reload(); + + $this->assertEquals($policy['bindings'][0], $actualPolicy['bindings'][0]); + } +} diff --git a/tests/system/PubSub/ManageSubscriptionsTest.php b/tests/system/PubSub/ManageSubscriptionsTest.php new file mode 100644 index 000000000000..bd62b754fe0b --- /dev/null +++ b/tests/system/PubSub/ManageSubscriptionsTest.php @@ -0,0 +1,76 @@ +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); + } +} diff --git a/tests/system/PubSub/ManageTopicsTest.php b/tests/system/PubSub/ManageTopicsTest.php new file mode 100644 index 000000000000..3a1e010c3c04 --- /dev/null +++ b/tests/system/PubSub/ManageTopicsTest.php @@ -0,0 +1,64 @@ +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']); + } +} diff --git a/tests/system/PubSub/PubSubTestCase.php b/tests/system/PubSub/PubSubTestCase.php new file mode 100644 index 000000000000..07dd04d87ad0 --- /dev/null +++ b/tests/system/PubSub/PubSubTestCase.php @@ -0,0 +1,73 @@ + $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(); + }); + } + } +} + + diff --git a/tests/system/PubSub/PublishAndPullTest.php b/tests/system/PubSub/PublishAndPullTest.php new file mode 100644 index 000000000000..d5fb6ee3c906 --- /dev/null +++ b/tests/system/PubSub/PublishAndPullTest.php @@ -0,0 +1,88 @@ +createTopic($topicName); + $sub = $client->subscribe($subName, $topicName); + self::$deletionQueue[] = $topic; + self::$deletionQueue[] = $sub; + + $message = [ + 'data' => 'A message.', + 'attributes' => [ + 'location' => 'Detroit' + ] + ]; + $topic->publish($message); + + $messages = iterator_to_array($sub->pull()); + $sub->modifyAckDeadline($messages[0], 15); + $sub->acknowledge($messages[0]); + + $this->assertEquals($message['data'], $messages[0]->data()); + $this->assertEquals($message['attributes'], $messages[0]->attributes()); + } + + /** + * @dataProvider clientProvider + */ + public function testPublishMessagesAndPull($client) + { + $topicName = uniqid(self::TESTING_PREFIX); + $subName = uniqid(self::TESTING_PREFIX); + $topic = $client->createTopic($topicName); + $sub = $client->subscribe($subName, $topicName); + self::$deletionQueue[] = $topic; + self::$deletionQueue[] = $sub; + + $messages = [ + [ + 'data' => 'First.', + 'attributes' => [ + 'first' => 'yes' + ] + ], + [ + 'data' => 'Second.', + 'attributes' => [ + 'second' => 'yes' + ] + ] + ]; + + $topic->publishBatch($messages); + + $actualMessages = iterator_to_array($sub->pull()); + $sub->modifyAckDeadlineBatch($actualMessages, 15); + $sub->acknowledgeBatch($actualMessages); + + $this->assertEquals($messages[0]['data'], $actualMessages[0]->data()); + $this->assertEquals($messages[0]['attributes'], $actualMessages[0]->attributes()); + $this->assertEquals($messages[1]['data'], $actualMessages[1]->data()); + $this->assertEquals($messages[1]['attributes'], $actualMessages[1]->attributes()); + } +} diff --git a/tests/system/bootstrap.php b/tests/system/bootstrap.php new file mode 100644 index 000000000000..d020e3cc80f2 --- /dev/null +++ b/tests/system/bootstrap.php @@ -0,0 +1,15 @@ +assertEquals(JSON_ERROR_NONE, json_last_error()); @@ -46,7 +46,7 @@ public function testComposer() public function testManifest() { - $file = file_get_contents(__DIR__ .'/../docs/manifest.json'); + $file = file_get_contents(__DIR__ .'/../../docs/manifest.json'); $json = json_decode($file); $this->assertEquals(JSON_ERROR_NONE, json_last_error()); @@ -63,7 +63,7 @@ public function testManifest() public function testToc() { - $file = file_get_contents(__DIR__ .'/../docs/toc.json'); + $file = file_get_contents(__DIR__ .'/../../docs/toc.json'); $json = json_decode($file); $this->assertEquals(JSON_ERROR_NONE, json_last_error()); diff --git a/tests/Logger/AppEngineFlexHandlerTest.php b/tests/unit/Logger/AppEngineFlexHandlerTest.php similarity index 100% rename from tests/Logger/AppEngineFlexHandlerTest.php rename to tests/unit/Logger/AppEngineFlexHandlerTest.php diff --git a/tests/Logging/Connection/GrpcTest.php b/tests/unit/Logging/Connection/GrpcTest.php similarity index 100% rename from tests/Logging/Connection/GrpcTest.php rename to tests/unit/Logging/Connection/GrpcTest.php diff --git a/tests/Logging/Connection/RestTest.php b/tests/unit/Logging/Connection/RestTest.php similarity index 100% rename from tests/Logging/Connection/RestTest.php rename to tests/unit/Logging/Connection/RestTest.php diff --git a/tests/Logging/LoggerTest.php b/tests/unit/Logging/LoggerTest.php similarity index 100% rename from tests/Logging/LoggerTest.php rename to tests/unit/Logging/LoggerTest.php diff --git a/tests/Logging/LoggingClientTest.php b/tests/unit/Logging/LoggingClientTest.php similarity index 100% rename from tests/Logging/LoggingClientTest.php rename to tests/unit/Logging/LoggingClientTest.php diff --git a/tests/Logging/MetricTest.php b/tests/unit/Logging/MetricTest.php similarity index 100% rename from tests/Logging/MetricTest.php rename to tests/unit/Logging/MetricTest.php diff --git a/tests/Logging/PsrLoggerTest.php b/tests/unit/Logging/PsrLoggerTest.php similarity index 100% rename from tests/Logging/PsrLoggerTest.php rename to tests/unit/Logging/PsrLoggerTest.php diff --git a/tests/Logging/SinkTest.php b/tests/unit/Logging/SinkTest.php similarity index 100% rename from tests/Logging/SinkTest.php rename to tests/unit/Logging/SinkTest.php diff --git a/tests/NaturalLanguage/AnnotationTest.php b/tests/unit/NaturalLanguage/AnnotationTest.php similarity index 100% rename from tests/NaturalLanguage/AnnotationTest.php rename to tests/unit/NaturalLanguage/AnnotationTest.php diff --git a/tests/NaturalLanguage/Connection/RestTest.php b/tests/unit/NaturalLanguage/Connection/RestTest.php similarity index 100% rename from tests/NaturalLanguage/Connection/RestTest.php rename to tests/unit/NaturalLanguage/Connection/RestTest.php diff --git a/tests/NaturalLanguage/NaturalLanguageClientTest.php b/tests/unit/NaturalLanguage/NaturalLanguageClientTest.php similarity index 100% rename from tests/NaturalLanguage/NaturalLanguageClientTest.php rename to tests/unit/NaturalLanguage/NaturalLanguageClientTest.php diff --git a/tests/PhpArrayTest.php b/tests/unit/PhpArrayTest.php similarity index 100% rename from tests/PhpArrayTest.php rename to tests/unit/PhpArrayTest.php diff --git a/tests/PubSub/Connection/GrpcTest.php b/tests/unit/PubSub/Connection/GrpcTest.php similarity index 100% rename from tests/PubSub/Connection/GrpcTest.php rename to tests/unit/PubSub/Connection/GrpcTest.php diff --git a/tests/PubSub/Connection/IamSubscriptionTest.php b/tests/unit/PubSub/Connection/IamSubscriptionTest.php similarity index 100% rename from tests/PubSub/Connection/IamSubscriptionTest.php rename to tests/unit/PubSub/Connection/IamSubscriptionTest.php diff --git a/tests/PubSub/Connection/IamTopicTest.php b/tests/unit/PubSub/Connection/IamTopicTest.php similarity index 100% rename from tests/PubSub/Connection/IamTopicTest.php rename to tests/unit/PubSub/Connection/IamTopicTest.php diff --git a/tests/PubSub/Connection/RestTest.php b/tests/unit/PubSub/Connection/RestTest.php similarity index 100% rename from tests/PubSub/Connection/RestTest.php rename to tests/unit/PubSub/Connection/RestTest.php diff --git a/tests/PubSub/IncomingMessageTraitTest.php b/tests/unit/PubSub/IncomingMessageTraitTest.php similarity index 100% rename from tests/PubSub/IncomingMessageTraitTest.php rename to tests/unit/PubSub/IncomingMessageTraitTest.php diff --git a/tests/PubSub/MessageTest.php b/tests/unit/PubSub/MessageTest.php similarity index 100% rename from tests/PubSub/MessageTest.php rename to tests/unit/PubSub/MessageTest.php diff --git a/tests/PubSub/PubSubClientTest.php b/tests/unit/PubSub/PubSubClientTest.php similarity index 100% rename from tests/PubSub/PubSubClientTest.php rename to tests/unit/PubSub/PubSubClientTest.php diff --git a/tests/PubSub/ResourceNameTraitTest.php b/tests/unit/PubSub/ResourceNameTraitTest.php similarity index 100% rename from tests/PubSub/ResourceNameTraitTest.php rename to tests/unit/PubSub/ResourceNameTraitTest.php diff --git a/tests/PubSub/SubscriptionTest.php b/tests/unit/PubSub/SubscriptionTest.php similarity index 100% rename from tests/PubSub/SubscriptionTest.php rename to tests/unit/PubSub/SubscriptionTest.php diff --git a/tests/PubSub/TopicTest.php b/tests/unit/PubSub/TopicTest.php similarity index 100% rename from tests/PubSub/TopicTest.php rename to tests/unit/PubSub/TopicTest.php diff --git a/tests/RequestBuilderTest.php b/tests/unit/RequestBuilderTest.php similarity index 100% rename from tests/RequestBuilderTest.php rename to tests/unit/RequestBuilderTest.php diff --git a/tests/RequestWrapperTest.php b/tests/unit/RequestWrapperTest.php similarity index 100% rename from tests/RequestWrapperTest.php rename to tests/unit/RequestWrapperTest.php diff --git a/tests/RestTraitTest.php b/tests/unit/RestTraitTest.php similarity index 100% rename from tests/RestTraitTest.php rename to tests/unit/RestTraitTest.php diff --git a/tests/ServiceBuilderTest.php b/tests/unit/ServiceBuilderTest.php similarity index 100% rename from tests/ServiceBuilderTest.php rename to tests/unit/ServiceBuilderTest.php diff --git a/tests/Speech/Connection/RestTest.php b/tests/unit/Speech/Connection/RestTest.php similarity index 100% rename from tests/Speech/Connection/RestTest.php rename to tests/unit/Speech/Connection/RestTest.php diff --git a/tests/Speech/OperationTest.php b/tests/unit/Speech/OperationTest.php similarity index 100% rename from tests/Speech/OperationTest.php rename to tests/unit/Speech/OperationTest.php diff --git a/tests/Speech/SpeechClientTest.php b/tests/unit/Speech/SpeechClientTest.php similarity index 100% rename from tests/Speech/SpeechClientTest.php rename to tests/unit/Speech/SpeechClientTest.php diff --git a/tests/Storage/AclTest.php b/tests/unit/Storage/AclTest.php similarity index 100% rename from tests/Storage/AclTest.php rename to tests/unit/Storage/AclTest.php diff --git a/tests/Storage/BucketTest.php b/tests/unit/Storage/BucketTest.php similarity index 100% rename from tests/Storage/BucketTest.php rename to tests/unit/Storage/BucketTest.php diff --git a/tests/Storage/Connection/RestTest.php b/tests/unit/Storage/Connection/RestTest.php similarity index 100% rename from tests/Storage/Connection/RestTest.php rename to tests/unit/Storage/Connection/RestTest.php diff --git a/tests/Storage/EncryptionTraitTest.php b/tests/unit/Storage/EncryptionTraitTest.php similarity index 100% rename from tests/Storage/EncryptionTraitTest.php rename to tests/unit/Storage/EncryptionTraitTest.php diff --git a/tests/Storage/StorageClientTest.php b/tests/unit/Storage/StorageClientTest.php similarity index 100% rename from tests/Storage/StorageClientTest.php rename to tests/unit/Storage/StorageClientTest.php diff --git a/tests/Storage/StorageObjectTest.php b/tests/unit/Storage/StorageObjectTest.php similarity index 100% rename from tests/Storage/StorageObjectTest.php rename to tests/unit/Storage/StorageObjectTest.php diff --git a/tests/Translate/Connection/RestTest.php b/tests/unit/Translate/Connection/RestTest.php similarity index 100% rename from tests/Translate/Connection/RestTest.php rename to tests/unit/Translate/Connection/RestTest.php diff --git a/tests/Translate/TranslateClientTest.php b/tests/unit/Translate/TranslateClientTest.php similarity index 100% rename from tests/Translate/TranslateClientTest.php rename to tests/unit/Translate/TranslateClientTest.php diff --git a/tests/Upload/MultipartUploaderTest.php b/tests/unit/Upload/MultipartUploaderTest.php similarity index 100% rename from tests/Upload/MultipartUploaderTest.php rename to tests/unit/Upload/MultipartUploaderTest.php diff --git a/tests/Upload/ResumableUploaderTest.php b/tests/unit/Upload/ResumableUploaderTest.php similarity index 100% rename from tests/Upload/ResumableUploaderTest.php rename to tests/unit/Upload/ResumableUploaderTest.php diff --git a/tests/UriTraitTest.php b/tests/unit/UriTraitTest.php similarity index 100% rename from tests/UriTraitTest.php rename to tests/unit/UriTraitTest.php diff --git a/tests/ValidateTraitTest.php b/tests/unit/ValidateTraitTest.php similarity index 100% rename from tests/ValidateTraitTest.php rename to tests/unit/ValidateTraitTest.php diff --git a/tests/Vision/Annotation/EntityTest.php b/tests/unit/Vision/Annotation/EntityTest.php similarity index 100% rename from tests/Vision/Annotation/EntityTest.php rename to tests/unit/Vision/Annotation/EntityTest.php diff --git a/tests/Vision/Annotation/Face/LandmarksTest.php b/tests/unit/Vision/Annotation/Face/LandmarksTest.php similarity index 100% rename from tests/Vision/Annotation/Face/LandmarksTest.php rename to tests/unit/Vision/Annotation/Face/LandmarksTest.php diff --git a/tests/Vision/Annotation/FaceTest.php b/tests/unit/Vision/Annotation/FaceTest.php similarity index 100% rename from tests/Vision/Annotation/FaceTest.php rename to tests/unit/Vision/Annotation/FaceTest.php diff --git a/tests/Vision/Annotation/LikelihoodTraitTest.php b/tests/unit/Vision/Annotation/LikelihoodTraitTest.php similarity index 100% rename from tests/Vision/Annotation/LikelihoodTraitTest.php rename to tests/unit/Vision/Annotation/LikelihoodTraitTest.php diff --git a/tests/Vision/Annotation/SafeSearchTest.php b/tests/unit/Vision/Annotation/SafeSearchTest.php similarity index 100% rename from tests/Vision/Annotation/SafeSearchTest.php rename to tests/unit/Vision/Annotation/SafeSearchTest.php diff --git a/tests/Vision/AnnotationTest.php b/tests/unit/Vision/AnnotationTest.php similarity index 100% rename from tests/Vision/AnnotationTest.php rename to tests/unit/Vision/AnnotationTest.php diff --git a/tests/Vision/Connection/RestTest.php b/tests/unit/Vision/Connection/RestTest.php similarity index 100% rename from tests/Vision/Connection/RestTest.php rename to tests/unit/Vision/Connection/RestTest.php diff --git a/tests/Vision/ImageTest.php b/tests/unit/Vision/ImageTest.php similarity index 100% rename from tests/Vision/ImageTest.php rename to tests/unit/Vision/ImageTest.php diff --git a/tests/Vision/VisionClientTest.php b/tests/unit/Vision/VisionClientTest.php similarity index 100% rename from tests/Vision/VisionClientTest.php rename to tests/unit/Vision/VisionClientTest.php diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php new file mode 100644 index 000000000000..19d4b20353dd --- /dev/null +++ b/tests/unit/bootstrap.php @@ -0,0 +1,3 @@ +