diff --git a/.kokoro/presubmit/run-tests.sh b/.kokoro/presubmit/run-tests.sh index beea3bd6c75a..646c16b5db2b 100755 --- a/.kokoro/presubmit/run-tests.sh +++ b/.kokoro/presubmit/run-tests.sh @@ -42,7 +42,7 @@ fi echo "Running Snippet Test Suite" -vendor/bin/phpunit -c phpunit${PHPUNIT_SUFFIX}.xml.dist --verbose --log-junit \ +vendor/bin/phpunit -c phpunit${PHPUNIT_SUFFIX}-snippets.xml.dist --verbose --log-junit \ ${SNIPPETS_LOG_FILENAME} # Run docs gen on PHP 7.4 only diff --git a/BigQuery/tests/Snippet/QueryResultsTest.php b/BigQuery/tests/Snippet/QueryResultsTest.php index 368c92c1b6bf..01012a37a4c6 100644 --- a/BigQuery/tests/Snippet/QueryResultsTest.php +++ b/BigQuery/tests/Snippet/QueryResultsTest.php @@ -63,6 +63,13 @@ public function setUp() ] ]; + $job = $this->prophesize(Job::class); + $job->identity() + ->willReturn([ + 'jobId' => 'job', + 'projectId' => 'project', + 'location' => 'us-west1' + ]); $this->connection = $this->prophesize(ConnectionInterface::class); $this->qr = TestHelpers::stub(QueryResults::class, [ $this->connection->reveal(), @@ -70,7 +77,7 @@ public function setUp() self::PROJECT, $this->info, new ValueMapper(false), - $this->prophesize(Job::class)->reveal() + $job->reveal() ]); } diff --git a/Core/src/Testing/TestHelpers.php b/Core/src/Testing/TestHelpers.php index 1292d3bce98e..5fb31f698128 100644 --- a/Core/src/Testing/TestHelpers.php +++ b/Core/src/Testing/TestHelpers.php @@ -113,7 +113,7 @@ public static function snippetBootstrap() '/vendor/', '/dev/', new RegexFileFilter('/\w{0,}\/vendor\//'), - new RegexFileFilter('/\w{0,}\/V\d{1,}\//') + new RegexFileFilter('/\w{0,}\/V\d{1,}\w{0,}\//') ]); $coverage = new Coverage($scanner); $coverage->buildListToCover(); diff --git a/Spanner/src/Backup.php b/Spanner/src/Backup.php index 22672c975eea..d60ba6b91979 100644 --- a/Spanner/src/Backup.php +++ b/Spanner/src/Backup.php @@ -192,17 +192,16 @@ public function create($database, DateTimeInterface $expireTime, array $options * * Example: * ``` - * $spanner = new SpannerClient(); * $sourceInstance = $spanner->instance('source-instance-id'); * $destInstance = $spanner->instance('destination-instance-id'); * $sourceBackup = $sourceInstance->backup('source-backup-id'); - * $destBackup = $instance->backup('new-backup-id'); + * $destBackup = $destInstance->backup('new-backup-id'); * * $operation = $sourceBackup->createCopy($destBackup, new \DateTime('+7 hours')); * ``` * * @param Backup $newBackup The backup object that needs to be created as a copy. - * @param DateTimeInterface $expireTime ​The expiration time of the backup, + * @param DateTimeInterface $expireTime The expiration time of the backup, * with microseconds granularity that must be at least 6 hours and * at most 366 days. Once the expireTime has passed, the backup is * eligible to be automatically deleted by Cloud Spanner. diff --git a/Spanner/tests/Snippet/ArrayTypeTest.php b/Spanner/tests/Snippet/ArrayTypeTest.php index 2d97cba4d9ef..24506d0f3802 100644 --- a/Spanner/tests/Snippet/ArrayTypeTest.php +++ b/Spanner/tests/Snippet/ArrayTypeTest.php @@ -58,6 +58,14 @@ public function setUp() $instance->name()->willReturn(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)); $session = $this->prophesize(Session::class); + $session->info() + ->willReturn([ + 'databaseName' => 'database' + ]); + $session->name() + ->willReturn('database'); + $session->setExpiration(Argument::any()) + ->willReturn(100); $sessionPool = $this->prophesize(SessionPoolInterface::class); $sessionPool->acquire(Argument::any()) diff --git a/Spanner/tests/Snippet/BackupTest.php b/Spanner/tests/Snippet/BackupTest.php index 9e4ce702a04b..1c15bcf018be 100644 --- a/Spanner/tests/Snippet/BackupTest.php +++ b/Spanner/tests/Snippet/BackupTest.php @@ -27,6 +27,7 @@ use Google\Cloud\Spanner\Connection\ConnectionInterface; use Google\Cloud\Spanner\Backup; use Google\Cloud\Spanner\Instance; +use Google\Cloud\Spanner\SpannerClient; use Prophecy\Argument; /** @@ -44,6 +45,7 @@ class BackupTest extends SnippetTestCase private $connection; private $backup; + private $client; private $instance; private $expireTime; @@ -52,6 +54,7 @@ public function setUp() $this->checkAndSkipGrpcTests(); $this->connection = $this->prophesize(ConnectionInterface::class); + $this->client = TestHelpers::stub(SpannerClient::class); $this->expireTime = new \DateTime("+ 7 hours"); $this->instance = TestHelpers::stub(Instance::class, [ $this->connection->reveal(), @@ -103,7 +106,7 @@ public function testCreate() public function testCreateCopy() { $snippet = $this->snippetFromMethod(Backup::class, 'createCopy'); - $snippet->addLocal('backup', $this->backup); + $snippet->addLocal('spanner', $this->client); $this->connection->copyBackup(Argument::any()) ->shouldBeCalled() @@ -111,7 +114,7 @@ public function testCreateCopy() 'name' => 'my-operation' ]); - $this->backup->___setProperty('connection', $this->connection->reveal()); + $this->client->___setProperty('connection', $this->connection->reveal()); $res = $snippet->invoke('operation'); $this->assertInstanceOf(LongRunningOperation::class, $res->returnVal()); diff --git a/Spanner/tests/Snippet/DatabaseTest.php b/Spanner/tests/Snippet/DatabaseTest.php index adfd1a30bf1d..c027299be317 100644 --- a/Spanner/tests/Snippet/DatabaseTest.php +++ b/Spanner/tests/Snippet/DatabaseTest.php @@ -68,6 +68,14 @@ public function setUp() $this->checkAndSkipGrpcTests(); $session = $this->prophesize(Session::class); + $session->info() + ->willReturn([ + 'databaseName' => 'database' + ]); + $session->name() + ->willReturn('database'); + $session->setExpiration(Argument::any()) + ->willReturn(100); $sessionPool = $this->prophesize(SessionPoolInterface::class); $sessionPool->acquire(Argument::any()) diff --git a/Spanner/tests/Snippet/StructTypeTest.php b/Spanner/tests/Snippet/StructTypeTest.php index 4311aa54f4b0..62803dce0a7f 100644 --- a/Spanner/tests/Snippet/StructTypeTest.php +++ b/Spanner/tests/Snippet/StructTypeTest.php @@ -58,6 +58,14 @@ public function setUp() $instance->name()->willReturn(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)); $session = $this->prophesize(Session::class); + $session->info() + ->willReturn([ + 'databaseName' => 'database' + ]); + $session->name() + ->willReturn('database'); + $session->setExpiration(Argument::any()) + ->willReturn(100); $sessionPool = $this->prophesize(SessionPoolInterface::class); $sessionPool->acquire(Argument::any()) diff --git a/Spanner/tests/Snippet/StructValueTest.php b/Spanner/tests/Snippet/StructValueTest.php index 51e32b1ab6d1..2ecb78a04021 100644 --- a/Spanner/tests/Snippet/StructValueTest.php +++ b/Spanner/tests/Snippet/StructValueTest.php @@ -57,6 +57,14 @@ public function setUp() $instance->name()->willReturn(InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)); $session = $this->prophesize(Session::class); + $session->info() + ->willReturn([ + 'databaseName' => 'database' + ]); + $session->name() + ->willReturn('database'); + $session->setExpiration(Argument::any()) + ->willReturn(100); $sessionPool = $this->prophesize(SessionPoolInterface::class); $sessionPool->acquire(Argument::any()) diff --git a/Spanner/tests/Snippet/TransactionTest.php b/Spanner/tests/Snippet/TransactionTest.php index cdcaa6af0743..3bb6d3844d05 100644 --- a/Spanner/tests/Snippet/TransactionTest.php +++ b/Spanner/tests/Snippet/TransactionTest.php @@ -57,6 +57,12 @@ public function setUp() $this->connection = $this->getConnStub(); $operation = $this->prophesize(Operation::class); $session = $this->prophesize(Session::class); + $session->info() + ->willReturn([ + 'databaseName' => 'database' + ]); + $session->name() + ->willReturn('database'); $this->transaction = TestHelpers::stub(Transaction::class, [ $operation->reveal(), diff --git a/Spanner/tests/Snippet/TransactionalReadMethodsTest.php b/Spanner/tests/Snippet/TransactionalReadMethodsTest.php index b6cee73c61a3..84d4fe2301b5 100644 --- a/Spanner/tests/Snippet/TransactionalReadMethodsTest.php +++ b/Spanner/tests/Snippet/TransactionalReadMethodsTest.php @@ -71,6 +71,10 @@ public function setUp() $this->connection = $this->getConnStub(); $this->session = $this->prophesize(Session::class); + $this->session->info() + ->willReturn([ + 'databaseName' => 'database' + ]); $this->operation = $this->prophesize(Operation::class); }