diff --git a/.github/workflows/backwards-compatibility-check.yaml b/.github/workflows/backwards-compatibility-checks.yaml similarity index 71% rename from .github/workflows/backwards-compatibility-check.yaml rename to .github/workflows/backwards-compatibility-checks.yaml index 33efeab1682d..64995944328e 100644 --- a/.github/workflows/backwards-compatibility-check.yaml +++ b/.github/workflows/backwards-compatibility-checks.yaml @@ -1,4 +1,4 @@ -name: Backwards Compatibility Check +name: Backwards Compatibility on: pull_request: types: [opened, synchronize, reopened, edited] @@ -6,6 +6,7 @@ on: jobs: # More info at https://github.com/Roave/BackwardCompatibilityCheck. backwards-compatibility-check: + name: Breaking Change Detector runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -46,10 +47,45 @@ jobs: --from=${{ steps.latest-release.outputs.release }} \ --to=origin/main --format=github-actions + # Ensure that PRs labeled "feat" actually contain a new feature, PRs labeled + # "bug" or "chore" do not. + conventional-commit-check: + name: Conventional Commit Check + runs-on: ubuntu-latest + if: github.event.pull_request.user.login == 'gcf-owl-bot[bot]' + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Install PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: "8.1" + - name: "Install dependencies" + run: composer global require "roave/backward-compatibility-check:^8.2" + - name: "Check for an incorrect feat label in the PR" + id: compatibility-checker + continue-on-error: true + # OwlBot PRs which are not labelled feat should not add new files or methods + run: | + ~/.composer/vendor/bin/roave-backward-compatibility-check --to=origin/main --format=github-actions + - name: "Print the action item" + run: | + if [[ "${{ steps.compatibility-checker.outcome }}" == 'failure' ]]; then + if [[ "${{ startsWith(github.event.pull_request.title, 'feat') }}" == "true" ]]; then + echo "Action item: Change the conventional commit to use 'feat'" + exit 1 + fi + elif [[ "${{ startsWith(github.event.pull_request.title, 'feat') }}" == "false" ]]; then + echo "Action item: No features found, do not use 'feat' for the conventional commit" + exit 1 + fi + # Ensure the release PR does not contain an unexpected (e.g. 2.0.0) major version release # Add "MAJOR_VERSION_ALLOWED=component1,component2" to the PR description to allow major version # releases for those components unexpected-major-version-check: + name: Unexpected Major Version Check runs-on: ubuntu-latest if: github.event.pull_request.user.login == 'release-please[bot]' steps: diff --git a/.github/workflows/storage-emulator-retry-conformance-tests.yaml b/.github/workflows/conformance-tests-storage-emulator.yaml similarity index 85% rename from .github/workflows/storage-emulator-retry-conformance-tests.yaml rename to .github/workflows/conformance-tests-storage-emulator.yaml index 9385fd7ca7a1..fe5d0d6fb59f 100644 --- a/.github/workflows/storage-emulator-retry-conformance-tests.yaml +++ b/.github/workflows/conformance-tests-storage-emulator.yaml @@ -4,11 +4,11 @@ on: - main paths: - 'Storage/**' - - '.github/workflows/storage-emulator-retry-conformance-tests.yaml' + - '.github/workflows/emulator-conformance-tests-storage.yaml' pull_request: paths: - 'Storage/**' - - '.github/workflows/storage-emulator-retry-conformance-tests.yaml' + - '.github/workflows/emulator-conformance-tests-storage.yaml' name: Run Storage Retry Conformance Tests With Emulator jobs: test: diff --git a/.github/workflows/incorrect-conventional-commit-check.yaml b/.github/workflows/incorrect-conventional-commit-check.yaml deleted file mode 100644 index 6071e5453719..000000000000 --- a/.github/workflows/incorrect-conventional-commit-check.yaml +++ /dev/null @@ -1,34 +0,0 @@ -name: Conventional Commit Check -on: - pull_request: - types: [opened, synchronize, reopened, edited] - branches: ['main'] -jobs: - # More info at https://github.com/Roave/BackwardCompatibilityCheck. - incorrect-conventional-commit-check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: "Install PHP" - uses: shivammathur/setup-php@v2 - with: - php-version: "8.1" - - name: "Install dependencies" - run: composer global require "roave/backward-compatibility-check:^8.2" - - name: "Check for an incorrect feat label in the PR" - id: compatibility-checker - if: ${{ github.event.pull_request.user.login == 'gcf-owl-bot' && !startsWith(github.event.pull_request.title, 'feat')}} - continue-on-error: true - # OwlBot PRs which are not labelled feat should not add new files or methods - run: | - ~/.composer/vendor/bin/roave-backward-compatibility-check \ - --from=${{ github.event.pull_request.head.sha }} \ - --to=${{ github.event.pull_request.base.sha }} - - name: "Print the action item" - run: | - if [[ "${{ steps.compatibility-checker.outcome }}" == 'failure' ]]; then - echo "Action item: Change the PR label to feat" - exit 1 - fi diff --git a/.github/workflows/bigtable-emulator-system-tests.yaml b/.github/workflows/system-tests-bigtable-emulator.yaml similarity index 90% rename from .github/workflows/bigtable-emulator-system-tests.yaml rename to .github/workflows/system-tests-bigtable-emulator.yaml index b06fc5c52ce7..6cc00a8032cb 100644 --- a/.github/workflows/bigtable-emulator-system-tests.yaml +++ b/.github/workflows/system-tests-bigtable-emulator.yaml @@ -4,12 +4,12 @@ on: - main paths: - 'Bigtable/**' - - '.github/workflows/bigtable-emulator-system-tests.yaml' + - '.github/workflows/system-tests-bigtable-emulator.yaml' - '.github/emulator/**' pull_request: paths: - 'Bigtable/**' - - '.github/workflows/bigtable-emulator-system-tests.yaml' + - '.github/workflows/system-tests-bigtable-emulator.yaml' - '.github/emulator/**' name: Run Bigtable System Tests With Emulator permissions: diff --git a/.github/workflows/datastore-emulator-system-tests.yaml b/.github/workflows/system-tests-datastore-emulator.yaml similarity index 90% rename from .github/workflows/datastore-emulator-system-tests.yaml rename to .github/workflows/system-tests-datastore-emulator.yaml index 583c22aa68d3..722ebd2a9546 100644 --- a/.github/workflows/datastore-emulator-system-tests.yaml +++ b/.github/workflows/system-tests-datastore-emulator.yaml @@ -5,12 +5,12 @@ on: - main paths: - 'Datastore/**' - - '.github/workflows/datastore-emulator-system-tests.yaml' + - '.github/workflows/system-tests-datastore-emulator.yaml' - '.github/emulator/**' pull_request: paths: - 'Datastore/**' - - '.github/workflows/datastore-emulator-system-tests.yaml' + - '.github/workflows/system-tests-datastore-emulator.yaml' - '.github/emulator/**' permissions: contents: read diff --git a/.github/workflows/firestore-emulator-system-tests.yaml b/.github/workflows/system-tests-firestore-emulator.yaml similarity index 90% rename from .github/workflows/firestore-emulator-system-tests.yaml rename to .github/workflows/system-tests-firestore-emulator.yaml index a68a42f87423..0a9c182c507e 100644 --- a/.github/workflows/firestore-emulator-system-tests.yaml +++ b/.github/workflows/system-tests-firestore-emulator.yaml @@ -4,12 +4,12 @@ on: - main paths: - 'Firestore/**' - - '.github/workflows/firestore-emulator-system-tests.yaml' + - '.github/workflows/system-tests-firestore-emulator.yaml' - '.github/emulator/**' pull_request: paths: - 'Firestore/**' - - '.github/workflows/firestore-emulator-system-tests.yaml' + - '.github/workflows/system-tests-firestore-emulator.yaml' - '.github/emulator/**' name: Run Firestore System Tests With Emulator permissions: diff --git a/.github/workflows/pubsub-emulator-system-tests.yaml b/.github/workflows/system-tests-pubsub-emulator.yaml similarity index 90% rename from .github/workflows/pubsub-emulator-system-tests.yaml rename to .github/workflows/system-tests-pubsub-emulator.yaml index 76b2837b950f..df9feb0c5653 100644 --- a/.github/workflows/pubsub-emulator-system-tests.yaml +++ b/.github/workflows/system-tests-pubsub-emulator.yaml @@ -4,12 +4,12 @@ on: - main paths: - 'PubSub/**' - - '.github/workflows/pubsub-emulator-system-tests.yaml' + - '.github/workflows/system-tests-pubsub-emulator.yaml' - '.github/emulator/**' pull_request: paths: - 'PubSub/**' - - '.github/workflows/pubsub-emulator-system-tests.yaml' + - '.github/workflows/system-tests-pubsub-emulator.yaml' - '.github/emulator/**' name: Run PubSub System Tests With Emulator permissions: diff --git a/.github/workflows/spanner-emulator-system-tests.yaml b/.github/workflows/system-tests-spanner-emulator.yaml similarity index 93% rename from .github/workflows/spanner-emulator-system-tests.yaml rename to .github/workflows/system-tests-spanner-emulator.yaml index c8bba2c085c8..7b3689b6dfd7 100644 --- a/.github/workflows/spanner-emulator-system-tests.yaml +++ b/.github/workflows/system-tests-spanner-emulator.yaml @@ -4,11 +4,11 @@ on: - main paths: - 'Spanner/**' - - '.github/workflows/spanner-emulator-system-tests.yaml' + - '.github/workflows/system-tests-spanner-emulator.yaml' pull_request: paths: - 'Spanner/**' - - '.github/workflows/spanner-emulator-system-tests.yaml' + - '.github/workflows/system-tests-spanner-emulator.yaml' name: Run Spanner System Tests With Emulator permissions: contents: read diff --git a/.github/workflows/system-tests.yaml b/.github/workflows/system-tests.yaml new file mode 100644 index 000000000000..3bdc84b0d9a6 --- /dev/null +++ b/.github/workflows/system-tests.yaml @@ -0,0 +1,31 @@ +name: System Tests +on: + pull_request: + workflow_dispatch: +jobs: + # Run system tests on the release PR + system-tests: + name: Run System Test Suite + runs-on: ubuntu-latest + if: github.event.pull_request.user.login == 'release-please[bot]' || github.event_name == 'workflow_dispatch' + env: + ASSET_TEST_BUCKET: cloud-php-testdata + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup PHP + uses: shivammathur/setup-php@verbose + with: + php-version: "8.1" + extensions: grpc + ini-values: grpc.grpc_verbosity=error + - name: Save secrets to file + run: | + echo "${{ secrets.GOOGLE_CLOUD_PHP_TESTS_KEY }}" | base64 -d > ${{ runner.temp }}/service-account.json + - name: Install dependencies + run: composer --no-interaction --no-ansi --no-progress update + - name: Run System Tests + run: vendor/bin/phpunit -c phpunit-system.xml.dist --colors=always --exclude-group=flakey + env: + GOOGLE_CLOUD_PHP_TESTS_KEY_PATH: ${{ runner.temp }}/service-account.json diff --git a/.github/workflows/tests.yaml b/.github/workflows/unit-tests.yaml similarity index 100% rename from .github/workflows/tests.yaml rename to .github/workflows/unit-tests.yaml diff --git a/.kokoro/continuous/php81.cfg b/.kokoro/continuous/php81.cfg deleted file mode 100644 index e1e6f7e4f098..000000000000 --- a/.kokoro/continuous/php81.cfg +++ /dev/null @@ -1,59 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Download trampoline resources. These will be in ${KOKORO_GFILE_DIR} -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# All builds use the trampoline script to run in docker. -build_file: "google-cloud-php/.kokoro/trampoline.sh" - -# Configure the build command -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/google-cloud-php/.kokoro/continuous/run-tests.sh" -} - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/php81" -} - -# key files from keystore -env_vars: { - key: "GOOGLE_CLOUD_PHP_TESTS_KEY_PATH" - value: "71386_google-cloud-php-system-test-service-account" -} - -env_vars: { - key: "GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH" - value: "71386_google-cloud-php-system-test-firestore-service-account" -} - -env_vars: { - key: "GOOGLE_CLOUD_PHP_WHITELIST_TESTS_KEY_PATH" - value: "71386_google-cloud-php-system-test-whitelist-service-account" -} - -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Fetch keystore keys -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 71386 - keyname: "google-cloud-php-system-test-service-account" - } - keystore_resource { - keystore_config_id: 71386 - keyname: "google-cloud-php-system-test-whitelist-service-account" - } - keystore_resource { - keystore_config_id: 71386 - keyname: "google-cloud-php-system-test-firestore-service-account" - } - } -} diff --git a/.kokoro/continuous/run-tests.sh b/.kokoro/continuous/run-tests.sh deleted file mode 100755 index 354254ce987e..000000000000 --- a/.kokoro/continuous/run-tests.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -set -ex - -pushd github/google-cloud-php -composer --no-interaction --no-ansi --no-progress update - -SHORT_JOB_NAME=${KOKORO_JOB_NAME##*/} - -mkdir -p ${SHORT_JOB_NAME}/unit -mkdir -p ${SHORT_JOB_NAME}/snippets -mkdir -p ${SHORT_JOB_NAME}/system - -UNIT_LOG_FILENAME=${SHORT_JOB_NAME}/unit/sponge_log.xml -SNIPPETS_LOG_FILENAME=${SHORT_JOB_NAME}/snippets/sponge_log.xml -SYSTEM_LOG_FILENAME=${SHORT_JOB_NAME}/system/sponge_log.xml - -if [ ! -z "${GOOGLE_CLOUD_PHP_TESTS_KEY_PATH}" ]; then - export GOOGLE_CLOUD_PHP_TESTS_KEY_PATH="${KOKORO_KEYSTORE_DIR}/${GOOGLE_CLOUD_PHP_TESTS_KEY_PATH}" -fi - -if [ ! -z "${GOOGLE_CLOUD_PHP_WHITELIST_TESTS_KEY_PATH}" ]; then - export GOOGLE_CLOUD_PHP_WHITELIST_TESTS_KEY_PATH="${KOKORO_KEYSTORE_DIR}/${GOOGLE_CLOUD_PHP_WHITELIST_TESTS_KEY_PATH}" -fi - -if [ ! -z "${GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH}" ]; then - export GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH="${KOKORO_KEYSTORE_DIR}/${GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH}" -fi - -# non-secret env vars -export ASSET_TEST_BUCKET="php_asset_test_bucket" - -PHP_VERSION=$(php -r 'echo PHP_MAJOR_VERSION;') -if [ "5" == $PHP_VERSION ]; then - # Exclude compute if the PHP version is below 7.0 - PHPUNIT_SUFFIX="-php5" -fi - -echo "Running Unit Test Suite" -vendor/bin/phpunit -c phpunit${PHPUNIT_SUFFIX}.xml.dist --log-junit ${UNIT_LOG_FILENAME} - -echo "Running Snippet Test Suite" -vendor/bin/phpunit -c phpunit-snippets.xml.dist --verbose --log-junit \ - ${SNIPPETS_LOG_FILENAME} - -echo "Running System Test Suite" -vendor/bin/phpunit -d memory_limit=512M -c phpunit${PHPUNIT_SUFFIX}-system.xml.dist \ - --verbose --log-junit ${SYSTEM_LOG_FILENAME} - -popd diff --git a/Asset/tests/System/V1/AssetServiceSmokeTest.php b/Asset/tests/System/V1/AssetServiceSmokeTest.php index d1204c021a89..fe6a3321887b 100644 --- a/Asset/tests/System/V1/AssetServiceSmokeTest.php +++ b/Asset/tests/System/V1/AssetServiceSmokeTest.php @@ -16,9 +16,9 @@ */ namespace Google\Cloud\Asset\Tests\System\V1; -use Google\Cloud\Asset\V1\AssetServiceClient; -use Google\Cloud\Asset\V1\GcsDestination; -use Google\Cloud\Asset\V1\OutputConfig; +use Google\Cloud\Asset\V1\Asset; +use Google\Cloud\Asset\V1\Client\AssetServiceClient; +use Google\Cloud\Asset\V1\ListAssetsRequest; use Google\Cloud\Core\Testing\System\SystemTestCase; /** @@ -36,20 +36,9 @@ public function smokeTest() if ($projectId === false) { $this->fail('Environment variable PROJECT_ID must be set for smoke test'); } - $bucket = getenv('ASSET_TEST_BUCKET'); - if ($bucket === false) { - $this->fail('Environment variable ASSET_TEST_BUCKET must be set for smoke test'); - } $client = new AssetServiceClient(); - $objectPath = "gs://$bucket/cai-system-test"; - $gcsDestination = new GcsDestination(['uri' => $objectPath]); - $outputConfig = new OutputConfig([ - 'gcs_destination' => $gcsDestination - ]); - - $resp = $client->exportAssets("projects/$projectId", $outputConfig); - $resp->pollUntilComplete(); - $this->assertTrue($resp->operationSucceeded()); + $response = $client->listAssets(ListAssetsRequest::build('projects/' . $projectId)); + $this->assertInstanceOf(Asset::class, $response->getIterator()->current()); } } diff --git a/BigQuery/tests/System/BigQueryTestCase.php b/BigQuery/tests/System/BigQueryTestCase.php index f64a4cae3b7b..fa00e52222dd 100644 --- a/BigQuery/tests/System/BigQueryTestCase.php +++ b/BigQuery/tests/System/BigQueryTestCase.php @@ -22,7 +22,7 @@ use Google\Cloud\Storage\StorageClient; use Google\Cloud\Core\Testing\System\SystemTestCase; -class BigQueryTestCase extends SystemTestCase +abstract class BigQueryTestCase extends SystemTestCase { const TESTING_PREFIX = 'gcloud_testing_'; const ENCRYPTION_SERVICE_ACCOUNT_EMAIL_TEMPLATE = 'bq-%s@bigquery-encryption.iam.gserviceaccount.com'; @@ -35,7 +35,10 @@ class BigQueryTestCase extends SystemTestCase protected static $table; private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/BigQuery/tests/System/ManageModelsTest.php b/BigQuery/tests/System/ManageModelsTest.php index 18f0b45b6f62..065689e1810c 100644 --- a/BigQuery/tests/System/ManageModelsTest.php +++ b/BigQuery/tests/System/ManageModelsTest.php @@ -37,9 +37,12 @@ class ManageModelsTest extends BigQueryTestCase private static $keyName1; private static $keyName2; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$modelId = uniqid(self::TESTING_PREFIX); diff --git a/BigQuery/tests/System/ManageRoutinesTest.php b/BigQuery/tests/System/ManageRoutinesTest.php index 3ba9c7750e37..3b6f4b60c1b9 100644 --- a/BigQuery/tests/System/ManageRoutinesTest.php +++ b/BigQuery/tests/System/ManageRoutinesTest.php @@ -27,9 +27,12 @@ class ManageRoutinesTest extends BigQueryTestCase { private static $routines = []; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); for ($i = 0; $i < 2; $i++) { $routineId = uniqid(self::TESTING_PREFIX); diff --git a/BigQuery/tests/System/ManageTablesTest.php b/BigQuery/tests/System/ManageTablesTest.php index 4acf5fe36b5d..c2ffe13d6902 100644 --- a/BigQuery/tests/System/ManageTablesTest.php +++ b/BigQuery/tests/System/ManageTablesTest.php @@ -169,6 +169,9 @@ public function testReloadsTable() public function testCreatesExternalTable() { $externalKeyFilePath = getenv('GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH'); + if (!$externalKeyFilePath) { + $this->markTestSkipped('GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH must be set to run this test.'); + } $authenticatedKeyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); $externalKey = json_decode(file_get_contents($externalKeyFilePath), true); $authenticatedKey = json_decode(file_get_contents($authenticatedKeyFilePath), true); diff --git a/BigQuery/tests/System/RegionalizationTest.php b/BigQuery/tests/System/RegionalizationTest.php index a5e92acc7d6e..9f28a23783c8 100644 --- a/BigQuery/tests/System/RegionalizationTest.php +++ b/BigQuery/tests/System/RegionalizationTest.php @@ -33,9 +33,12 @@ class RegionalizationTest extends BigQueryTestCase private static $tableAsia; private static $bucketAsia; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$datasetAsia = self::createDataset( self::$client, uniqid(self::TESTING_PREFIX), diff --git a/Bigtable/tests/System/BackupTests.php b/Bigtable/tests/System/BackupTests.php index 854718d0ff54..a3c0794b7908 100644 --- a/Bigtable/tests/System/BackupTests.php +++ b/Bigtable/tests/System/BackupTests.php @@ -64,9 +64,12 @@ class BackupTests extends BigtableTestCase */ private static $copyBackupClusterId; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$backupId = uniqid('backup'); self::$copyBackupId = 'copy' . self::$backupId; @@ -78,8 +81,10 @@ public static function setUpBeforeClass(): void ); self::$copyBackupClusterId = uniqid(self::CLUSTER_ID_PREFIX); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { // Delete the base backup self::deleteBackupIfExists(self::$tableAdminClient, self::$backupName); diff --git a/Bigtable/tests/System/BigtableInstanceAdminClientTest.php b/Bigtable/tests/System/BigtableInstanceAdminClientTest.php index eda7f68a49cd..ea7f96d9e651 100644 --- a/Bigtable/tests/System/BigtableInstanceAdminClientTest.php +++ b/Bigtable/tests/System/BigtableInstanceAdminClientTest.php @@ -31,7 +31,7 @@ class BigtableInstanceAdminClientTest extends TestCase public function clientProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); return [ [self::$restClient], @@ -39,7 +39,10 @@ public function clientProvider() ]; } - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/Bigtable/tests/System/BigtableTestCase.php b/Bigtable/tests/System/BigtableTestCase.php index 642eb5901be3..edcac1676d88 100644 --- a/Bigtable/tests/System/BigtableTestCase.php +++ b/Bigtable/tests/System/BigtableTestCase.php @@ -49,7 +49,10 @@ class BigtableTestCase extends SystemTestCase protected static $instanceId; protected static $clusterId; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::setUsingEmulator(getenv('BIGTABLE_EMULATOR_HOST')); $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); @@ -73,8 +76,10 @@ public static function setUpBeforeClass(): void } self::createTable(); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::deleteTable(); if (!self::isEmulatorUsed()) { diff --git a/Bigtable/tests/System/CheckAndMutateRowTest.php b/Bigtable/tests/System/CheckAndMutateRowTest.php index fbead7baef52..21fbf03e4e6a 100644 --- a/Bigtable/tests/System/CheckAndMutateRowTest.php +++ b/Bigtable/tests/System/CheckAndMutateRowTest.php @@ -26,9 +26,12 @@ */ class CheckAndMutateRowTest extends BigtableTestCase { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); $insertRows = [ 'rk1' => [ 'cf1' => [ diff --git a/Bigtable/tests/System/FilterTest.php b/Bigtable/tests/System/FilterTest.php index fc374571b398..074b866573fe 100644 --- a/Bigtable/tests/System/FilterTest.php +++ b/Bigtable/tests/System/FilterTest.php @@ -28,9 +28,12 @@ class FilterTest extends BigtableTestCase { protected static $rowMutations = []; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$table->mutateRows(self::$rowMutations); } @@ -449,9 +452,4 @@ public function testSample() ); $this->assertGreaterThan(0, count($rows)); } - - public function testLabel() - { - //TODO Implement label test - } } diff --git a/Bigtable/tests/System/ReadModifyWriteRowTest.php b/Bigtable/tests/System/ReadModifyWriteRowTest.php index 066e72131630..513039b23930 100644 --- a/Bigtable/tests/System/ReadModifyWriteRowTest.php +++ b/Bigtable/tests/System/ReadModifyWriteRowTest.php @@ -26,9 +26,12 @@ */ class ReadModifyWriteRowTest extends BigtableTestCase { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); $insertRows = [ 'rk1' => [ 'cf1' => [ diff --git a/Bigtable/tests/System/ReadRowsTest.php b/Bigtable/tests/System/ReadRowsTest.php index 1317a4eb26b2..f47c16309f15 100644 --- a/Bigtable/tests/System/ReadRowsTest.php +++ b/Bigtable/tests/System/ReadRowsTest.php @@ -23,9 +23,12 @@ */ class ReadRowsTest extends BigtableTestCase { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); $insertRows = [ 'rk1' => [ 'cf1' => [ diff --git a/Bigtable/tests/System/SampleRowKeysTest.php b/Bigtable/tests/System/SampleRowKeysTest.php index 4f88f3a642ed..777584e047d0 100644 --- a/Bigtable/tests/System/SampleRowKeysTest.php +++ b/Bigtable/tests/System/SampleRowKeysTest.php @@ -23,9 +23,12 @@ */ class SampleRowKeysTest extends BigtableTestCase { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); $insertRows = [ 'rk1' => [ 'cf1' => [ diff --git a/Compute/tests/System/V1/AddressTest.php b/Compute/tests/System/V1/AddressTest.php index fce2ae2d8723..bae72ff46f92 100644 --- a/Compute/tests/System/V1/AddressTest.php +++ b/Compute/tests/System/V1/AddressTest.php @@ -29,7 +29,10 @@ class AddressTest extends SystemTestCase protected static $projectId; protected static $name; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::$projectId = getenv('PROJECT_ID'); if (self::$projectId === false) { @@ -38,8 +41,10 @@ public static function setUpBeforeClass(): void self::$addressesClient = new AddressesClient(); self::$name = "gapicphp" . strval(rand(100000, 999999)); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::$addressesClient->close(); } diff --git a/Compute/tests/System/V1/FirewallsTest.php b/Compute/tests/System/V1/FirewallsTest.php index e2e5ba98c982..ed35cbf2a72f 100644 --- a/Compute/tests/System/V1/FirewallsTest.php +++ b/Compute/tests/System/V1/FirewallsTest.php @@ -31,7 +31,10 @@ class FirewallsTest extends SystemTestCase protected static $name; protected static $globalClient; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::$projectId = getenv('PROJECT_ID'); if (self::$projectId === false) { @@ -40,8 +43,10 @@ public static function setUpBeforeClass(): void self::$client = new FirewallsClient(); self::$name = 'gapicphp' . strval(rand(100000, 999999)); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::$client->close(); } diff --git a/Compute/tests/System/V1/PaginationTest.php b/Compute/tests/System/V1/PaginationTest.php index 56b12eb1b0ee..cc4e753d2319 100644 --- a/Compute/tests/System/V1/PaginationTest.php +++ b/Compute/tests/System/V1/PaginationTest.php @@ -34,7 +34,10 @@ class PaginationTest extends TestCase private static $projectId; private static $zone; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::$projectId = getenv('PROJECT_ID'); if (self::$projectId === false) { @@ -53,8 +56,10 @@ public static function setUpBeforeClass(): void self::fail('Atleast 4 instances are required for test run'); } } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::$instancesClient->close(); self::$zonesClient->close(); diff --git a/Compute/tests/System/V1/SmokeTest.php b/Compute/tests/System/V1/SmokeTest.php index 988a41636d78..b0e8380f6493 100644 --- a/Compute/tests/System/V1/SmokeTest.php +++ b/Compute/tests/System/V1/SmokeTest.php @@ -39,7 +39,7 @@ class SmokeTest extends SystemTestCase { const ZONE = 'us-central1-a'; - const IMAGE = 'projects/debian-cloud/global/images/family/debian-10'; + const IMAGE = 'projects/debian-cloud/global/images/family/debian-11'; protected static $instancesClient; protected static $projectId; @@ -47,7 +47,10 @@ class SmokeTest extends SystemTestCase protected static $name; protected static $zoneOperationsClient; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::$projectId = getenv('PROJECT_ID'); if (self::$projectId === false) { @@ -62,8 +65,10 @@ public static function setUpBeforeClass(): void ); self::$name = 'gapicphp' . strval(rand(100000, 999999)); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::$instancesClient->close(); } diff --git a/Container/tests/System/V1/ClusterManagerSmokeTest.php b/Container/tests/System/V1/ClusterManagerSmokeTest.php index 341e1200efdf..59485b59efc0 100644 --- a/Container/tests/System/V1/ClusterManagerSmokeTest.php +++ b/Container/tests/System/V1/ClusterManagerSmokeTest.php @@ -22,7 +22,8 @@ namespace Google\Cloud\Container\Tests\System\V1; -use Google\Cloud\Container\V1\ClusterManagerClient; +use Google\Cloud\Container\V1\Client\ClusterManagerClient; +use Google\Cloud\Container\V1\ListClustersRequest; use Google\ApiCore\Testing\GeneratedTest; /** @@ -42,8 +43,8 @@ public function listClustersTest() } $clusterManagerClient = new ClusterManagerClient(); - $projectId2 = $projectId; $zone = 'us-central1-a'; - $clusterManagerClient->listClusters(['projectId' => $projectId2, 'zone' => $zone]); + $request = ListClustersRequest::build($projectId, $zone); + $clusterManagerClient->listClusters($request); } } diff --git a/Core/src/Testing/System/SystemTestCase.php b/Core/src/Testing/System/SystemTestCase.php index c0dc573a7d06..1b1e257c5aec 100644 --- a/Core/src/Testing/System/SystemTestCase.php +++ b/Core/src/Testing/System/SystemTestCase.php @@ -35,7 +35,7 @@ * @experimental * @internal */ -class SystemTestCase extends TestCase +abstract class SystemTestCase extends TestCase { protected static $deletionQueue; diff --git a/Core/src/Testing/TestHelpers.php b/Core/src/Testing/TestHelpers.php index e2050d6356ff..0faf64bb10f8 100644 --- a/Core/src/Testing/TestHelpers.php +++ b/Core/src/Testing/TestHelpers.php @@ -23,6 +23,7 @@ use Google\Cloud\Core\Testing\Snippet\Coverage\Coverage; use Google\Cloud\Core\Testing\Snippet\Coverage\Scanner; use Google\Cloud\Core\Testing\Snippet\Parser\Parser; +use Google\Cloud\Core\Testing\Snippet\Fixtures; use Google\Cloud\Core\Testing\System\SystemTestCase; /** @@ -106,7 +107,7 @@ public function call($fn, array $args = []) { return call_user_func_array([$this */ public static function snippetBootstrap() { - putenv('GOOGLE_APPLICATION_CREDENTIALS='. \Google\Cloud\Core\Testing\Snippet\Fixtures::KEYFILE_STUB_FIXTURE()); + putenv('GOOGLE_APPLICATION_CREDENTIALS='. Fixtures::KEYFILE_STUB_FIXTURE()); $parser = new Parser; $scanner = new Scanner($parser, self::projectRoot(), [ @@ -190,6 +191,7 @@ public static function systemBootstrap() // also set up the generated system tests self::generatedSystemTestBootstrap(); $bootstraps = glob(self::projectRoot() .'/*tests/System/bootstrap.php'); + foreach ($bootstraps as $bootstrap) { require_once $bootstrap; } @@ -212,6 +214,9 @@ public static function generatedSystemTestBootstrap() // For generated system tests, we need to set GOOGLE_APPLICATION_CREDENTIALS // and PROJECT_ID to appropriate values $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); + if (empty($keyFilePath)) { + exit('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH must be set to run system tests.'); + } putenv("GOOGLE_APPLICATION_CREDENTIALS=$keyFilePath"); $keyFileData = json_decode(file_get_contents($keyFilePath), true); putenv('PROJECT_ID=' . $keyFileData['project_id']); diff --git a/Core/tests/System/Batch/BatchRunnerTest.php b/Core/tests/System/Batch/BatchRunnerTest.php index 262495f15693..2c96913fd65d 100644 --- a/Core/tests/System/Batch/BatchRunnerTest.php +++ b/Core/tests/System/Batch/BatchRunnerTest.php @@ -49,7 +49,10 @@ public static function delTree($dir) return rmdir($dir); } - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::$testDir = sprintf( '%s/google-cloud-system-test-%d', @@ -89,8 +92,10 @@ public static function setUpBeforeClass(): void putenv('IS_BATCH_DAEMON_RUNNING'); } } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { @proc_terminate(self::$daemon); @proc_close(self::$daemon); @@ -167,7 +172,8 @@ public function testSubmit() } // sleep(1); usleep(500000); - $this->assertResultContains('BANANA'); - $this->assertResultContains('LEMON' . PHP_EOL); + $result = $this->getResult(); + $this->assertStringNotContainsString('BANANA', $result); + $this->assertStringContainsString('LEMON' . PHP_EOL, $result); } } diff --git a/Datastore/tests/System/AggregationQueryTest.php b/Datastore/tests/System/AggregationQueryTest.php index 283a8e3c3c35..9056d129bff0 100644 --- a/Datastore/tests/System/AggregationQueryTest.php +++ b/Datastore/tests/System/AggregationQueryTest.php @@ -42,9 +42,12 @@ class AggregationQueryTest extends DatastoreMultipleDbTestCase ['arrayScore' => [10]] ]; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$kind = uniqid('testKind'); $keys = self::$restClient->keys(self::$kind, ['number' => count(self::$data)]); $keys = self::$restClient->allocateIds($keys); @@ -61,8 +64,10 @@ public static function setUpBeforeClass(): void self::$localDeletionQueue->add($key); } } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::tearDownFixtures(); } diff --git a/Datastore/tests/System/DatastoreMultipleDbTest.php b/Datastore/tests/System/DatastoreMultipleDbTest.php index 43c0ce5b64a5..7969670d0f82 100644 --- a/Datastore/tests/System/DatastoreMultipleDbTest.php +++ b/Datastore/tests/System/DatastoreMultipleDbTest.php @@ -48,7 +48,10 @@ class DatastoreMultipleDbTest extends DatastoreMultipleDbTestCase ], ]; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { parent::setUpMultiDbBeforeClass(); self::$ancestor = self::$restMultiDbClient->key(self::$kind, 'V_A'); @@ -75,8 +78,10 @@ public static function setUpBeforeClass(): void self::$localDeletionQueue->add($key2); self::$localDeletionQueue->add($key3); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::tearDownFixtures(); } diff --git a/Datastore/tests/System/DatastoreMultipleDbTestCase.php b/Datastore/tests/System/DatastoreMultipleDbTestCase.php index 79b425befc94..d150c2a74f59 100644 --- a/Datastore/tests/System/DatastoreMultipleDbTestCase.php +++ b/Datastore/tests/System/DatastoreMultipleDbTestCase.php @@ -72,7 +72,7 @@ public static function setUpMultiDbBeforeClass() public function multiDbClientProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); self::setUpMultiDbBeforeClass(); if (!self::$multipleDbValidationResult) { diff --git a/Datastore/tests/System/DatastoreTestCase.php b/Datastore/tests/System/DatastoreTestCase.php index cce2b0410a55..1f38fb6b2f59 100644 --- a/Datastore/tests/System/DatastoreTestCase.php +++ b/Datastore/tests/System/DatastoreTestCase.php @@ -37,7 +37,10 @@ class DatastoreTestCase extends TestCase protected static $localDeletionQueue; private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; @@ -81,7 +84,7 @@ public static function tearDownFixtures() public function defaultDbClientProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); return [ 'restClient' => [self::$restClient], diff --git a/Datastore/tests/System/FilterTest.php b/Datastore/tests/System/FilterTest.php index dd971aab50ee..447caa25f3e1 100644 --- a/Datastore/tests/System/FilterTest.php +++ b/Datastore/tests/System/FilterTest.php @@ -27,7 +27,10 @@ class FilterTest extends DatastoreMultipleDbTestCase { private static $kind = 'People'; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { parent::setUpMultiDbBeforeClass(); $data = self::getInitialData(); @@ -47,8 +50,10 @@ public static function setUpBeforeClass(): void self::$localDeletionQueue->add($entity->key()); } } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::tearDownFixtures(); } diff --git a/Datastore/tests/System/QueryResultPaginationTest.php b/Datastore/tests/System/QueryResultPaginationTest.php index 067154d70a42..9ec74a56f6d6 100644 --- a/Datastore/tests/System/QueryResultPaginationTest.php +++ b/Datastore/tests/System/QueryResultPaginationTest.php @@ -30,9 +30,12 @@ class QueryResultPaginationTest extends DatastoreMultipleDbTestCase private static $parentKey; private static $testKind; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); static $setUp = false; if ($setUp) { return; @@ -66,10 +69,12 @@ public static function setUpBeforeClass(): void $setUp = true; } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { - self::setUpBeforeClass(); + self::setUpTestFixtures(); $client = self::$restClient; $q = $client->query() diff --git a/Datastore/tests/System/RunQueryTest.php b/Datastore/tests/System/RunQueryTest.php index 868f7b520957..4e384315b76d 100644 --- a/Datastore/tests/System/RunQueryTest.php +++ b/Datastore/tests/System/RunQueryTest.php @@ -52,9 +52,12 @@ class RunQueryTest extends DatastoreMultipleDbTestCase ] ]; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$ancestor = self::$restClient->key(self::$kind, 'Grandpa Frank'); $key1 = self::$restClient->key(self::$kind, 'Frank'); $key1->ancestorKey(self::$ancestor); @@ -79,8 +82,10 @@ public static function setUpBeforeClass(): void self::$localDeletionQueue->add($key2); self::$localDeletionQueue->add($key3); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::tearDownFixtures(); } diff --git a/Debugger/tests/System/E2ETest.php b/Debugger/tests/System/E2ETest.php index 003b82f1d2e1..9611cd858648 100644 --- a/Debugger/tests/System/E2ETest.php +++ b/Debugger/tests/System/E2ETest.php @@ -63,8 +63,10 @@ public function setUp(): void $this->debuggeeId = $data['debuggeeId']; }, 5, true); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::deleteApp(); } diff --git a/Firestore/tests/System/Admin/V1/FirestoreAdminClientSmokeTest.php b/Firestore/tests/System/Admin/V1/FirestoreAdminClientSmokeTest.php index d16d3bf72f6d..4d57392fb3b1 100644 --- a/Firestore/tests/System/Admin/V1/FirestoreAdminClientSmokeTest.php +++ b/Firestore/tests/System/Admin/V1/FirestoreAdminClientSmokeTest.php @@ -36,12 +36,18 @@ class FirestoreAdminClientSmokeTest extends SystemTestCase private static $projectId; private static $hasSetup = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetup) { return; } $keyFilePath = getenv('GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH'); + if (!$keyFilePath) { + self::markTestSkipped('Set the GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH env var to run system tests'); + } $keyFileData = json_decode(file_get_contents($keyFilePath), true); self::$projectId = $keyFileData['project_id']; self::$adminClient = new FirestoreAdminClient([ diff --git a/Firestore/tests/System/FirestoreTestCase.php b/Firestore/tests/System/FirestoreTestCase.php index 276f556f7f2a..66a3e06d4d41 100644 --- a/Firestore/tests/System/FirestoreTestCase.php +++ b/Firestore/tests/System/FirestoreTestCase.php @@ -37,7 +37,10 @@ class FirestoreTestCase extends SystemTestCase protected static $localDeletionQueue; private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; @@ -46,6 +49,9 @@ public static function setUpBeforeClass(): void self::$localDeletionQueue = new DeletionQueue(true); $keyFilePath = getenv('GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH'); + if (false === $keyFilePath) { + self::markTestSkipped('Set the GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH env var to run the system tests'); + } self::$client = new FirestoreClient([ 'keyFilePath' => $keyFilePath ]); diff --git a/Firestore/tests/System/GetAllDocumentsTest.php b/Firestore/tests/System/GetAllDocumentsTest.php index 8a34bbcf49db..9787d7f47645 100644 --- a/Firestore/tests/System/GetAllDocumentsTest.php +++ b/Firestore/tests/System/GetAllDocumentsTest.php @@ -30,9 +30,12 @@ class GetAllDocumentsTest extends FirestoreTestCase private static $refsExist = []; private static $refsNonExist = []; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); $c = self::$client->collection(uniqid(self::COLLECTION_NAME)); self::$localDeletionQueue->add($c); diff --git a/Firestore/tests/System/ValueMapperTest.php b/Firestore/tests/System/ValueMapperTest.php index d9b68201397f..403ed7e5af2c 100644 --- a/Firestore/tests/System/ValueMapperTest.php +++ b/Firestore/tests/System/ValueMapperTest.php @@ -32,9 +32,12 @@ class ValueMapperTest extends FirestoreTestCase const FIELD = 'testedField'; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); if (!self::$isSetup) { self::$document = self::$collection->add([]); @@ -63,7 +66,7 @@ public function testValue($input, callable $expectation = null) public function values() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); return [ [null], diff --git a/Language/tests/System/LanguageTestCase.php b/Language/tests/System/LanguageTestCase.php index 81b345464d9c..82a4639df05c 100644 --- a/Language/tests/System/LanguageTestCase.php +++ b/Language/tests/System/LanguageTestCase.php @@ -29,7 +29,10 @@ class LanguageTestCase extends TestCase protected static $client; private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/Logging/tests/System/LoggingTestCase.php b/Logging/tests/System/LoggingTestCase.php index a809a98d3a79..4167cc5476aa 100644 --- a/Logging/tests/System/LoggingTestCase.php +++ b/Logging/tests/System/LoggingTestCase.php @@ -37,7 +37,7 @@ class LoggingTestCase extends SystemTestCase public function clientProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); return [ [self::$restClient], @@ -45,7 +45,10 @@ public function clientProvider() ]; } - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/Logging/tests/System/ManageSinksTest.php b/Logging/tests/System/ManageSinksTest.php index 4bc31c775035..917796de98aa 100644 --- a/Logging/tests/System/ManageSinksTest.php +++ b/Logging/tests/System/ManageSinksTest.php @@ -76,7 +76,7 @@ public function testCreateSink($client, $destination) public function createSinkProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); $bucket = self::$bucket; $bucket->acl()->add('group-cloud-logs@google.com', 'OWNER'); $bucketDest = sprintf('storage.googleapis.com/%s', $bucket->name()); diff --git a/PubSub/tests/System/ManageIAMPoliciesTest.php b/PubSub/tests/System/ManageIAMPoliciesTest.php index 25c016096f95..04a72e92c3bb 100644 --- a/PubSub/tests/System/ManageIAMPoliciesTest.php +++ b/PubSub/tests/System/ManageIAMPoliciesTest.php @@ -23,9 +23,12 @@ */ class ManageIAMPoliciesTest extends PubSubTestCase { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::skipIfEmulatorUsed('Emulator does not implement IAM functions.'); } diff --git a/PubSub/tests/System/ManageSubscriptionsTest.php b/PubSub/tests/System/ManageSubscriptionsTest.php index 50b129a52c6e..510bba7a19f6 100644 --- a/PubSub/tests/System/ManageSubscriptionsTest.php +++ b/PubSub/tests/System/ManageSubscriptionsTest.php @@ -438,7 +438,7 @@ public function testFiltering($client) 'identifier' => 'baz' ])->build()); - sleep(6); + sleep(10); $messages = $sub->pull(); $this->assertCount(2, $messages); $this->assertTrue(in_array($messages[0]->attribute('identifier'), ['foo', 'bar'])); diff --git a/PubSub/tests/System/ManageTopicsTest.php b/PubSub/tests/System/ManageTopicsTest.php index 2b87235a00e0..26aefc733f69 100644 --- a/PubSub/tests/System/ManageTopicsTest.php +++ b/PubSub/tests/System/ManageTopicsTest.php @@ -80,7 +80,8 @@ public function testUpdateTopic($client) $topic = self::topic($client); $policy = [ - 'allowedPersistenceRegions' => ['us-central1', 'us-east1'] + 'allowedPersistenceRegions' => ['us-central1', 'us-east1'], + 'enforceInTransit' => false, ]; $topic->update([ diff --git a/PubSub/tests/System/PubSubTestCase.php b/PubSub/tests/System/PubSubTestCase.php index a73a4be276c2..6db755dfde63 100644 --- a/PubSub/tests/System/PubSubTestCase.php +++ b/PubSub/tests/System/PubSubTestCase.php @@ -32,7 +32,7 @@ class PubSubTestCase extends SystemTestCase public function clientProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); $result = [ 'grpc' => [self::$grpcClient], @@ -43,7 +43,10 @@ public function clientProvider() return $result; } - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/PubSub/tests/System/SchemaTest.php b/PubSub/tests/System/SchemaTest.php index 33eadefe2de2..f5c5352ea386 100644 --- a/PubSub/tests/System/SchemaTest.php +++ b/PubSub/tests/System/SchemaTest.php @@ -30,7 +30,10 @@ */ class SchemaTest extends PubSubTestCase { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::skipIfEmulatorUsed( "schema tests are not supported when using service emulation" diff --git a/PubSub/tests/System/V1/PublisherSmokeTest.php b/PubSub/tests/System/V1/PublisherSmokeTest.php index cfa4c6105bcf..f80b81660dca 100644 --- a/PubSub/tests/System/V1/PublisherSmokeTest.php +++ b/PubSub/tests/System/V1/PublisherSmokeTest.php @@ -22,7 +22,8 @@ namespace Google\Cloud\PubSub\Tests\System\V1; -use Google\Cloud\PubSub\V1\PublisherClient; +use Google\Cloud\PubSub\V1\Client\PublisherClient; +use Google\Cloud\PubSub\V1\ListTopicsRequest; use Google\ApiCore\Testing\GeneratedTest; /** @@ -43,6 +44,6 @@ public function listTopicsTest() $publisherClient = new PublisherClient(); $formattedProject = $publisherClient->projectName($projectId); - $publisherClient->listTopics($formattedProject); + $publisherClient->listTopics(ListTopicsRequest::build($formattedProject)); } } diff --git a/Redis/tests/System/V1/CloudRedisClientTest.php b/Redis/tests/System/V1/CloudRedisClientTest.php index c9c8edcc3f6e..2065ead61ac3 100644 --- a/Redis/tests/System/V1/CloudRedisClientTest.php +++ b/Redis/tests/System/V1/CloudRedisClientTest.php @@ -18,7 +18,10 @@ namespace Google\Cloud\Redis\Tests\System\V1; use Google\Auth\CredentialsLoader; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\CreateInstanceRequest; +use Google\Cloud\Redis\V1\DeleteInstanceRequest; +use Google\Cloud\Redis\V1\ListInstancesRequest; use Google\Cloud\Redis\V1\Instance; use Google\Cloud\Redis\V1\Instance\Tier; use Google\Cloud\Redis\V1\OperationMetadata; @@ -31,111 +34,83 @@ */ class CloudRedisClientTest extends TestCase { - protected static $grpcClient; - protected static $projectId; - private static $hasSetUp = false; + const LOCATION_ID = 'us-central1'; + const TIER = Tier::BASIC; + const MEMORY_SIZE_GB = 1; - public function clientProvider() - { - self::setUpBeforeClass(); - - return [ - [self::$grpcClient] - ]; - } + private static CloudRedisClient $client; + private static string $parent; + private static string $instanceId; + private static string $instanceName; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures() { - if (self::$hasSetUp) { - return; + if (!$keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH')) { + self::markTestSkipped('Set the GOOGLE_CLOUD_PHP_TESTS_KEY_PATH environment variable'); } - - $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); $keyFileData = json_decode(file_get_contents($keyFilePath), true); + $projectId = $keyFileData['project_id'] ?? ''; - self::$grpcClient = new CloudRedisClient([ + self::$client = new CloudRedisClient([ 'credentials' => $keyFilePath, 'transport' => 'grpc' ]); - self::$projectId = $keyFileData['project_id']; - - self::$hasSetUp = true; + self::$parent = self::$client::locationName($projectId, self::LOCATION_ID); + self::$instanceId = uniqid('redis-test-instance-'); + self::$instanceName = self::$client::instanceName($projectId, self::LOCATION_ID, self::$instanceId); } - private function deleteInstance(CloudRedisClient $client, $instanceToDelete) + public function testCreateOperations() { - $operationResponse = $client->deleteInstance($instanceToDelete); - while (!$operationResponse->isDone()) { - // get the $any object to ensure this does not fail - $any = $operationResponse->getMetadata(); - $this->assertInstanceOf(OperationMetadata::class, $any); - sleep(5); - $operationResponse->reload(); - } - - $this->assertTrue($operationResponse->operationSucceeded()); - // get the $result object to ensure this does not fail - $result = $operationResponse->getResult(); - $this->assertInstanceOf(GPBEmpty::class, $result); + // Create the listance + $instance = (new Instance()) + ->setTier(self::TIER) + ->setMemorySizeGb(self::MEMORY_SIZE_GB); + $createOp = self::$client->createInstance( + CreateInstanceRequest::build(self::$parent, self::$instanceId, $instance) + ); + $createOp->pollUntilComplete(); + + $this->assertTrue($createOp->operationSucceeded()); + $instance = $createOp->getResult(); + $this->assertInstanceOf(Instance::class, $instance); + $this->assertSame(self::$instanceName, $instance->getName()); } /** - * @param CloudRedisClient $client - * @param string $parent - * @param string $instanceId - * @return string Name + * @depends testCreateOperations */ - private function createRedisInstance(CloudRedisClient $client, $parent, $instanceId) + public function testListOperation() { - $tier = Tier::BASIC; - $memorySizeGb = 1; - $instance = new Instance(); - $instance->setTier($tier); - $instance->setMemorySizeGb($memorySizeGb); - $operationResponse = $client->createInstance($parent, $instanceId, $instance); - - while (!$operationResponse->isDone()) { - // get the $any object to ensure this does not fail - $any = $operationResponse->getMetadata(); - $this->assertInstanceOf(OperationMetadata::class, $any); - sleep(5); - $operationResponse->reload(); - } - - $this->assertTrue($operationResponse->operationSucceeded()); - $result = $operationResponse->getResult(); - $this->assertInstanceOf(Instance::class, $result); - return $result->getName(); + // List the instance + $instances = self::$client->listInstances(ListInstancesRequest::build(self::$parent)); + $this->assertSame(1, count(array_map( + fn ($instance) => $instance->getName() === self::$instanceName, + iterator_to_array($instances->iterateAllElements()) + ))); } /** - * @dataProvider clientProvider + * @depends testCreateOperations */ - public function testCreateListDeleteOperations(CloudRedisClient $client) + public function testDeleteOperation() { - $locationId = 'us-central1'; - $instanceId = 'my-redis-test-instance'; - $parent = $client::locationName(self::$projectId, $locationId); - $instanceName = $client::instanceName(self::$projectId, $locationId, $instanceId); - - $instances = $client->listInstances($parent); - foreach ($instances->iterateAllElements() as $instance) { - if ($instance->getName() === $instanceName) { - // Instance exists - lets delete it - $this->deleteInstance($client, $instance->getName()); - } - } - - $createdInstanceName = $this->createRedisInstance($client, $parent, $instanceId); - $this->assertSame($instanceName, $createdInstanceName); - - $instances = iterator_to_array($client->listInstances($parent)->iterateAllElements()); - $this->assertSame(1, count($instances)); - - $this->deleteInstance($client, $createdInstanceName); - - $instances = iterator_to_array($client->listInstances($parent)->iterateAllElements()); - $this->assertSame(0, count($instances)); + // Delete Operation + $deleteOp = self::$client->deleteInstance( + DeleteInstanceRequest::build(self::$instanceName) + ); + $deleteOp->pollUntilComplete(); + $this->assertTrue($deleteOp->operationSucceeded()); + + // Ensure delete op succeeded + $instances = self::$client->listInstances(ListInstancesRequest::build(self::$parent)); + $this->assertSame(0, count(array_map( + fn ($instance) => $instance->getName() === $instanceName, + iterator_to_array($instances->iterateAllElements()) + ))); } } diff --git a/Spanner/tests/System/BackupTest.php b/Spanner/tests/System/BackupTest.php index 663c59b8e523..5d8633c6e7e0 100644 --- a/Spanner/tests/System/BackupTest.php +++ b/Spanner/tests/System/BackupTest.php @@ -51,11 +51,14 @@ class BackupTest extends SpannerTestCase private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::skipEmulatorTests(); - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); if (self::$hasSetUp) { return; } diff --git a/Spanner/tests/System/BatchTest.php b/Spanner/tests/System/BatchTest.php index eda1799531f9..2d90a07e6c08 100644 --- a/Spanner/tests/System/BatchTest.php +++ b/Spanner/tests/System/BatchTest.php @@ -35,12 +35,15 @@ class BatchTest extends SpannerTestCase private static $tableName; private static $isSetup = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$isSetup) { return; } - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$tableName = uniqid(self::TESTING_PREFIX); diff --git a/Spanner/tests/System/BatchWriteTest.php b/Spanner/tests/System/BatchWriteTest.php index 764fee3f8e19..cbcf38031985 100644 --- a/Spanner/tests/System/BatchWriteTest.php +++ b/Spanner/tests/System/BatchWriteTest.php @@ -25,10 +25,13 @@ class BatchWriteTest extends SpannerTestCase { const TABLE_NAME = 'BatchWrites'; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::skipEmulatorTests(); - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$database->updateDdlBatch([ 'CREATE TABLE Singers ( diff --git a/Spanner/tests/System/DatabaseRoleTrait.php b/Spanner/tests/System/DatabaseRoleTrait.php index 2b668a28f733..c4c0323fb0b1 100644 --- a/Spanner/tests/System/DatabaseRoleTrait.php +++ b/Spanner/tests/System/DatabaseRoleTrait.php @@ -31,7 +31,7 @@ abstract public static function setUpBeforeClass(); public function dbProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); return [ [self::$restrictiveDbRole, 'PERMISSION_DENIED'], [self::$dbRole, null] @@ -40,7 +40,7 @@ public function dbProvider() public function insertDbProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); return [ [ self::getDbWithRestrictiveRole(), @@ -64,7 +64,7 @@ public function insertDbProvider() public function readDbProvider() { - self::setUpBeforeClass(); + self::setUpTestFixtures(); return [ [self::getDbWithReaderRole(), null], [self::getDbWithRestrictiveRole(), 'PERMISSION_DENIED'] diff --git a/Spanner/tests/System/GeneratedAdminEmulatorTest.php b/Spanner/tests/System/GeneratedAdminEmulatorTest.php index 8ede972cba86..b31d5f409ac0 100644 --- a/Spanner/tests/System/GeneratedAdminEmulatorTest.php +++ b/Spanner/tests/System/GeneratedAdminEmulatorTest.php @@ -32,7 +32,10 @@ class GeneratedAdminEmulatorTest extends SpannerTestCase { private static $projectId; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::$projectId = 'emulator-project'; } diff --git a/Spanner/tests/System/LargeReadTest.php b/Spanner/tests/System/LargeReadTest.php index ff82698fdd87..e491aca6e8f4 100644 --- a/Spanner/tests/System/LargeReadTest.php +++ b/Spanner/tests/System/LargeReadTest.php @@ -38,9 +38,12 @@ class LargeReadTest extends SpannerTestCase private static $str = ''; const NUM = 40000; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$tableName = uniqid(self::TESTING_PREFIX); diff --git a/Spanner/tests/System/OperationsTest.php b/Spanner/tests/System/OperationsTest.php index c7c3ad30ca65..50e88cb6fb80 100644 --- a/Spanner/tests/System/OperationsTest.php +++ b/Spanner/tests/System/OperationsTest.php @@ -34,7 +34,10 @@ class OperationsTest extends SpannerTestCase private static $name2; private static $isSetup = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$isSetup) { return; @@ -44,7 +47,7 @@ public static function setUpBeforeClass(): void self::$name1 = uniqid(self::TESTING_PREFIX); self::$name2 = uniqid(self::TESTING_PREFIX); - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$database->insert(self::TEST_TABLE_NAME, [ 'id' => self::$id1, diff --git a/Spanner/tests/System/PgBatchTest.php b/Spanner/tests/System/PgBatchTest.php index 803e67a533a7..131ba743a084 100644 --- a/Spanner/tests/System/PgBatchTest.php +++ b/Spanner/tests/System/PgBatchTest.php @@ -34,12 +34,15 @@ class PgBatchTest extends SpannerPgTestCase private static $tableName; private static $isSetup = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$isSetup) { return; } - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$tableName = uniqid(self::TESTING_PREFIX); diff --git a/Spanner/tests/System/PgBatchWriteTest.php b/Spanner/tests/System/PgBatchWriteTest.php index 66e0e859c639..d7563bbe5ccf 100644 --- a/Spanner/tests/System/PgBatchWriteTest.php +++ b/Spanner/tests/System/PgBatchWriteTest.php @@ -26,10 +26,13 @@ class PgBatchWriteTest extends SpannerPgTestCase { const TABLE_NAME = 'BatchWrites'; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::skipEmulatorTests(); - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$database->updateDdlBatch([ 'CREATE TABLE Singers ( diff --git a/Spanner/tests/System/PgOperationsTest.php b/Spanner/tests/System/PgOperationsTest.php index 1a2b86e7c3ba..53238803c875 100644 --- a/Spanner/tests/System/PgOperationsTest.php +++ b/Spanner/tests/System/PgOperationsTest.php @@ -34,12 +34,15 @@ class PgOperationsTest extends SpannerPgTestCase private static $id; private static $isSetup = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$isSetup) { return; } - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$id = rand(1000, 9999); self::$row = [ diff --git a/Spanner/tests/System/PgQueryTest.php b/Spanner/tests/System/PgQueryTest.php index dd374e517544..b45766cfa491 100644 --- a/Spanner/tests/System/PgQueryTest.php +++ b/Spanner/tests/System/PgQueryTest.php @@ -40,9 +40,12 @@ class PgQueryTest extends SpannerPgTestCase public static $timestampVal; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$database->updateDdl( 'CREATE TABLE ' . self::TABLE_NAME . ' ( diff --git a/Spanner/tests/System/PgReadTest.php b/Spanner/tests/System/PgReadTest.php index a3574a8c46e2..30ce4c48dd14 100644 --- a/Spanner/tests/System/PgReadTest.php +++ b/Spanner/tests/System/PgReadTest.php @@ -34,9 +34,12 @@ class PgReadTest extends SpannerPgTestCase private static $indexes = []; private static $dataset; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$readTableName = "read_table"; self::$rangeTableName = "range_table"; diff --git a/Spanner/tests/System/PgTransactionTest.php b/Spanner/tests/System/PgTransactionTest.php index 39d9bf8eb560..f6f807c33173 100644 --- a/Spanner/tests/System/PgTransactionTest.php +++ b/Spanner/tests/System/PgTransactionTest.php @@ -38,12 +38,15 @@ class PgTransactionTest extends SpannerPgTestCase private static $id1; private static $isSetup = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$isSetup) { return; } - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$tableName = "transactions_test"; diff --git a/Spanner/tests/System/PgWriteTest.php b/Spanner/tests/System/PgWriteTest.php index c4aed6da28f1..037efa24ead8 100644 --- a/Spanner/tests/System/PgWriteTest.php +++ b/Spanner/tests/System/PgWriteTest.php @@ -42,9 +42,12 @@ class PgWriteTest extends SpannerPgTestCase const TABLE_NAME = 'Writes'; const COMMIT_TIMESTAMP_TABLE_NAME = 'CommitTimestamps'; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$database->updateDdlBatch([ 'CREATE TABLE ' . self::TABLE_NAME . ' ( diff --git a/Spanner/tests/System/ReadTest.php b/Spanner/tests/System/ReadTest.php index 7ab189e2a7f0..a6ebcc47a554 100644 --- a/Spanner/tests/System/ReadTest.php +++ b/Spanner/tests/System/ReadTest.php @@ -33,9 +33,12 @@ class ReadTest extends SpannerTestCase private static $indexes = []; private static $dataset; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$readTableName = uniqid(self::TESTING_PREFIX); self::$rangeTableName = uniqid(self::TESTING_PREFIX); diff --git a/Spanner/tests/System/SnapshotTest.php b/Spanner/tests/System/SnapshotTest.php index 98c4e9381db1..e41dc3c3cb8d 100644 --- a/Spanner/tests/System/SnapshotTest.php +++ b/Spanner/tests/System/SnapshotTest.php @@ -30,9 +30,12 @@ class SnapshotTest extends SpannerTestCase private static $tableName; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$tableName = uniqid(self::TABLE_NAME); diff --git a/Spanner/tests/System/SpannerPgTestCase.php b/Spanner/tests/System/SpannerPgTestCase.php index 0de06236396b..5787afd0a69a 100644 --- a/Spanner/tests/System/SpannerPgTestCase.php +++ b/Spanner/tests/System/SpannerPgTestCase.php @@ -28,7 +28,7 @@ * @group spanner * @group spanner-postgres */ -class SpannerPgTestCase extends SystemTestCase +abstract class SpannerPgTestCase extends SystemTestCase { const TESTING_PREFIX = 'gcloud_testing_'; const INSTANCE_NAME = 'google-cloud-php-system-tests'; @@ -47,7 +47,10 @@ class SpannerPgTestCase extends SystemTestCase private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/Spanner/tests/System/SpannerTestCase.php b/Spanner/tests/System/SpannerTestCase.php index c1c2cb8e4171..d74467a5237f 100644 --- a/Spanner/tests/System/SpannerTestCase.php +++ b/Spanner/tests/System/SpannerTestCase.php @@ -27,7 +27,7 @@ /** * @group spanner */ -class SpannerTestCase extends SystemTestCase +abstract class SpannerTestCase extends SystemTestCase { const TESTING_PREFIX = 'gcloud_testing_'; const INSTANCE_NAME = 'google-cloud-php-system-tests'; @@ -46,7 +46,10 @@ class SpannerTestCase extends SystemTestCase private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/Spanner/tests/System/TransactionTest.php b/Spanner/tests/System/TransactionTest.php index d3ec2e08cfb7..99b9931cb025 100644 --- a/Spanner/tests/System/TransactionTest.php +++ b/Spanner/tests/System/TransactionTest.php @@ -39,12 +39,15 @@ class TransactionTest extends SpannerTestCase private static $id1; private static $isSetup = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$isSetup) { return; } - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$tableName = uniqid(self::TABLE_NAME); self::$id1 = rand(1000, 9999); diff --git a/Spanner/tests/System/WriteTest.php b/Spanner/tests/System/WriteTest.php index 07b17dad44c6..e6724b7111f6 100644 --- a/Spanner/tests/System/WriteTest.php +++ b/Spanner/tests/System/WriteTest.php @@ -40,10 +40,13 @@ class WriteTest extends SpannerTestCase const TABLE_NAME = 'Writes'; const COMMIT_TIMESTAMP_TABLE_NAME = 'CommitTimestamps'; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { self::skipEmulatorTests(); - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$database->updateDdlBatch([ 'CREATE TABLE ' . self::TABLE_NAME . ' ( diff --git a/Storage/tests/System/HmacKeyTest.php b/Storage/tests/System/HmacKeyTest.php index c262f9a8fa21..916562befefd 100644 --- a/Storage/tests/System/HmacKeyTest.php +++ b/Storage/tests/System/HmacKeyTest.php @@ -28,9 +28,12 @@ class HmacKeyTest extends StorageTestCase { private static $serviceAccountEmail; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$serviceAccountEmail = json_decode( file_get_contents(getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH')), diff --git a/Storage/tests/System/KmsTest.php b/Storage/tests/System/KmsTest.php index 27e5b6b3a8ee..8ce0bd9a70a6 100644 --- a/Storage/tests/System/KmsTest.php +++ b/Storage/tests/System/KmsTest.php @@ -34,9 +34,12 @@ class KmsTest extends StorageTestCase private static $keyName1; private static $keyName2; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); $encryption = new KeyManager( diff --git a/Storage/tests/System/ManageAclTest.php b/Storage/tests/System/ManageAclTest.php index 0531b5bd66ae..b3fedf4f9c7d 100644 --- a/Storage/tests/System/ManageAclTest.php +++ b/Storage/tests/System/ManageAclTest.php @@ -32,6 +32,12 @@ public function testManageBucketAcl() $this->assertAcl(self::$bucket->acl(), $kind); } + /** + * This test is marked flakey because it often throws a RateLimitExceeded + * error + * + * @group flakey + */ public function testManageDefaultObjectAcl() { $kind = 'storage#objectAccessControl'; diff --git a/Storage/tests/System/RequesterPaysTest.php b/Storage/tests/System/RequesterPaysTest.php index 151537744390..5de65f1289ca 100644 --- a/Storage/tests/System/RequesterPaysTest.php +++ b/Storage/tests/System/RequesterPaysTest.php @@ -48,11 +48,17 @@ class RequesterPaysTest extends StorageTestCase private static $topic; private static $notificationId; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); $requesterKeyFilePath = getenv('GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH'); + if (!$requesterKeyFilePath) { + self::markTestSkipped('Set GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH to run this test'); + } $ownerKeyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); self::$requesterKeyFile = json_decode(file_get_contents($requesterKeyFilePath), true); self::$requesterEmail = self::$requesterKeyFile['client_email']; diff --git a/Storage/tests/System/SignedUrlTest.php b/Storage/tests/System/SignedUrlTest.php index 48531faab26e..a44d9fffef4f 100644 --- a/Storage/tests/System/SignedUrlTest.php +++ b/Storage/tests/System/SignedUrlTest.php @@ -18,6 +18,7 @@ namespace Google\Cloud\Storage\Tests\System; use Google\Cloud\Core\Exception\NotFoundException; +use Google\Cloud\Core\ExponentialBackoff; use Google\Cloud\Core\Timestamp; use GuzzleHttp\Client; @@ -78,7 +79,7 @@ public function signedUrls() public function testSignedUrlV2($objectName, array $urlOpts = []) { $urlOpts += [ - 'version' => 'v2' + 'force_ip_resolve' => 'v2' ]; $obj = $this->createFile($objectName); @@ -95,7 +96,7 @@ public function testSignedUrlV2($objectName, array $urlOpts = []) public function testSignedUrlV4($objectName, array $urlOpts = []) { $urlOpts += [ - 'version' => 'v4' + 'force_ip_resolve' => 'v4' ]; $obj = $this->createFile($objectName); @@ -118,7 +119,7 @@ public function testSignedUrlDelete($version) $url = $obj->signedUrl($ts, [ 'method' => 'DELETE', 'contentType' => 'text/plain', - 'version' => $version + 'force_ip_resolve' => $version ]); try { @@ -142,7 +143,7 @@ public function testSignedUploadSession($version) { $obj = self::$bucket->object(uniqid(self::TESTING_PREFIX) .'.txt'); $url = $obj->beginSignedUploadSession([ - 'version' => $version + 'force_ip_resolve' => $version ]); $this->guzzle->request('PUT', $url, [ @@ -166,7 +167,7 @@ public function testSignedUploadSessionOrigin($version) $url = $obj->beginSignedUploadSession([ 'origin' => 'https://google.com', - 'version' => $version, + 'force_ip_resolve' => $version, 'headers' => [ 'x-goog-test' => 'hi' ] @@ -181,7 +182,7 @@ public function testSignedUploadSessionOrigin($version) $this->guzzle->request('PUT', $url, [ 'body' => self::CONTENT, - 'version' => $version, + 'force_ip_resolve' => $version, 'headers' => [ 'x-goog-test' => 'hi' ] @@ -205,7 +206,7 @@ public function testSignedUrlContentType($version) $url = $obj->signedUrl(time() + 2, [ 'responseDisposition' => $disposition, 'responseType' => $contentType, - 'version' => $version + 'force_ip_resolve' => $version ]); $res = $this->guzzle->request('GET', $url); @@ -225,7 +226,7 @@ public function testSignedUrlWithSaveAsName($version) $saveAs = 'foo bar'; $url = $obj->signedUrl(time() + 2, [ 'saveAsName' => $saveAs, - 'version' => $version + 'force_ip_resolve' => $version ]); $res = $this->guzzle->request('GET', $url); @@ -240,7 +241,7 @@ public function testSignedUrlWithSaveAsName($version) public function testBucketUrlSigning($version) { $url = self::$bucket->signedUrl(time() + 2, [ - 'version' => $version + 'force_ip_resolve' => $version ]); $res = $this->guzzle->request('GET', $url); @@ -269,11 +270,14 @@ private function createFile($name) private function getFile($url, array $options = []) { - $res = $this->guzzle->request('GET', $url, $options + [ - 'http_errors' => false - ]); - - return (string) $res->getBody(); + $exponentialBackoff = new ExponentialBackoff(); + return $exponentialBackoff->execute(function () use ($url, $options) { + $res = $this->guzzle->request('GET', $url, $options + [ + 'http_errors' => false, + ]); + + return (string) $res->getBody(); + }); } private function deleteFile($url, array $headers = []) diff --git a/Storage/tests/System/StorageTestCase.php b/Storage/tests/System/StorageTestCase.php index fcca3297cdda..dd3b69db48f7 100644 --- a/Storage/tests/System/StorageTestCase.php +++ b/Storage/tests/System/StorageTestCase.php @@ -38,14 +38,12 @@ class StorageTestCase extends SystemTestCase protected static $pubsubClient; protected static $object; protected static $mainBucketName; - private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - if (self::$hasSetUp) { - return; - } - $config = [ 'keyFilePath' => getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'), 'transport' => 'rest' @@ -64,8 +62,17 @@ public static function setUpBeforeClass(): void ['location' => 'us-west1'] ); self::$object = self::$bucket->upload('somedata', ['name' => uniqid(self::TESTING_PREFIX)]); + } - self::$hasSetUp = true; + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void + { + foreach (self::$bucket->objects() as $object) { + $object->delete(); + } + self::$bucket->delete(); } protected static function getProjectId($keyFilePath) diff --git a/Storage/tests/System/StreamWrapper/AppendTest.php b/Storage/tests/System/StreamWrapper/AppendTest.php index ae3ed5bef3c7..1220b225d7c1 100644 --- a/Storage/tests/System/StreamWrapper/AppendTest.php +++ b/Storage/tests/System/StreamWrapper/AppendTest.php @@ -36,7 +36,10 @@ public function setUp(): void $this->tailFileUrl = $this->fileUrl . StreamWrapper::TAIL_NAME_SUFFIX; } - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { $url = static::generateUrl(self::$fileName); unlink($url); diff --git a/Storage/tests/System/StreamWrapper/DirectoryTest.php b/Storage/tests/System/StreamWrapper/DirectoryTest.php index b59afdfbd49a..d3b88e3423ef 100644 --- a/Storage/tests/System/StreamWrapper/DirectoryTest.php +++ b/Storage/tests/System/StreamWrapper/DirectoryTest.php @@ -36,9 +36,12 @@ class DirectoryTest extends StreamWrapperTestCase 'bar/', ]; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); // create file in folder foreach (self::$createObjects as $name) { @@ -46,13 +49,16 @@ public static function setUpBeforeClass(): void } } - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { foreach (self::$createObjects as $name) { self::$bucket->object($name)->delete(); } - parent::tearDownAfterClass(); + parent::tearDownTestFixtures(); } public function testMkDir() diff --git a/Storage/tests/System/StreamWrapper/ImageTest.php b/Storage/tests/System/StreamWrapper/ImageTest.php index d5b382c5df32..dc639d5636d7 100644 --- a/Storage/tests/System/StreamWrapper/ImageTest.php +++ b/Storage/tests/System/StreamWrapper/ImageTest.php @@ -27,9 +27,12 @@ class ImageTest extends StreamWrapperTestCase const TEST_IMAGE_WITH_EXIF = __DIR__ . '/../data/fujifilm-dx10.jpg'; const TEST_IMAGE = __DIR__ . '/../data/screenshot.png'; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$bucket->upload( fopen(self::TEST_IMAGE_WITH_EXIF, 'r'), diff --git a/Storage/tests/System/StreamWrapper/RenameTest.php b/Storage/tests/System/StreamWrapper/RenameTest.php index dae6af51be60..2726aa1c445c 100644 --- a/Storage/tests/System/StreamWrapper/RenameTest.php +++ b/Storage/tests/System/StreamWrapper/RenameTest.php @@ -27,9 +27,12 @@ class RenameTest extends StreamWrapperTestCase const TEST_FILE = 'some_folder/foo.txt'; const NEW_TEST_FILE = 'some_folder/bar.txt'; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); // create file in folder self::$bucket->upload('somedata', ['name' => self::TEST_FILE]); diff --git a/Storage/tests/System/StreamWrapper/StreamWrapperTestCase.php b/Storage/tests/System/StreamWrapper/StreamWrapperTestCase.php index aa5c8d4d6166..cd15693a601f 100644 --- a/Storage/tests/System/StreamWrapper/StreamWrapperTestCase.php +++ b/Storage/tests/System/StreamWrapper/StreamWrapperTestCase.php @@ -26,16 +26,20 @@ */ class StreamWrapperTestCase extends StorageTestCase { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$client->registerStreamWrapper(); } - - public static function tearDownAfterClass(): void + /** + * @afterClass + */ + public static function tearDownTestFixtures(): void { self::$client->unregisterStreamWrapper(); - parent::tearDownAfterClass(); } protected static function generateUrl($file, Bucket $bucket = null) diff --git a/Storage/tests/System/StreamWrapper/UrlStatTest.php b/Storage/tests/System/StreamWrapper/UrlStatTest.php index f72969a5d291..2169d5d8cd47 100644 --- a/Storage/tests/System/StreamWrapper/UrlStatTest.php +++ b/Storage/tests/System/StreamWrapper/UrlStatTest.php @@ -27,9 +27,12 @@ class UrlStatTest extends StreamWrapperTestCase protected static $fileUrl; protected static $dirUrl; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { - parent::setUpBeforeClass(); + parent::setUpTestFixtures(); self::$fileUrl = self::generateUrl(self::$object->name()); self::$dirUrl = self::generateUrl('some_folder/'); mkdir(self::$dirUrl); @@ -58,7 +61,7 @@ public function testStatOnOpenFileForRead() { $fd = fopen(self::$fileUrl, 'r'); $stat = fstat($fd); - $this->assertEquals(33206, $stat['mode']); + $this->assertEquals(33060, $stat['mode']); } public function testIsWritable() diff --git a/Tasks/tests/System/V2/TasksServiceSmokeTest.php b/Tasks/tests/System/V2/TasksServiceSmokeTest.php index 41f0a408f5a0..7c020683311c 100644 --- a/Tasks/tests/System/V2/TasksServiceSmokeTest.php +++ b/Tasks/tests/System/V2/TasksServiceSmokeTest.php @@ -18,7 +18,10 @@ use Google\Cloud\Core\ExponentialBackoff; use Google\Cloud\Core\Testing\System\SystemTestCase; -use Google\Cloud\Tasks\V2\CloudTasksClient; +use Google\Cloud\Tasks\V2\Client\CloudTasksClient; +use Google\Cloud\Tasks\V2\CreateQueueRequest; +use Google\Cloud\Tasks\V2\DeleteQueueRequest; +use Google\Cloud\Tasks\V2\ListQueuesRequest; use Google\Cloud\Tasks\V2\Queue; use Google\Cloud\Tasks\V2\Task; @@ -32,10 +35,10 @@ private function createQueue($client, $locationName, $queue) { $backoff = new ExponentialBackoff(8); $backoff->execute(function () use ($client, $locationName, $queue) { - $client->createQueue($locationName, $queue); + $client->createQueue(CreateQueueRequest::build($locationName, $queue)); }); self::$deletionQueue->add(function () use ($client, $queue) { - $client->deleteQueue($queue->getName()); + $client->deleteQueue(DeleteQueueRequest::build($queue->getName())); }); } @@ -58,7 +61,7 @@ public function smokeTest() ]); $this->createQueue($client, $locationName, $queue); - $resp = $client->listQueues($locationName); + $resp = $client->listQueues(ListQueuesRequest::build($locationName)); $found = false; foreach ($resp->iterateAllElements() as $q) { if ($queueName === $q->getName()) { diff --git a/Tasks/tests/System/V2beta2/TasksServiceSmokeTest.php b/Tasks/tests/System/V2beta2/TasksServiceSmokeTest.php deleted file mode 100644 index 753a26154205..000000000000 --- a/Tasks/tests/System/V2beta2/TasksServiceSmokeTest.php +++ /dev/null @@ -1,90 +0,0 @@ -execute(function () use ($client, $locationName, $queue) { - $client->createQueue($locationName, $queue); - }); - self::$deletionQueue->add(function () use ($client, $queue) { - $client->deleteQueue($queue->getName()); - }); - sleep(120); - } - - /** - * @test - */ - public function smokeTest() - { - $projectId = getenv('PROJECT_ID'); - if ($projectId === false) { - $this->fail('Environment variable PROJECT_ID must be set for smoke test'); - } - $client = new CloudTasksClient(); - $location = 'us-central1'; - $queue = uniqid(); - $queueName = $client::queueName($projectId, $location, $queue); - $locationName = $client::locationName($projectId, $location); - $queue = new Queue(); - $queue->setName($queueName); - $queue->setPullTarget(new PullTarget()); - $this->createQueue($client, $locationName, $queue); - $pullMessage = new PullMessage(); - $payload = 'a message for the consumer: ' . uniqid(); - $pullMessage->setPayload($payload); - $task = new Task(); - $task->setPullMessage($pullMessage); - $client->createTask($queueName, $task); - - $leaseDuration = new Duration(); - $leaseDuration->setSeconds(600); - $resp = $client->leaseTasks( - $queueName, - $leaseDuration, - [ - 'maxTasks' => 1, - 'responseView' => Task_View::FULL - ] - ); - $task = $resp->getTasks()[0]; - $this->assertEquals($payload, $task->getPullMessage()->getPayload()); - - // Acknowledge the task - $client->acknowledgeTask($task->getName(), $task->getScheduleTime()); - } -} diff --git a/Tasks/tests/System/V2beta3/TasksServiceSmokeTest.php b/Tasks/tests/System/V2beta3/TasksServiceSmokeTest.php deleted file mode 100644 index bf969b4a3211..000000000000 --- a/Tasks/tests/System/V2beta3/TasksServiceSmokeTest.php +++ /dev/null @@ -1,72 +0,0 @@ -execute(function () use ($client, $locationName, $queue) { - $client->createQueue($locationName, $queue); - }); - self::$deletionQueue->add(function () use ($client, $queue) { - $client->deleteQueue($queue->getName()); - }); - } - - /** - * @test - */ - public function smokeTest() - { - $projectId = getenv('PROJECT_ID'); - if ($projectId === false) { - $this->fail('Environment variable PROJECT_ID must be set for smoke test'); - } - $client = new CloudTasksClient(); - $location = 'us-central1'; - $queue = uniqid(); - $queueName = $client::queueName($projectId, $location, $queue); - $locationName = $client::locationName($projectId, $location); - $queue = new Queue([ - 'name' => $queueName, - 'app_engine_http_queue' => new AppEngineHttpQueue() - ]); - $this->createQueue($client, $locationName, $queue); - - $resp = $client->listQueues($locationName); - $found = false; - foreach ($resp->iterateAllElements() as $q) { - if ($queueName === $q->getName()) { - $found = true; - } - } - $this->assertTrue($found, "Queue $queueName should be found in the listQueues respons"); - } -} diff --git a/Translate/tests/System/V2/TranslateTestCase.php b/Translate/tests/System/V2/TranslateTestCase.php index 446d656f942d..5425c639c9eb 100644 --- a/Translate/tests/System/V2/TranslateTestCase.php +++ b/Translate/tests/System/V2/TranslateTestCase.php @@ -25,7 +25,10 @@ class TranslateTestCase extends TestCase protected static $hasSetUp = false; protected static $client; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/Vision/tests/System/AnnotationsTest.php b/Vision/tests/System/AnnotationsTest.php index f1bdae905487..7fdd914bc78b 100644 --- a/Vision/tests/System/AnnotationsTest.php +++ b/Vision/tests/System/AnnotationsTest.php @@ -88,12 +88,15 @@ public function testAnnotate() $desc = array_filter($res->web()->entities(), function ($e) { return isset($e->info()['description']) - && strpos($e->description(), 'Rushmore') !== false; + && strpos($e->description(), 'Monument') !== false; }); $this->assertGreaterThan(0, count($desc)); - $this->assertInstanceOf(WebImage::class, $res->web()->matchingImages()[0]); - $this->assertInstanceOf(WebImage::class, $res->web()->partialMatchingImages()[0]); + // flakey tests + if (isset($res->web()->matchingImages()[0])) { + $this->assertInstanceOf(WebImage::class, $res->web()->matchingImages()[0]); + $this->assertInstanceOf(WebImage::class, $res->web()->partialMatchingImages()[0]); + } $this->assertInstanceOf(WebPage::class, $res->web()->pages()[0]); } diff --git a/Vision/tests/System/VisionTestCase.php b/Vision/tests/System/VisionTestCase.php index 48a18433ce35..9cd47e1b7711 100644 --- a/Vision/tests/System/VisionTestCase.php +++ b/Vision/tests/System/VisionTestCase.php @@ -28,7 +28,10 @@ class VisionTestCase extends TestCase protected static $vision; private static $hasSetUp = false; - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + public static function setUpTestFixtures(): void { if (self::$hasSetUp) { return; diff --git a/phpunit-system.xml.dist b/phpunit-system.xml.dist index 2297e85ede70..8d364641227a 100644 --- a/phpunit-system.xml.dist +++ b/phpunit-system.xml.dist @@ -1,21 +1,18 @@ - - - */src - src - - - */src/V[!a-zA-Z]* - */src/*/V[!a-zA-Z]* - */src/*/*/V[!a-zA-Z]* - Core/src/Testing - dev - - */tests/System + + Datastore/tests/System + Firestore/tests/System + Logging/tests/System + Spanner/tests/System + + Debugger/tests/System + + +