Skip to content

Commit

Permalink
chore: add action to run individual package tests (#5325)
Browse files Browse the repository at this point in the history
* feat(tests): add test for running package deps and tests individually

* remove unneceessary autoload-dev entries
  • Loading branch information
bshaffer authored and vishwarajanand committed Nov 8, 2022
1 parent f0a2895 commit a27ff50
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 97 deletions.
42 changes: 42 additions & 0 deletions .github/run-package-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# Copyright 2022 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FAILED_FILE=$(mktemp -d)/failed
for DIR in $(find * -maxdepth 0 -type d -name '[A-Z]*'); do {
echo "Running $DIR Unit Tests"
composer -q --no-interaction --no-ansi --no-progress update -d ${DIR};
if [ $? != 0 ]; then
echo "$DIR: composer install failed" >> "${FAILED_FILE}"
continue
fi
${DIR}/vendor/bin/phpunit -c ${DIR}/phpunit.xml.dist;
if [ $? != 0 ]; then
echo "$DIR: failed" >> "${FAILED_FILE}"
fi
if [ -f "${DIR}/phpunit-snippets.xml.dist" ]; then
echo "Running $DIR Snippet Tests"
${DIR}/vendor/bin/phpunit -c ${DIR}/phpunit-snippets.xml.dist;
if [ $? != 0 ]; then
echo "$DIR (snippets): failed" >> "${FAILED_FILE}"
fi
fi
}; done

if [ -f "${FAILED_FILE}" ]; then
echo "--------- Failed tests --------------"
cat "${FAILED_FILE}"
echo "-------------------------------------"
exit 1
fi
13 changes: 13 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ jobs:
run: |
vendor/bin/phpunit -c ${{ matrix.phpunit-filename }}-snippets.xml.dist --verbose
test_package:
name: Package Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@verbose
with:
php-version: '8.0'
extensions: grpc
- name: Run Unit Test Suites
run: bash .github/run-package-tests.sh

style:
runs-on: ubuntu-latest
name: PHP Style Check
Expand Down
1 change: 1 addition & 0 deletions Bigtable/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0|^8.0",
"yoast/phpunit-polyfills": "^1.0",
"phpspec/prophecy": "^1.10.3",
"erusev/parsedown": "^1.6",
"phpdocumentor/reflection": "^3.0||^4.0"
},
Expand Down
3 changes: 2 additions & 1 deletion Bigtable/tests/Unit/BigtableClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Google\Cloud\Bigtable\BigtableClient;
use Google\Cloud\Bigtable\Table;
use Google\Cloud\Core\InsecureCredentialsWrapper;
use Google\Cloud\Core\Testing\TestHelpers;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

Expand All @@ -33,7 +34,7 @@ class BigtableClientTest extends TestCase
public function set_up()
{
$this->client = TestHelpers::stub(BigtableClient::class, [
['projectId' => 'my-project']
['projectId' => 'my-project', 'credentials' => new InsecureCredentialsWrapper()]
]);
}

Expand Down
2 changes: 1 addition & 1 deletion CommonProtos/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"google/common-protos": "^1.0||^2.0||^3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36"
"phpunit/phpunit": "^4.8|^5.0|^8.0"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"phpdocumentor/reflection": "^3.0||^4.0",
"erusev/parsedown": "^1.6",
"google/gax": "^1.9",
"opis/closure": "^3"
"opis/closure": "^3",
"google/cloud-common-protos": "^0.3"
},
"suggest": {
"opis/closure": "May be used to serialize closures to process jobs in the batch daemon. Please require version ^3.",
Expand Down
6 changes: 4 additions & 2 deletions Datastore/tests/Unit/DatastoreClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public function testGrpcConnection()
$this->checkAndSkipGrpcTests();

$client = TestHelpers::stub(DatastoreClient::class, [[
'transport' => 'grpc'
'projectId' => self::PROJECT,
'transport' => 'grpc',
]]);

$this->assertInstanceOf(Grpc::class, $client->___getProperty('connection'));
Expand All @@ -80,7 +81,8 @@ public function testRestConnection()
$this->checkAndSkipGrpcTests();

$client = TestHelpers::stub(DatastoreClient::class, [[
'transport' => 'rest'
'projectId' => self::PROJECT,
'transport' => 'rest',
]]);

$this->assertInstanceOf(Rest::class, $client->___getProperty('connection'));
Expand Down
3 changes: 2 additions & 1 deletion Filestore/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
}
},
"require": {
"google/gax": "^1.8.0"
"google/gax": "^1.8.0",
"google/cloud-common-protos": "^0.3"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0|^8.0",
Expand Down
4 changes: 3 additions & 1 deletion PubSub/tests/Unit/BatchPublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public function testGetCallback()

public function testPublishDeferred()
{
$client = TestHelpers::stub(PubSubClient::class, [], [
$client = TestHelpers::stub(PubSubClient::class, [
['suppressKeyFileNotice' => true, 'projectId' => 'example-project']
], [
'encode', 'connection'
]);
$client->___setProperty('encode', false);
Expand Down
5 changes: 3 additions & 2 deletions Redis/tests/Unit/V1/CloudRedisClientPartialVeneerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\Redis\Tests\Unit\V1;

use Google\ApiCore\Transport\GrpcTransport;
use Google\Cloud\Core\InsecureCredentialsWrapper;
use Google\Cloud\Core\Testing\GrpcTestTrait;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
Expand All @@ -42,13 +43,13 @@ public function testRestTransportFails()
$this->expectException('InvalidArgumentException');

new CloudRedisClient([
'transport' => 'rest'
'transport' => 'rest',
]);
}

public function testTransportDefaultsToGrpc()
{
$client = new CloudRedisPartial();
$client = new CloudRedisPartial(['credentials' => new InsecureCredentialsWrapper()]);
$this->assertFalse(isset($client->initialOptions['transport']));
$this->assertInstanceOf(GrpcTransport::class, $client->transport());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\Redis\Tests\Unit\V1beta1;

use Google\ApiCore\Transport\GrpcTransport;
use Google\Cloud\Core\InsecureCredentialsWrapper;
use Google\Cloud\Core\Testing\GrpcTestTrait;
use Google\Cloud\Redis\V1beta1\CloudRedisClient;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function testRestTransportFails()

public function testTransportDefaultsToGrpc()
{
$client = new CloudRedisPartial();
$client = new CloudRedisPartial(['credentials' => new InsecureCredentialsWrapper()]);
$this->assertFalse(isset($client->initialOptions['transport']));
$this->assertInstanceOf(GrpcTransport::class, $client->transport());
}
Expand Down
4 changes: 2 additions & 2 deletions Speech/tests/Unit/SpeechClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SpeechClientTest extends TestCase
public function set_up()
{
$this->client = TestHelpers::stub(SpeechClient::class, [
['languageCode' => 'en-US']
['languageCode' => 'en-US', 'suppressKeyFileNotice' => true]
]);
$this->connection = $this->prophesize(ConnectionInterface::class);
}
Expand All @@ -51,7 +51,7 @@ public function testThrowsExceptionWithoutLanguageCode()
{
$this->expectException('\InvalidArgumentException');

$client = TestHelpers::stub(SpeechClient::class);
$client = TestHelpers::stub(SpeechClient::class, [['suppressKeyFileNotice' => true]]);
$client->recognize(self::GCS_URI);
}

Expand Down
2 changes: 2 additions & 0 deletions Speech/tests/Unit/V1/SpeechClientExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Google\ApiCore\Call;
use Google\ApiCore\Testing\MockBidiStreamingCall;
use Google\ApiCore\Transport\TransportInterface;
use Google\Cloud\Core\InsecureCredentialsWrapper;
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig_AudioEncoding;
Expand All @@ -46,6 +47,7 @@ public function set_up()
$this->transport = $this->prophesize(TransportInterface::class);
$this->client = new SpeechClient([
'transport' => $this->transport->reveal(),
'credentials' => new InsecureCredentialsWrapper(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion Vision/tests/Unit/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testWithString()

public function testWithStorage()
{
$storage = new StorageClient;
$storage = new StorageClient(['suppressKeyFileNotice' => true]);
$bucket = $storage->bucket('test-bucket');
$object = $bucket->object('test-object.jpg');

Expand Down
2 changes: 2 additions & 0 deletions Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Google\ApiCore\Call;
use Google\ApiCore\Transport\TransportInterface;
use Google\Cloud\Core\InsecureCredentialsWrapper;
use Google\Cloud\Vision\V1\AnnotateImageRequest;
use Google\Cloud\Vision\V1\AnnotateImageResponse;
use Google\Cloud\Vision\V1\BatchAnnotateImagesRequest;
Expand Down Expand Up @@ -52,6 +53,7 @@ public function set_up()
$this->transport = $this->prophesize(TransportInterface::class);
$this->client = new ImageAnnotatorClient([
'transport' => $this->transport->reveal(),
'credentials' => new InsecureCredentialsWrapper(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion Vision/tests/Unit/VisionClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class VisionClientTest extends TestCase

public function set_up()
{
$this->client = TestHelpers::stub(VisionClient::class);
$this->client = TestHelpers::stub(VisionClient::class, [['suppressKeyFileNotice' => true]]);
$this->connection = $this->prophesize(ConnectionInterface::class);
}

Expand Down
83 changes: 0 additions & 83 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,101 +517,18 @@
"Google\\Cloud\\BigQuery\\Storage\\Tests\\": "BigQueryStorage/tests",
"Google\\Cloud\\BigQuery\\Tests\\": "BigQuery/tests",
"Google\\Cloud\\Bigtable\\Tests\\": "Bigtable/tests",
"Google\\Cloud\\Billing\\Budgets\\Tests\\": "BillingBudgets/tests",
"Google\\Cloud\\Billing\\Tests\\": "Billing/tests",
"Google\\Cloud\\BinaryAuthorization\\Tests\\": "BinaryAuthorization/tests",
"Google\\Cloud\\Build\\Tests\\": "Build/tests",
"Google\\Cloud\\CertificateManager\\Tests\\": "CertificateManager/tests",
"Google\\Cloud\\Channel\\Tests\\": "Channel/tests",
"Google\\Cloud\\CloudDms\\Tests\\": "Dms/tests",
"Google\\Cloud\\CommonProtos\\Tests\\": "CommonProtos/tests",
"Google\\Cloud\\Compute\\Tests\\": "Compute/tests",
"Google\\Cloud\\ContactCenterInsights\\Tests\\": "ContactCenterInsights/tests",
"Google\\Cloud\\ContainerAnalysis\\Tests\\": "ContainerAnalysis/tests",
"Google\\Cloud\\Container\\Tests\\": "Container/tests",
"Google\\Cloud\\Core\\Tests\\": "Core/tests",
"Google\\Cloud\\DataCatalog\\Tests\\": "DataCatalog/tests",
"Google\\Cloud\\DataFusion\\Tests\\": "DataFusion/tests",
"Google\\Cloud\\DataLabeling\\Tests\\": "tests",
"Google\\Cloud\\Dataflow\\Tests\\": "Dataflow/tests",
"Google\\Cloud\\Dataplex\\Tests\\": "Dataplex/tests",
"Google\\Cloud\\Dataproc\\Tests\\": "Dataproc/tests",
"Google\\Cloud\\Datastore\\Admin\\Tests\\": "DatastoreAdmin/tests",
"Google\\Cloud\\Datastore\\Tests\\": "Datastore/tests",
"Google\\Cloud\\Datastream\\Tests\\": "Datastream/tests",
"Google\\Cloud\\Debugger\\Tests\\": "Debugger/tests",
"Google\\Cloud\\Deploy\\Tests\\": "Deploy/tests",
"Google\\Cloud\\Dev\\": "dev/src",
"Google\\Cloud\\Dialogflow\\Tests\\": "Dialogflow/tests",
"Google\\Cloud\\Dlp\\Tests\\": "Dlp/tests",
"Google\\Cloud\\DocumentAI\\Tests\\": "DocumentAi/tests",
"Google\\Cloud\\Domains\\Tests\\": "Domains/tests",
"Google\\Cloud\\ErrorReporting\\Tests\\": "ErrorReporting/tests",
"Google\\Cloud\\EssentialContacts\\Tests\\": "EssentialContacts/tests",
"Google\\Cloud\\Eventarc\\Publishing\\Tests\\": "EventarcPublishing/tests",
"Google\\Cloud\\Eventarc\\Tests\\": "Eventarc/tests",
"Google\\Cloud\\Filestore\\Tests\\": "Filestore/tests",
"Google\\Cloud\\Firestore\\Tests\\": "Firestore/tests",
"Google\\Cloud\\Functions\\Tests\\": "Functions/tests",
"Google\\Cloud\\Gaming\\Tests\\": "Gaming/tests",
"Google\\Cloud\\GkeBackup\\Tests\\": "GkeBackup/tests",
"Google\\Cloud\\GkeConnect\\Gateway\\Tests\\": "GkeConnectGateway/tests",
"Google\\Cloud\\GkeHub\\Tests\\": "GkeHub/tests",
"Google\\Cloud\\GkeMultiCloud\\Tests\\": "GkeMultiCloud/tests",
"Google\\Cloud\\Iam\\Credentials\\Tests\\": "IamCredentials/tests",
"Google\\Cloud\\Iap\\Tests\\": "Iap/tests",
"Google\\Cloud\\Ids\\Tests\\": "Ids/tests",
"Google\\Cloud\\Iot\\Tests\\": "Iot/tests",
"Google\\Cloud\\Kms\\Tests\\": "Kms/tests",
"Google\\Cloud\\Language\\Tests\\": "Language/tests",
"Google\\Cloud\\LifeSciences\\Tests\\": "LifeSciences/tests",
"Google\\Cloud\\Logging\\Tests\\": "Logging/tests",
"Google\\Cloud\\ManagedIdentities\\Tests\\": "ManagedIdentities/tests",
"Google\\Cloud\\MediaTranslation\\Tests\\": "MediaTranslation/tests",
"Google\\Cloud\\Memcache\\Tests\\": "Memcache/tests",
"Google\\Cloud\\Metastore\\Tests\\": "DataprocMetastore/tests",
"Google\\Cloud\\Monitoring\\Tests\\": "Monitoring/tests",
"Google\\Cloud\\NetworkConnectivity\\Tests\\": "NetworkConnectivity/tests",
"Google\\Cloud\\NetworkManagement\\Tests\\": "NetworkManagement/tests",
"Google\\Cloud\\NetworkSecurity\\Tests\\": "NetworkSecurity/tests",
"Google\\Cloud\\Notebooks\\Tests\\": "Notebooks/tests",
"Google\\Cloud\\Optimization\\Tests\\": "Optimization/tests",
"Google\\Cloud\\Orchestration\\Airflow\\Service\\Tests\\": "OrchestrationAirflow/tests",
"Google\\Cloud\\OrgPolicy\\Tests\\": "OrgPolicy/tests",
"Google\\Cloud\\OsConfig\\Tests\\": "OsConfig/tests",
"Google\\Cloud\\OsLogin\\Tests\\": "OsLogin/tests",
"Google\\Cloud\\PolicyTroubleshooter\\Tests\\": "PolicyTroubleshooter/tests",
"Google\\Cloud\\PrivateCatalog\\Tests\\": "PrivateCatalog/tests",
"Google\\Cloud\\Profiler\\Tests\\": "Profiler/tests",
"Google\\Cloud\\PubSub\\Tests\\": "PubSub/tests",
"Google\\Cloud\\RecaptchaEnterprise\\Tests\\": "RecaptchaEnterprise/tests",
"Google\\Cloud\\RecommendationEngine\\Tests\\": "RecommendationEngine/tests",
"Google\\Cloud\\Recommender\\Tests\\": "Recommender/tests",
"Google\\Cloud\\Redis\\Tests\\": "Redis/tests",
"Google\\Cloud\\ResourceManager\\Tests\\": "ResourceManager/tests",
"Google\\Cloud\\ResourceSettings\\Tests\\": "ResourceSettings/tests",
"Google\\Cloud\\Retail\\Tests\\": "Retail/tests",
"Google\\Cloud\\Run\\Tests\\": "Run/tests",
"Google\\Cloud\\Scheduler\\Tests\\": "Scheduler/tests",
"Google\\Cloud\\SecretManager\\Tests\\": "SecretManager/tests",
"Google\\Cloud\\SecurityCenter\\Tests\\": "SecurityCenter/tests",
"Google\\Cloud\\Security\\PrivateCA\\Tests\\": "SecurityPrivateCa/tests",
"Google\\Cloud\\ServiceControl\\Tests\\": "ServiceControl/tests",
"Google\\Cloud\\ServiceDirectory\\Tests\\": "ServiceDirectory/tests",
"Google\\Cloud\\ServiceManagement\\Tests\\": "ServiceManagement/tests",
"Google\\Cloud\\ServiceUsage\\Tests\\": "ServiceUsage/tests",
"Google\\Cloud\\Shell\\Tests\\": "Shell/tests",
"Google\\Cloud\\Spanner\\Tests\\": "Spanner/tests",
"Google\\Cloud\\Speech\\Tests\\": "Speech/tests",
"Google\\Cloud\\Sql\\Tests\\": "SqlAdmin/tests",
"Google\\Cloud\\StorageTransfer\\Tests\\": "StorageTransfer/tests",
"Google\\Cloud\\Storage\\Tests\\": "Storage/tests",
"Google\\Cloud\\Talent\\Tests\\": "Talent/tests",
"Google\\Cloud\\Tasks\\Tests\\": "Tasks/tests",
"Google\\Cloud\\Tests\\": "tests",
"Google\\Cloud\\TextToSpeech\\Tests\\": "TextToSpeech/tests",
"Google\\Cloud\\Tpu\\Tests\\": "Tpu/tests",
"Google\\Cloud\\Trace\\Tests\\": "Trace/tests",
"Google\\Cloud\\Translate\\Tests\\": "Translate/tests",
"Google\\Cloud\\VMMigration\\Tests\\": "VmMigration/tests",
"Google\\Cloud\\VideoIntelligence\\Tests\\": "VideoIntelligence/tests",
Expand Down

0 comments on commit a27ff50

Please sign in to comment.