From 94d82807fe202f5d327ddeede4e513319c7a0de4 Mon Sep 17 00:00:00 2001 From: Vishwaraj Anand Date: Thu, 28 Sep 2023 19:58:45 +0530 Subject: [PATCH] chore: fixing static analysis tests (#1921) --- .github/workflows/lint.yml | 2 +- analyticsdata/src/get_common_metadata.php | 2 +- asset/test/assetSearchTest.php | 30 ++++++++++++------- .../src/list_instance_config_operations.php | 2 +- spanner/src/list_instance_configs.php | 8 +++-- storage/src/generate_encryption_key.php | 2 +- storage/src/list_buckets.php | 2 +- testing/composer.json | 2 +- testing/run_staticanalysis_check.sh | 2 +- 9 files changed, 32 insertions(+), 20 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c52130716b..c4ddad101f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: staticanalysis: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} fetch-depth: 5 diff --git a/analyticsdata/src/get_common_metadata.php b/analyticsdata/src/get_common_metadata.php index 5a8d9a1141..aadbabc171 100644 --- a/analyticsdata/src/get_common_metadata.php +++ b/analyticsdata/src/get_common_metadata.php @@ -36,7 +36,7 @@ /** * Retrieves dimensions and metrics available for all Google Analytics 4 properties. */ -function get_common_metadata() +function get_common_metadata(): void { // Create an instance of the Google Analytics Data API client library. $client = new BetaAnalyticsDataClient(); diff --git a/asset/test/assetSearchTest.php b/asset/test/assetSearchTest.php index c5db6e0ad0..7d05c01cce 100644 --- a/asset/test/assetSearchTest.php +++ b/asset/test/assetSearchTest.php @@ -18,6 +18,7 @@ namespace Google\Cloud\Samples\Asset; use Google\Cloud\BigQuery\BigQueryClient; +use Google\Cloud\TestUtils\EventuallyConsistentTestTrait; use Google\Cloud\TestUtils\TestTrait; use PHPUnit\Framework\TestCase; use PHPUnitRetry\RetryTrait; @@ -30,6 +31,7 @@ */ class assetSearchTest extends TestCase { + use EventuallyConsistentTestTrait; use RetryTrait; use TestTrait; @@ -55,12 +57,16 @@ public function testSearchAllResources() $scope = 'projects/' . self::$projectId; $query = 'name:' . self::$datasetId; - $output = $this->runFunctionSnippet('search_all_resources', [ - $scope, - $query - ]); + $this->runEventuallyConsistentTest( + function () use ($scope, $query) { + $output = $this->runFunctionSnippet('search_all_resources', [ + $scope, + $query + ]); - $this->assertStringContainsString(self::$datasetId, $output); + $this->assertStringContainsString(self::$datasetId, $output); + } + ); } public function testSearchAllIamPolicies() @@ -68,10 +74,14 @@ public function testSearchAllIamPolicies() $scope = 'projects/' . self::$projectId; $query = 'policy:roles/owner'; - $output = $this->runFunctionSnippet('search_all_iam_policies', [ - $scope, - $query - ]); - $this->assertStringContainsString(self::$projectId, $output); + $this->runEventuallyConsistentTest( + function () use ($scope, $query) { + $output = $this->runFunctionSnippet('search_all_iam_policies', [ + $scope, + $query + ]); + $this->assertStringContainsString(self::$projectId, $output); + } + ); } } diff --git a/spanner/src/list_instance_config_operations.php b/spanner/src/list_instance_config_operations.php index 732566f3ee..731516c63d 100644 --- a/spanner/src/list_instance_config_operations.php +++ b/spanner/src/list_instance_config_operations.php @@ -33,7 +33,7 @@ * list_instance_config_operations(); * ``` */ -function list_instance_config_operations() +function list_instance_config_operations(): void { $spanner = new SpannerClient(); diff --git a/spanner/src/list_instance_configs.php b/spanner/src/list_instance_configs.php index fba528baf3..e902daeec5 100644 --- a/spanner/src/list_instance_configs.php +++ b/spanner/src/list_instance_configs.php @@ -33,12 +33,14 @@ * list_instance_configs(); * ``` */ -function list_instance_configs() +function list_instance_configs(): void { $spanner = new SpannerClient(); foreach ($spanner->instanceConfigurations() as $config) { - printf('Available leader options for instance config %s: %s' . PHP_EOL, - $config->info()['displayName'], $config->info()['leaderOptions'] + printf( + 'Available leader options for instance config %s: %s' . PHP_EOL, + $config->info()['displayName'], + $config->info()['leaderOptions'] ); } } diff --git a/storage/src/generate_encryption_key.php b/storage/src/generate_encryption_key.php index 78f2ac5f5e..7463d39c1f 100644 --- a/storage/src/generate_encryption_key.php +++ b/storage/src/generate_encryption_key.php @@ -28,7 +28,7 @@ /** * Generate a base64 encoded encryption key for Google Cloud Storage. */ -function generate_encryption_key() +function generate_encryption_key(): void { $key = random_bytes(32); $encodedKey = base64_encode($key); diff --git a/storage/src/list_buckets.php b/storage/src/list_buckets.php index 2bb1946f37..38ccbc0877 100644 --- a/storage/src/list_buckets.php +++ b/storage/src/list_buckets.php @@ -29,7 +29,7 @@ /** * List all Cloud Storage buckets for the current project. */ -function list_buckets() +function list_buckets(): void { $storage = new StorageClient(); foreach ($storage->buckets() as $bucket) { diff --git a/testing/composer.json b/testing/composer.json index 81a8b63446..a39308fd69 100755 --- a/testing/composer.json +++ b/testing/composer.json @@ -10,7 +10,7 @@ "phpunit/phpunit": "^9.0", "friendsofphp/php-cs-fixer": "^3,<3.9", "composer/semver": "^3.2", - "phpstan/phpstan": "^1.9", + "phpstan/phpstan": "^1.10", "phpspec/prophecy-phpunit": "^2.0" } } diff --git a/testing/run_staticanalysis_check.sh b/testing/run_staticanalysis_check.sh index 114dea9ff1..0dd8bf187e 100644 --- a/testing/run_staticanalysis_check.sh +++ b/testing/run_staticanalysis_check.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2022 Google Inc. +# Copyright 2023 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.