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

chore: utilize the correct phpunit configuration for snippets #5259

Merged
merged 4 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .kokoro/presubmit/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion BigQuery/tests/Snippet/QueryResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,21 @@ 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(),
self::JOB_ID,
self::PROJECT,
$this->info,
new ValueMapper(false),
$this->prophesize(Job::class)->reveal()
$job->reveal()
]);
}

Expand Down
2 changes: 1 addition & 1 deletion Core/src/Testing/TestHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions Spanner/src/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot for the life of me find what's different between these two lines. I even hid whitespace, and it's still here...

Please tell me the difference so I don't go insane

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2022-05-04 at 4 48 47 PM

* 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.
Expand Down
8 changes: 8 additions & 0 deletions Spanner/tests/Snippet/ArrayTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 5 additions & 2 deletions Spanner/tests/Snippet/BackupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -44,6 +45,7 @@ class BackupTest extends SnippetTestCase

private $connection;
private $backup;
private $client;
private $instance;
private $expireTime;

Expand All @@ -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(),
Expand Down Expand Up @@ -103,15 +106,15 @@ 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()
->willReturn([
'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());
Expand Down
8 changes: 8 additions & 0 deletions Spanner/tests/Snippet/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 8 additions & 0 deletions Spanner/tests/Snippet/StructTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 8 additions & 0 deletions Spanner/tests/Snippet/StructValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions Spanner/tests/Snippet/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions Spanner/tests/Snippet/TransactionalReadMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down