Skip to content

Commit

Permalink
fix: use exception::class instead of strings (#6051)
Browse files Browse the repository at this point in the history
fix: rename exceptions in test and phpDoc
  • Loading branch information
vishwarajanand authored Apr 10, 2023
1 parent 04acdb4 commit e707aa3
Show file tree
Hide file tree
Showing 118 changed files with 458 additions and 368 deletions.
3 changes: 2 additions & 1 deletion BigQuery/tests/System/ManageDatasetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\BigQuery\Tests\System;

use Google\Cloud\Core\Testing\System\KeyManager;
use Google\Cloud\Core\Exception\FailedPreconditionException;

/**
* @group bigquery
Expand Down Expand Up @@ -144,7 +145,7 @@ public function testSetDatasetDefaultEncryption()

public function testUpdateDatasetConcurrentUpdateFails()
{
$this->expectException('Google\Cloud\Core\Exception\FailedPreconditionException');
$this->expectException(FailedPreconditionException::class);

$data = [
'friendlyName' => 'foo',
Expand Down
3 changes: 2 additions & 1 deletion BigQuery/tests/System/ManageTablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\BigQuery\Table;
use Google\Cloud\Core\ExponentialBackoff;
use Google\Cloud\Core\Exception\FailedPreconditionException;

/**
* @group bigquery
Expand Down Expand Up @@ -134,7 +135,7 @@ public function testUpdateTable()

public function testUpdateTableConcurrentUpdateFails()
{
$this->expectException('Google\Cloud\Core\Exception\FailedPreconditionException');
$this->expectException(FailedPreconditionException::class);

$data = [
'friendlyName' => 'foo',
Expand Down
14 changes: 8 additions & 6 deletions BigQuery/tests/System/RegionalizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace Google\Cloud\BigQuery\Tests\System;

use Google\Cloud\Core\Exception\NotFoundException;

/**
* @group bigquery
* @group bigquery-regionalization
Expand Down Expand Up @@ -70,7 +72,7 @@ public function testCopyJobSucceedsInAsia()

public function testCopyJobThrowsNotFoundExceptionInUS()
{
$this->expectException('Google\Cloud\Core\Exception\NotFoundException');
$this->expectException(NotFoundException::class);

$targetTable = self::$datasetAsia
->table(uniqid(self::TESTING_PREFIX));
Expand All @@ -96,7 +98,7 @@ public function testExtractJobSucceedsInAsia()

public function testExtractJobThrowsNotFoundExceptionInUS()
{
$this->expectException('Google\Cloud\Core\Exception\NotFoundException');
$this->expectException(NotFoundException::class);

$object = self::$bucketAsia->object(uniqid(self::TESTING_PREFIX));
$extractConfig = self::$tableAsia->extract($object)
Expand All @@ -123,7 +125,7 @@ public function testLoadJobSucceedsInAsia()

public function testLoadJobThrowsNotFoundExceptionInUS()
{
$this->expectException('Google\Cloud\Core\Exception\NotFoundException');
$this->expectException(NotFoundException::class);

$loadConfig = self::$tableAsia->load(
file_get_contents(__DIR__ . '/data/table-data.json')
Expand Down Expand Up @@ -154,7 +156,7 @@ public function testRunQuerySucceedsInAsia()

public function testRunQueryThrowsNotFoundExceptionInUS()
{
$this->expectException('Google\Cloud\Core\Exception\NotFoundException');
$this->expectException(NotFoundException::class);

$queryConfig = self::$client->query(
sprintf(
Expand Down Expand Up @@ -187,7 +189,7 @@ public function testGetJobSucceedsInAsia()

public function testGetJobThrowsNotFoundExceptionInUS()
{
$this->expectException('Google\Cloud\Core\Exception\NotFoundException');
$this->expectException(NotFoundException::class);

$queryConfig = self::$client->query(
sprintf(
Expand Down Expand Up @@ -223,7 +225,7 @@ public function testCancelJobSucceedsInAsia()

public function testCancelJobThrowsNotFoundExceptionInUS()
{
$this->expectException('Google\Cloud\Core\Exception\NotFoundException');
$this->expectException(NotFoundException::class);

$queryConfig = self::$client->query(
sprintf(
Expand Down
3 changes: 2 additions & 1 deletion BigQuery/tests/Unit/BigNumericTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\BigQuery\Tests\Unit;

use Google\Cloud\BigQuery\BigNumeric;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -31,7 +32,7 @@ class BigNumericTest extends TestCase
*/
public function testInvalidValues($value)
{
$this->expectException('\InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);

new BigNumeric($value);
}
Expand Down
3 changes: 2 additions & 1 deletion BigQuery/tests/Unit/JobWaitTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace Google\Cloud\BigQuery\Tests\Unit;

use Google\Cloud\BigQuery\Exception\JobException;
use Google\Cloud\BigQuery\Job;
use Google\Cloud\BigQuery\JobWaitTrait;
use Google\Cloud\Core\Testing\TestHelpers;
Expand Down Expand Up @@ -85,7 +86,7 @@ function () use (&$isReloadCalled) {

public function testWaitThrowsExceptionWhenMaxAttemptsMet()
{
$this->expectException('Google\Cloud\BigQuery\Exception\JobException');
$this->expectException(JobException::class);
$this->expectExceptionMessage('Job did not complete within the allowed number of retries.');

$this->trait->call('wait', [
Expand Down
3 changes: 2 additions & 1 deletion BigQuery/tests/Unit/NumericTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\BigQuery\Tests\Unit;

use Google\Cloud\BigQuery\Numeric;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -30,7 +31,7 @@ class NumericTest extends TestCase
*/
public function testInvalidValues($value)
{
$this->expectException('\InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);

new Numeric($value);
}
Expand Down
11 changes: 6 additions & 5 deletions BigQuery/tests/Unit/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Google\Cloud\Core\Upload\AbstractUploader;
use Google\Cloud\Storage\Connection\ConnectionInterface as StorageConnectionInterface;
use Google\Cloud\Storage\StorageObject;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -613,7 +614,7 @@ public function testInsertsRowsWithAutoCreate()

public function testInsertRowsThrowsExceptionWithoutSchema()
{
$this->expectException('\InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('A schema is required when creating a table.');

$options = [
Expand Down Expand Up @@ -642,7 +643,7 @@ public function testInsertRowsThrowsExceptionWithoutSchema()

public function testInsertRowsThrowsExceptionWithUnretryableTableFailure()
{
$this->expectException('\Exception');
$this->expectException(\Exception::class);

$options = [
'autoCreate' => true,
Expand Down Expand Up @@ -685,7 +686,7 @@ public function testInsertRowsThrowsExceptionWithUnretryableTableFailure()

public function testInsertRowsThrowsExceptionWhenMaxRetryLimitHit()
{
$this->expectException('Google\Cloud\Core\Exception\NotFoundException');
$this->expectException(NotFoundException::class);

$options = [
'autoCreate' => true,
Expand Down Expand Up @@ -729,7 +730,7 @@ public function testInsertRowsThrowsExceptionWhenMaxRetryLimitHit()

public function testInsertRowsThrowsExceptionWithoutDataKey()
{
$this->expectException('\InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('A row must have a data key.');

$table = $this->getTable($this->connection);
Expand All @@ -738,7 +739,7 @@ public function testInsertRowsThrowsExceptionWithoutDataKey()

public function testInsertRowsThrowsExceptionWithZeroRows()
{
$this->expectException('\InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Must provide at least a single row.');

$table = $this->getTable($this->connection);
Expand Down
2 changes: 1 addition & 1 deletion Bigtable/src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function __construct(
* @param array $options [optional] Configuration options.
* @return void
* @throws ApiException|BigtableDataOperationException If the remote call fails or operation fails.
* @throws InvalidArgumentException If rowMutations is a list instead of associative array indexed by row key.
* @throws \InvalidArgumentException If rowMutations is a list instead of associative array indexed by row key.
*/
public function mutateRows(array $rowMutations, array $options = [])
{
Expand Down
39 changes: 20 additions & 19 deletions Bigtable/tests/Unit/ChunkFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Google\ApiCore\ServerStream;
use Google\Cloud\Bigtable\ChunkFormatter;
use Google\Cloud\Bigtable\Exception\BigtableDataOperationException;
use Google\Cloud\Bigtable\V2\ReadRowsResponse;
use Google\Cloud\Bigtable\V2\ReadRowsResponse\CellChunk as ReadRowsResponse_CellChunk;
use Google\Protobuf\StringValue;
Expand Down Expand Up @@ -52,7 +53,7 @@ function () {

public function testNewRowShouldThrowWhenNoRowKey()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A row key must be set.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -99,7 +100,7 @@ public function testNewRowShouldGenerateWhenRowKeyIsZero()

public function testNewRowShouldThrowWhenResetIsTrue()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A new row cannot be reset.');

$readRowsResponse = new ReadRowsResponse;
Expand All @@ -115,7 +116,7 @@ public function testNewRowShouldThrowWhenResetIsTrue()

public function testNewRowShouldThrowWhenNoFamilyName()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A family must be set.');

$readRowsResponse = new ReadRowsResponse;
Expand All @@ -130,7 +131,7 @@ public function testNewRowShouldThrowWhenNoFamilyName()

public function testNewRowShouldThrowWhenNoQualifier()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A column qualifier must be set.');

$readRowsResponse = new ReadRowsResponse;
Expand All @@ -148,7 +149,7 @@ public function testNewRowShouldThrowWhenNoQualifier()

public function testNewRowShouldThrowWhenValueSizeAndCommitRow()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A row cannot have a value size and be a commit row.');

$readRowsResponse = new ReadRowsResponse;
Expand All @@ -171,7 +172,7 @@ public function testNewRowShouldThrowWhenValueSizeAndCommitRow()

public function testNewRowShouldThrowWhenSameRowKeyFollows()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A commit happened but the same key followed.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -380,7 +381,7 @@ public function testNewRowShouldGenerateNewRowWithLabels()

public function testNewRowShouldThrowWhenPendingRow()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('Response ended with pending row without commit.');

$readRowsResponse = new ReadRowsResponse;
Expand All @@ -404,7 +405,7 @@ public function testNewRowShouldThrowWhenPendingRow()

public function testValidateResetWithRowKey()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A reset should have no data.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -432,7 +433,7 @@ public function testValidateResetWithRowKey()

public function testValidateResetWithQualifier()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A reset should have no data.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -460,7 +461,7 @@ public function testValidateResetWithQualifier()

public function testValidateResetWithValue()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A reset should have no data.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -488,7 +489,7 @@ public function testValidateResetWithValue()

public function testValidateResetWithTimestampMicro()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A reset should have no data.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -516,7 +517,7 @@ public function testValidateResetWithTimestampMicro()

public function testRowInProgressDifferentRowKey()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A commit is required between row keys.');

$readRowsResponse = new ReadRowsResponse;
Expand All @@ -543,7 +544,7 @@ public function testRowInProgressDifferentRowKey()

public function testRowInProgressFamilyNameWithouQualifier()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A qualifier must be specified.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -573,7 +574,7 @@ public function testRowInProgressFamilyNameWithouQualifier()

public function testRowInProgressValueSizeAndCommit()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A row cannot have a value size and be a commit row.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -820,7 +821,7 @@ public function testRowInProgressWithLabels()

public function testCellInProgressValueSizeAndCommit()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A row cannot have a value size and be a commit row.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -849,7 +850,7 @@ public function testCellInProgressValueSizeAndCommit()

public function testCellInProgressValidateResetWithRowKey()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A reset should have no data.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -878,7 +879,7 @@ public function testCellInProgressValidateResetWithRowKey()

public function testCellInProgressValidateResetWithQualifier()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A reset should have no data.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -909,7 +910,7 @@ public function testCellInProgressValidateResetWithQualifier()

public function testCellInProgressValidateResetWithValue()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A reset should have no data.');

$readRowsResponse = new ReadRowsResponse;
Expand Down Expand Up @@ -938,7 +939,7 @@ public function testCellInProgressValidateResetWithValue()

public function testCellInProgressValidateResetWithTimestampMicro()
{
$this->expectException('\Google\Cloud\Bigtable\Exception\BigtableDataOperationException');
$this->expectException(BigtableDataOperationException::class);
$this->expectExceptionMessage('A reset should have no data.');

$readRowsResponse = new ReadRowsResponse;
Expand Down
Loading

0 comments on commit e707aa3

Please sign in to comment.