Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/emulator-system-tests-spanner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: 'ubuntu-24.04'
services:
emulator:
image: gcr.io/cloud-spanner-emulator/emulator:1.5.34
image: gcr.io/cloud-spanner-emulator/emulator:1.5.42
ports:
- 9010:9010
- 9020:9020
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.4'
ini-values: grpc.enable_fork_support=1
tools: pecl
extensions: bcmath, grpc, pcntl
Expand Down
8 changes: 0 additions & 8 deletions Core/src/Testing/System/SystemTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Core\Testing\System\DeletionQueue;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

/**
* SystemTestCase can be extended to implement system tests
Expand Down Expand Up @@ -287,11 +286,4 @@ public static function skipIfEmulatorUsed($reason = null)
self::markTestSkipped($reason ?: 'This test is not supported by the emulator.');
}
}

protected static function getCacheItemPool()
{
return new FilesystemAdapter(
directory: __DIR__ . '/../../../../.cache'
);
}
}
2 changes: 1 addition & 1 deletion Spanner/src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private function setSnapshotOrTransaction(array $result): void
[],
$this->mapper
);
if (isset($result['precommitToken'])) {
Comment thread
Hectorhammett marked this conversation as resolved.
if (isset($result['precommitToken']['precommitToken'])) {
// @TODO: Can we move this logic to the serializer or value mapper?
$this->transaction->setPrecommitToken(
(new MultiplexedSessionPrecommitToken())
Expand Down
15 changes: 5 additions & 10 deletions Spanner/tests/System/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Google\Cloud\Core\Exception\FailedPreconditionException;
use Google\Cloud\Core\LongRunning\LongRunningOperation;
use Google\Cloud\Core\Testing\System\SystemTestCase;
use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient;
use Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect;
use Google\Cloud\Spanner\Admin\Instance\V1\Client\InstanceAdminClient;
Expand All @@ -31,8 +32,10 @@
* @group spanner
* @group admin
*/
class AdminTest extends SpannerTestCase
class AdminTest extends SystemTestCase
{
use SystemTestCaseTrait;

/**
* @beforeClass
*/
Expand Down Expand Up @@ -123,15 +126,7 @@ public function testDatabase()

$this->assertInstanceOf(Database::class, current($database));
$this->assertTrue($db->exists());

$expectedDatabaseDialect = DatabaseDialect::GOOGLE_STANDARD_SQL;

// TODO: Remove this, when the emulator supports PGSQL
if ((bool) getenv('SPANNER_EMULATOR_HOST')) {
$expectedDatabaseDialect = DatabaseDialect::DATABASE_DIALECT_UNSPECIFIED;
}

$this->assertEquals($db->info()['databaseDialect'], $expectedDatabaseDialect);
$this->assertEquals($db->info()['databaseDialect'], DatabaseDialect::GOOGLE_STANDARD_SQL);

$stmt = "CREATE TABLE Ids (\n" .
" id INT64 NOT NULL,\n" .
Expand Down
11 changes: 7 additions & 4 deletions Spanner/tests/System/BackupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Google\Cloud\Core\Exception\BadRequestException;
use Google\Cloud\Core\Exception\ConflictException;
use Google\Cloud\Core\LongRunning\LongRunningOperation;
use Google\Cloud\Core\Testing\System\SystemTestCase;
use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient;
use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupEncryptionConfig;
use Google\Cloud\Spanner\Admin\Database\V1\EncryptionInfo\Type;
Expand All @@ -30,8 +31,10 @@
/**
* @group spanner
*/
class BackupTest extends SpannerTestCase
class BackupTest extends SystemTestCase
{
use SystemTestCaseTrait;

const BACKUP_PREFIX = 'spanner_backup_';

protected static $backupId1;
Expand All @@ -47,7 +50,7 @@ class BackupTest extends SpannerTestCase

protected static $project;

private static $hasSetUp = false;
private static $hasSetUpBackup = false;

/**
* @beforeClass
Expand All @@ -59,7 +62,7 @@ public static function setUpTestFixtures(): void
self::emulatorOnly();

self::setUpTestDatabase();
if (self::$hasSetUp) {
if (self::$hasSetUpBackup) {
return;
}

Expand Down Expand Up @@ -112,7 +115,7 @@ public static function setUpTestFixtures(): void
self::$backupId1 = uniqid(self::BACKUP_PREFIX);
self::$backupId2 = uniqid('users-');
self::$copyBackupId = uniqid('copy-');
self::$hasSetUp = true;
self::$hasSetUpBackup = true;
}

public function testCreateBackup()
Expand Down
38 changes: 20 additions & 18 deletions Spanner/tests/System/BatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\Spanner\Tests\System;

use Google\Cloud\Core\Exception\ServiceException;
use Google\Cloud\Core\Testing\System\SystemTestCase;
use Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect;
use Google\Cloud\Spanner\Batch\BatchClient;
use Google\Cloud\Spanner\Batch\BatchSnapshot;
Expand All @@ -28,8 +29,9 @@
* @group spanner
* @group spanner-batch
*/
class BatchTest extends SpannerTestCase
class BatchTest extends SystemTestCase
{
use SystemTestCaseTrait;
use DatabaseRoleTrait;

private static $tableName;
Expand All @@ -56,26 +58,26 @@ public static function setUpTestFixtures(): void
))->pollUntilComplete();

if (self::$database->info()['databaseDialect'] == DatabaseDialect::GOOGLE_STANDARD_SQL) {
self::$database->updateDdlBatch([
sprintf(
'CREATE ROLE %s',
self::$dbRole
),
sprintf(
'CREATE ROLE %s',
self::$restrictiveDbRole
),
sprintf(
$statements = [
sprintf('CREATE ROLE %s', self::$dbRole),
sprintf('CREATE ROLE %s', self::$restrictiveDbRole),
];

if (!self::isEmulatorUsed()) {
$statements[] = sprintf(
'GRANT SELECT(id) ON TABLE %s TO ROLE %s',
self::$tableName,
self::$restrictiveDbRole
),
sprintf(
'GRANT SELECT ON TABLE %s TO ROLE %s',
self::$tableName,
self::$dbRole
)
])->pollUntilComplete();
);
}

$statements[] = sprintf(
'GRANT SELECT ON TABLE %s TO ROLE %s',
self::$tableName,
self::$dbRole
);

self::$database->updateDdlBatch($statements)->pollUntilComplete();
}

self::seedTable();
Expand Down
5 changes: 4 additions & 1 deletion Spanner/tests/System/BatchWriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
namespace Google\Cloud\Spanner\Tests\System;

use Google\Rpc\Code;
use Google\Cloud\Core\Testing\System\SystemTestCase;

/**
* @group spanner
*/
class BatchWriteTest extends SpannerTestCase
class BatchWriteTest extends SystemTestCase
{
use SystemTestCaseTrait;

const TABLE_NAME = 'BatchWrites';
/**
* @beforeClass
Expand Down
4 changes: 2 additions & 2 deletions Spanner/tests/System/DatabaseRoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function insertDbProvider()
self::getDbWithRestrictiveRole(),
[
'id' => rand(1, 346464),
'name' => uniqid(SpannerTestCase::TESTING_PREFIX),
'name' => uniqid(self::TESTING_PREFIX),
'birthday' => new Date(new \DateTime('2000-01-01'))
],
'PERMISSION_DENIED'
Expand All @@ -55,7 +55,7 @@ public function insertDbProvider()
self::getDbWithRestrictiveRole(),
[
'id' => rand(1, 346464),
'name' => uniqid(SpannerTestCase::TESTING_PREFIX)
'name' => uniqid(self::TESTING_PREFIX)
],
null
]
Expand Down
9 changes: 5 additions & 4 deletions Spanner/tests/System/GeneratedAdminEmulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace Google\Cloud\Spanner\Tests\System;

use Google\Cloud\Core\Testing\System\SystemTestCase;
use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient;
use Google\Cloud\Spanner\Admin\Database\V1\CreateDatabaseRequest;
use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseRequest;
Expand All @@ -28,8 +29,10 @@
/**
* @group spanner
*/
class GeneratedAdminEmulatorTest extends SpannerTestCase
class GeneratedAdminEmulatorTest extends SystemTestCase
{
use SystemTestCaseTrait;

private static $projectId;

/**
Expand All @@ -42,9 +45,7 @@ public static function setUpTestFixtures(): void

public function testAdminClientEmulatorSupport()
{
if (!getenv('SPANNER_EMULATOR_HOST')) {
self::markTestSkipped('This test is required to run only in the emulator.');
}
self::emulatorOnly();

$instanceId = uniqid(self::INSTANCE_NAME);
$databaseId = uniqid(self::TESTING_PREFIX);
Expand Down
5 changes: 4 additions & 1 deletion Spanner/tests/System/LargeReadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@

namespace Google\Cloud\Spanner\Tests\System;

use Google\Cloud\Core\Testing\System\SystemTestCase;
use Google\Cloud\Spanner\Bytes;
use Google\Cloud\Spanner\KeySet;

/**
* @group spanner
* @group spanner-large-read
*/
class LargeReadTest extends SpannerTestCase
class LargeReadTest extends SystemTestCase
{
use SystemTestCaseTrait;

private static $tableName;
private static $row = [];

Expand Down
4 changes: 3 additions & 1 deletion Spanner/tests/System/OperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@

namespace Google\Cloud\Spanner\Tests\System;

use Google\Cloud\Core\Testing\System\SystemTestCase;
use Google\Cloud\Core\Exception\ServiceException;
use Google\Cloud\Spanner\Date;
use Google\Cloud\Spanner\Timestamp;

/**
* @group spanner
*/
class OperationsTest extends SpannerTestCase
class OperationsTest extends SystemTestCase
{
use DatabaseRoleTrait;
use SystemTestCaseTrait;

private static $id1;
private static $id2;
Expand Down
6 changes: 5 additions & 1 deletion Spanner/tests/System/PartitionedDmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@

namespace Google\Cloud\Spanner\Tests\System;

use Google\Cloud\Core\Testing\System\SystemTestCase;

/**
* @group spanner
* @group spanner-pdml
*/
class PartitionedDmlTest extends SpannerTestCase
class PartitionedDmlTest extends SystemTestCase
{
use SystemTestCaseTrait;

const PDML_TABLE = 'partitionedDml';

/**
Expand Down
41 changes: 23 additions & 18 deletions Spanner/tests/System/PgBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\Spanner\Tests\System;

use Google\Cloud\Core\Exception\ServiceException;
use Google\Cloud\Core\Testing\System\SystemTestCase;
use Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect;
use Google\Cloud\Spanner\Batch\BatchClient;
use Google\Cloud\Spanner\Batch\BatchSnapshot;
Expand All @@ -27,19 +28,24 @@
* @group spanner-batch
* @group spanner-postgres
*/
class PgBatchTest extends SpannerPgTestCase
class PgBatchTest extends SystemTestCase
{
use PgSystemTestCaseTrait;
use DatabaseRoleTrait;

private static $tableName;
private static $isSetup = false;
private static $hasSetupBatch = false;

/**
* @beforeClass
*/
public static function setUpTestFixtures(): void
{
if (self::$isSetup) {
// Skip setting up fixutres for the emulator as there's only one test which does not suppport the emulator.
// NOTE: remove this if new tests tests are added which support the emulator.
self::skipEmulatorTests();

if (self::$hasSetupBatch) {
return;
}
self::setUpTestDatabase();
Expand All @@ -55,30 +61,29 @@ public static function setUpTestFixtures(): void
))->pollUntilComplete();

if (self::$database->info()['databaseDialect'] == DatabaseDialect::POSTGRESQL) {
self::$database->updateDdlBatch([
sprintf(
'CREATE ROLE %s',
self::$dbRole
),
sprintf(
'CREATE ROLE %s',
self::$restrictiveDbRole
),
sprintf(
$statements = [
sprintf('CREATE ROLE %s', self::$dbRole),
sprintf('CREATE ROLE %s', self::$restrictiveDbRole),
];

if (!self::isEmulatorUsed()) {
$statements[] = sprintf(
'GRANT SELECT(id) ON TABLE %s TO %s',
self::$tableName,
self::$restrictiveDbRole
),
sprintf(
);
$statements[] = sprintf(
'GRANT SELECT ON TABLE %s TO %s',
self::$tableName,
self::$dbRole
)
])->pollUntilComplete();
);
}

self::$database->updateDdlBatch($statements)->pollUntilComplete();
}

self::seedTable();
self::$isSetup = true;
self::$hasSetupBatch = true;
}

/**
Expand Down
Loading
Loading