diff --git a/src/BigQuery/BigQueryClient.php b/src/BigQuery/BigQueryClient.php index 38d48f70942f..231e928b937e 100644 --- a/src/BigQuery/BigQueryClient.php +++ b/src/BigQuery/BigQueryClient.php @@ -105,7 +105,7 @@ public function __construct(array $config = []) * $isComplete = $queryResults->isComplete(); // check the query's status * } * - * foreach ($queryResults->getRows() as $row) { + * foreach ($queryResults->rows() as $row) { * echo $row['name']; * } * ``` @@ -159,7 +159,7 @@ public function runQuery($query, array $options = []) * $job = $bigQuery->runQueryAsJob('SELECT * FROM [bigquery-public-data:usa_names.usa_1910_2013]'); * * $isComplete = false; - * $queryResults = $job->getQueryResults(); + * $queryResults = $job->queryResults(); * * while (!$isComplete) { * sleep(1); // let's wait for a moment... @@ -167,7 +167,7 @@ public function runQuery($query, array $options = []) * $isComplete = $queryResults->isComplete(); // check the query's status * } * - * foreach ($queryResults->getRows() as $row) { + * foreach ($queryResults->rows() as $row) { * echo $row['name']; * } * ``` @@ -227,7 +227,7 @@ public function job($id) * ]); * * foreach ($jobs as $job) { - * var_dump($job->getId()); + * var_dump($job->id()); * } * ``` * @@ -294,7 +294,7 @@ public function dataset($id) * $datasets = $bigQuery->datasets(); * * foreach ($datasets as $dataset) { - * var_dump($dataset->getId()); + * var_dump($dataset->id()); * } * ``` * diff --git a/src/BigQuery/Dataset.php b/src/BigQuery/Dataset.php index 019a900659c3..f94fd64e5c7b 100644 --- a/src/BigQuery/Dataset.php +++ b/src/BigQuery/Dataset.php @@ -32,26 +32,26 @@ class Dataset private $connection; /** - * @var array The dataset's metadata. + * @var array The dataset's identity. */ - private $data; + private $identity; /** - * @var array The dataset's identity. + * @var array The dataset's metadata. */ - private $identity; + private $info; /** * @param ConnectionInterface $connection Represents a connection to * BigQuery. * @param string $id The dataset's ID. * @param string $projectId The project's ID. - * @param array $data The dataset's metadata. + * @param array $info The dataset's metadata. */ - public function __construct(ConnectionInterface $connection, $id, $projectId, array $data = []) + public function __construct(ConnectionInterface $connection, $id, $projectId, array $info = []) { $this->connection = $connection; - $this->data = $data; + $this->info = $info; $this->identity = [ 'datasetId' => $id, 'projectId' => $projectId @@ -121,9 +121,9 @@ public function delete(array $options = []) public function update(array $metadata, array $options = []) { $options += $metadata; - $this->data = $this->connection->patchDataset($options + $this->identity); + $this->info = $this->connection->patchDataset($options + $this->identity); - return $this->data; + return $this->info; } /** @@ -152,7 +152,7 @@ public function table($id) * $tables = $dataset->tables(); * * foreach ($tables as $table) { - * var_dump($table->getId()); + * var_dump($table->id()); * } * ``` * @@ -236,7 +236,7 @@ public function createTable($id, array $options = []) * * Example: * ``` - * $info = $dataset->getInfo(); + * $info = $dataset->info(); * echo $info['friendlyName']; * ``` * @@ -245,13 +245,13 @@ public function createTable($id, array $options = []) * @param array $options Configuration options. * @return array */ - public function getInfo(array $options = []) + public function info(array $options = []) { - if (!$this->data) { + if (!$this->info) { $this->reload($options); } - return $this->data; + return $this->info; } /** @@ -260,7 +260,7 @@ public function getInfo(array $options = []) * Example: * ``` * $dataset->reload(); - * $info = $dataset->getInfo(); + * $info = $dataset->info(); * echo $info['friendlyName']; * ``` * @@ -271,11 +271,7 @@ public function getInfo(array $options = []) */ public function reload(array $options = []) { - if (!$this->data) { - $this->data = $this->connection->getDataset($options + $this->identity); - } - - return $this->data; + return $this->info = $this->connection->getDataset($options + $this->identity); } /** @@ -283,12 +279,12 @@ public function reload(array $options = []) * * Example: * ``` - * echo $dataset->getId(); + * echo $dataset->id(); * ``` * * @return string */ - public function getId() + public function id() { return $this->identity['datasetId']; } @@ -300,12 +296,12 @@ public function getId() * * Example: * ``` - * echo $dataset->getIdentity()['projectId']; + * echo $dataset->identity()['projectId']; * ``` * * @return array */ - public function getIdentity() + public function identity() { return $this->identity; } diff --git a/src/BigQuery/Job.php b/src/BigQuery/Job.php index 787a4ce4965f..8b690cc9550a 100644 --- a/src/BigQuery/Job.php +++ b/src/BigQuery/Job.php @@ -33,26 +33,26 @@ class Job private $connection; /** - * @var array The job's metadata + * @var array The job's identity. */ - private $data; + private $identity; /** - * @var array The job's identity. + * @var array The job's metadata */ - private $identity; + private $info; /** * @param ConnectionInterface $connection Represents a connection to * BigQuery. * @param string $id The job's ID. * @param string $projectId The project's ID. - * @param array $data The job's metadata. + * @param array $info The job's metadata. */ - public function __construct(ConnectionInterface $connection, $id, $projectId, array $data = []) + public function __construct(ConnectionInterface $connection, $id, $projectId, array $info = []) { $this->connection = $connection; - $this->data = $data; + $this->info = $info; $this->identity = [ 'jobId' => $id, 'projectId' => $projectId @@ -114,7 +114,7 @@ public function cancel(array $options = []) * Example: * ``` * $job = $bigQuery->runQueryAsJob('SELECT * FROM [bigquery-public-data:usa_names.usa_1910_2013]'); - * $queryResults = $job->getQueryResults(); + * $queryResults = $job->queryResults(); * ``` * * @see https://cloud.google.com/bigquery/docs/reference/v2/jobs/getQueryResults @@ -130,7 +130,7 @@ public function cancel(array $options = []) * } * @return array */ - public function getQueryResults(array $options = []) + public function queryResults(array $options = []) { $response = $this->connection->getQueryResults($options + $this->identity); @@ -164,7 +164,7 @@ public function getQueryResults(array $options = []) */ public function isComplete(array $options = []) { - return $this->getInfo($options)['status']['state'] === 'DONE'; + return $this->info($options)['status']['state'] === 'DONE'; } /** @@ -173,7 +173,7 @@ public function isComplete(array $options = []) * * Example: * ``` - * $info = $job->getInfo(); + * $info = $job->info(); * echo $info['statistics']['startTime']; * ``` * @@ -182,13 +182,13 @@ public function isComplete(array $options = []) * @param array $options Configuration options. * @return array */ - public function getInfo(array $options = []) + public function info(array $options = []) { - if (!$this->data) { + if (!$this->info) { $this->reload($options); } - return $this->data; + return $this->info; } /** @@ -209,7 +209,7 @@ public function getInfo(array $options = []) */ public function reload(array $options = []) { - return $this->data = $this->connection->getJob($options + $this->identity); + return $this->info = $this->connection->getJob($options + $this->identity); } /** @@ -217,12 +217,12 @@ public function reload(array $options = []) * * Example: * ``` - * echo $job->getId(); + * echo $job->id(); * ``` * * @return string */ - public function getId() + public function id() { return $this->identity['jobId']; } @@ -234,12 +234,12 @@ public function getId() * * Example: * ``` - * echo $job->getIdentity()['projectId']; + * echo $job->identity()['projectId']; * ``` * * @return array */ - public function getIdentity() + public function identity() { return $this->identity; } diff --git a/src/BigQuery/QueryResults.php b/src/BigQuery/QueryResults.php index 2e3f3f46123d..d21745fa8311 100644 --- a/src/BigQuery/QueryResults.php +++ b/src/BigQuery/QueryResults.php @@ -32,14 +32,14 @@ class QueryResults private $connection; /** - * @var array The query result's metadata. + * @var array The query result's identity. */ - private $data; + private $identity; /** - * @var array The query result's identity. + * @var array The query result's metadata. */ - private $identity; + private $info; /** * @var array The options to use when reloading query data. @@ -49,19 +49,19 @@ class QueryResults /** * This class should be not instantiated directly, but as a result of * calling {@see Google\Cloud\BigQuery\BigQueryClient::runQuery} or - * {@see Google\Cloud\BigQuery\Job::getQueryResults}. + * {@see Google\Cloud\BigQuery\Job::queryResults}. * * @param ConnectionInterface $connection Represents a connection to * BigQuery. * @param string $jobId The job's ID. * @param string $projectId The project's ID. - * @param array $data The query result's metadata. + * @param array $info The query result's metadata. * @param array $reloadOptions The options to use when reloading query data. */ - public function __construct(ConnectionInterface $connection, $jobId, $projectId, array $data, array $reloadOptions) + public function __construct(ConnectionInterface $connection, $jobId, $projectId, array $info, array $reloadOptions) { $this->connection = $connection; - $this->data = $data; + $this->info = $info; $this->reloadOptions = $reloadOptions; $this->identity = [ 'jobId' => $jobId, @@ -79,7 +79,7 @@ public function __construct(ConnectionInterface $connection, $jobId, $projectId, * $isComplete = $queryResults->isComplete(); * * if ($isComplete) { - * $rows = $queryResults->getRows(); + * $rows = $queryResults->rows(); * * foreach ($rows as $row) { * echo $row['name']; @@ -91,22 +91,22 @@ public function __construct(ConnectionInterface $connection, $jobId, $projectId, * @return array * @throws GoogleException Thrown if the query has not yet completed. */ - public function getRows(array $options = []) + public function rows(array $options = []) { if (!$this->isComplete()) { throw new GoogleException('The query has not completed yet.'); } - if (!isset($this->data['rows'])) { + if (!isset($this->info['rows'])) { return; } - $schema = $this->data['schema']['fields']; + $schema = $this->info['schema']['fields']; while (true) { - $options['pageToken'] = isset($this->data['pageToken']) ? $this->data['pageToken'] : null; + $options['pageToken'] = isset($this->info['pageToken']) ? $this->info['pageToken'] : null; - foreach ($this->data['rows'] as $row) { + foreach ($this->info['rows'] as $row) { $mergedRow = []; foreach ($row['f'] as $key => $value) { @@ -120,7 +120,7 @@ public function getRows(array $options = []) return; } - $this->data = $this->connection->getQueryResults($options + $this->identity); + $this->info = $this->connection->getQueryResults($options + $this->identity); } } @@ -145,7 +145,7 @@ public function getRows(array $options = []) */ public function isComplete() { - return $this->data['jobComplete']; + return $this->info['jobComplete']; } /** @@ -153,7 +153,7 @@ public function isComplete() * * Example: * ``` - * $info = $queryResults->getInfo(); + * $info = $queryResults->info(); * echo $info['totalBytesProcessed']; * ``` * @@ -162,9 +162,9 @@ public function isComplete() * * @return array */ - public function getInfo() + public function info() { - return $this->data; + return $this->info; } /** @@ -172,7 +172,7 @@ public function getInfo() * * Useful when needing to poll an incomplete query * for status. Configuration options will be inherited from - * {@see Google\Cloud\BigQuery\Job::getQueryResults} or + * {@see Google\Cloud\BigQuery\Job::queryResults} or * {@see Google\Cloud\BigQuery\BigQueryClient::runQuery}, but they can be * overridden if needed. * @@ -200,7 +200,7 @@ public function getInfo() public function reload(array $options = []) { $options += $this->identity; - return $this->data = $this->connection->getQueryResults($options + $this->reloadOptions); + return $this->info = $this->connection->getQueryResults($options + $this->reloadOptions); } /** @@ -210,12 +210,12 @@ public function reload(array $options = []) * * Example: * ``` - * echo $queryResults->getIdentity()['projectId']; + * echo $queryResults->identity()['projectId']; * ``` * * @return array */ - public function getIdentity() + public function identity() { return $this->identity; } diff --git a/src/BigQuery/Table.php b/src/BigQuery/Table.php index 2c1b35b20baf..c39028fca89a 100644 --- a/src/BigQuery/Table.php +++ b/src/BigQuery/Table.php @@ -36,14 +36,14 @@ class Table private $connection; /** - * @var array The table's metadata + * @var array The table's identity. */ - private $data; + private $identity; /** - * @var array The table's identity. + * @var array The table's metadata */ - private $identity; + private $info; /** * @param ConnectionInterface $connection Represents a connection to @@ -51,12 +51,12 @@ class Table * @param string $id The table's id. * @param string $datasetId The dataset's id. * @param string $projectId The project's id. - * @param array $data The table's metadata. + * @param array $info The table's metadata. */ - public function __construct(ConnectionInterface $connection, $id, $datasetId, $projectId, array $data = []) + public function __construct(ConnectionInterface $connection, $id, $datasetId, $projectId, array $info = []) { $this->connection = $connection; - $this->data = $data; + $this->info = $info; $this->identity = [ 'tableId' => $id, 'datasetId' => $datasetId, @@ -91,7 +91,7 @@ public function exists() * * Example: * ``` - * foreach ($table->getRows() as $row) { + * foreach ($table->rows() as $row) { * echo $row['name']; * } * ``` @@ -106,10 +106,10 @@ public function exists() * } * @return \Generator */ - public function getRows(array $options = []) + public function rows(array $options = []) { $options['pageToken'] = null; - $schema = $this->getInfo()['schema']['fields']; + $schema = $this->info()['schema']['fields']; do { $response = $this->connection->listTableData($options + $this->identity); @@ -161,7 +161,7 @@ public function copy(Table $destination, array $options = []) 'copy', $this->identity['projectId'], [ - 'destinationTable' => $destination->getIdentity(), + 'destinationTable' => $destination->identity(), 'sourceTable' => $this->identity ], $options @@ -196,7 +196,7 @@ public function copy(Table $destination, array $options = []) */ public function export(Object $destination, array $options = []) { - $objIdentity = $destination->getIdentity(); + $objIdentity = $destination->identity(); $config = $this->buildJobConfig( 'extract', $this->identity['projectId'], @@ -281,7 +281,7 @@ public function load($data, array $options = []) */ public function loadFromStorage(Object $object, array $options = []) { - $objIdentity = $object->getIdentity(); + $objIdentity = $object->identity(); $options['jobConfig']['sourceUris'] = ['gs://' . $objIdentity['bucket'] . '/' . $objIdentity['object']]; return $this->load(null, $options); @@ -293,7 +293,7 @@ public function loadFromStorage(Object $object, array $options = []) * * Example: * ``` - * $info = $table->getInfo(); + * $info = $table->info(); * echo $info['friendlyName']; * ``` * @@ -302,13 +302,13 @@ public function loadFromStorage(Object $object, array $options = []) * @param array $options Configuration options. * @return array */ - public function getInfo(array $options = []) + public function info(array $options = []) { - if (!$this->data) { + if (!$this->info) { $this->reload($options); } - return $this->data; + return $this->info; } /** @@ -317,7 +317,7 @@ public function getInfo(array $options = []) * Example: * ``` * $table->reload(); - * $info = $table->getInfo(); + * $info = $table->info(); * echo $info['friendlyName']; * ``` * @@ -328,7 +328,7 @@ public function getInfo(array $options = []) */ public function reload(array $options = []) { - return $this->data = $this->connection->getTable($options + $this->identity); + return $this->info = $this->connection->getTable($options + $this->identity); } /** @@ -336,12 +336,12 @@ public function reload(array $options = []) * * Example: * ``` - * echo $table->getId(); + * echo $table->id(); * ``` * * @return string */ - public function getId() + public function id() { return $this->identity['tableId']; } @@ -353,12 +353,12 @@ public function getId() * * Example: * ``` - * echo $table->getIdentity()['projectId']; + * echo $table->identity()['projectId']; * ``` * * @return array */ - public function getIdentity() + public function identity() { return $this->identity; } diff --git a/src/Storage/Bucket.php b/src/Storage/Bucket.php index 44c5765d73db..67cb839b4600 100644 --- a/src/Storage/Bucket.php +++ b/src/Storage/Bucket.php @@ -30,41 +30,41 @@ class Bucket { /** - * @var ConnectionInterface Represents a connection to Cloud Storage. + * @var Acl ACL for the bucket. */ - private $connection; + private $acl; /** - * @var array The bucket's identity. + * @var ConnectionInterface Represents a connection to Cloud Storage. */ - private $identity; + private $connection; /** - * @var array The bucket's metadata. + * @var Acl Default ACL for objects created within the bucket. */ - private $data; + private $defaultAcl; /** - * @var Acl ACL for the bucket. + * @var array The bucket's identity. */ - private $acl; + private $identity; /** - * @var Acl Default ACL for objects created within the bucket. + * @var array The bucket's metadata. */ - private $defaultAcl; + private $info; /** * @param ConnectionInterface $connection Represents a connection to Cloud * Storage. * @param string $name The bucket's name. - * @param array $data The bucket's metadata. + * @param array $info The bucket's metadata. */ - public function __construct(ConnectionInterface $connection, $name, array $data = null) + public function __construct(ConnectionInterface $connection, $name, array $info = null) { $this->connection = $connection; $this->identity = ['bucket' => $name]; - $this->data = $data; + $this->info = $info; $this->acl = new Acl($this->connection, 'bucketAccessControls', $this->identity); $this->defaultAcl = new Acl($this->connection, 'defaultObjectAccessControls', $this->identity); } @@ -302,7 +302,7 @@ public function object($name, array $options = []) * ]); * * foreach ($objects as $object) { - * var_dump($object->getName()); + * var_dump($object->name()); * } * ``` * @@ -421,17 +421,16 @@ public function delete(array $options = []) */ public function update(array $options = []) { - $this->data = $this->connection->patchBucket($options + $this->identity); - - return $this->data; + return $this->info = $this->connection->patchBucket($options + $this->identity); } /** - * Retrieves the bucket's details. + * Retrieves the bucket's details. If no bucket data is cached a network + * request will be made to retrieve it. * * Example: * ``` - * $info = $bucket->getInfo(); + * $info = $bucket->info(); * echo $info['location']; * ``` * @@ -440,8 +439,6 @@ public function update(array $options = []) * @param array $options { * Configuration options. * - * @type bool $force If true fetches fresh data, otherwise returns data - * stored locally if it exists. * @type string $ifMetagenerationMatch Makes the return of the bucket * metadata conditional on whether the bucket's current * metageneration matches the given value. @@ -453,13 +450,44 @@ public function update(array $options = []) * } * @return array */ - public function getInfo(array $options = []) + public function info(array $options = []) { - if (!$this->data || isset($options['force'])) { - $this->data = $this->connection->getBucket($options + $this->identity); + if (!$this->info) { + $this->reload($options); } - return $this->data; + return $this->info; + } + + /** + * Triggers a network request to reload the bucket's details. + * + * Example: + * ``` + * $bucket->reload(); + * $info = $bucket->info(); + * echo $info['location']; + * ``` + * + * @see https://cloud.google.com/storage/docs/json_api/v1/buckets/get Buckets get API documentation. + * + * @param array $options { + * Configuration options. + * + * @type string $ifMetagenerationMatch Makes the return of the bucket + * metadata conditional on whether the bucket's current + * metageneration matches the given value. + * @type string $ifMetagenerationNotMatch Makes the return of the bucket + * metadata conditional on whether the bucket's current + * metageneration does not match the given value. + * @type string $projection Determines which properties to return. May + * be either 'full' or 'noAcl'. + * } + * @return array + */ + public function reload(array $options = []) + { + return $this->info = $this->connection->getBucket($options + $this->identity); } /** @@ -467,12 +495,12 @@ public function getInfo(array $options = []) * * Example: * ``` - * echo $bucket->getName(); + * echo $bucket->name(); * ``` * * @return string */ - public function getName() + public function name() { return $this->identity['bucket']; } diff --git a/src/Storage/Object.php b/src/Storage/Object.php index 2d69536d4f6c..02417bd09ddb 100644 --- a/src/Storage/Object.php +++ b/src/Storage/Object.php @@ -29,14 +29,14 @@ class Object { /** - * @var ConnectionInterface Represents a connection to Cloud Storage. + * @var Acl ACL for the object. */ - private $connection; + private $acl; /** - * @var array The object's metadata. + * @var ConnectionInterface Represents a connection to Cloud Storage. */ - private $data; + private $connection; /** * @var array The object's identity. @@ -44,9 +44,9 @@ class Object private $identity; /** - * @var Acl ACL for the object. + * @var array The object's metadata. */ - private $acl; + private $info; /** * @param ConnectionInterface $connection Represents a connection to Cloud @@ -54,12 +54,12 @@ class Object * @param string $name The object's name. * @param string $bucket The name of the bucket the object is contained in. * @param string $generation The generation of the object. - * @param array $data The object's metadata. + * @param array $info The object's metadata. */ - public function __construct(ConnectionInterface $connection, $name, $bucket, $generation = null, array $data = null) + public function __construct(ConnectionInterface $connection, $name, $bucket, $generation = null, array $info = null) { $this->connection = $connection; - $this->data = $data; + $this->info = $info; $this->identity = [ 'bucket' => $bucket, 'object' => $name, @@ -188,9 +188,7 @@ public function delete(array $options = []) public function update(array $metadata, array $options = []) { $options += $metadata; - $this->data = $this->connection->patchObject($options + $this->identity); - - return $this->data; + return $this->info = $this->connection->patchObject($options + $this->identity); } /** @@ -237,11 +235,12 @@ public function downloadToFile($path, array $options = []) } /** - * Retrieves the object's details. + * Retrieves the object's details. If no object data is cached a network + * request will be made to retrieve it. * * Example: * ``` - * $info = $object->getInfo(); + * $info = $object->info(); * echo $info['metadata']; * ``` * @@ -250,8 +249,6 @@ public function downloadToFile($path, array $options = []) * @param array $options { * Configuration options. * - * @type bool $force If true fetches fresh data, otherwise returns data - * stored locally if it exists. * @type string $ifGenerationMatch Makes the operation conditional on * whether the object's current generation matches the given * value. @@ -269,13 +266,50 @@ public function downloadToFile($path, array $options = []) * } * @return array */ - public function getInfo(array $options = []) + public function info(array $options = []) { - if (!$this->data || isset($options['force'])) { - $this->data = $this->connection->getObject($options + $this->identity); + if (!$this->info) { + $this->reload($options); } - return $this->data; + return $this->info; + } + + /** + * Triggers a network request to reload the object's details. + * + * Example: + * ``` + * $object->reload(); + * $info = $object->info(); + * echo $info['location']; + * ``` + * + * @see https://cloud.google.com/storage/docs/json_api/v1/objects/get Objects get API documentation. + * + * @param array $options { + * Configuration options. + * + * @type string $ifGenerationMatch Makes the operation conditional on + * whether the object's current generation matches the given + * value. + * @type string $ifGenerationNotMatch Makes the operation conditional on + * whether the object's current generation does not match the + * given value. + * @type string $ifMetagenerationMatch Makes the operation conditional + * on whether the object's current metageneration matches the + * given value. + * @type string $ifMetagenerationNotMatch Makes the operation + * conditional on whether the object's current metageneration does + * not match the given value. + * @type string $projection Determines which properties to return. May + * be either 'full' or 'noAcl'. + * } + * @return array + */ + public function reload(array $options = []) + { + return $this->info = $this->connection->getObject($options + $this->identity); } /** @@ -283,12 +317,12 @@ public function getInfo(array $options = []) * * Example: * ``` - * echo $object->getName(); + * echo $object->name(); * ``` * * @return string */ - public function getName() + public function name() { return $this->identity['object']; } @@ -298,12 +332,12 @@ public function getName() * * Example: * ``` - * echo $object->getIdentity()['object']; + * echo $object->identity()['object']; * ``` * * @return string */ - public function getIdentity() + public function identity() { return $this->identity; } diff --git a/tests/BigQuery/BigQueryClientTest.php b/tests/BigQuery/BigQueryClientTest.php index bb332c3db4a6..dd9a612c42da 100644 --- a/tests/BigQuery/BigQueryClientTest.php +++ b/tests/BigQuery/BigQueryClientTest.php @@ -59,7 +59,7 @@ public function testRunsQuery() $queryResults = $this->client->runQuery('someQuery'); $this->assertInstanceOf(QueryResults::class, $queryResults); - $this->assertEquals($this->jobId, $queryResults->getIdentity()['jobId']); + $this->assertEquals($this->jobId, $queryResults->identity()['jobId']); } public function testRunsQueryAsJob() @@ -77,7 +77,7 @@ public function testRunsQueryAsJob() ]); $this->assertInstanceOf(Job::class, $job); - $this->assertEquals($this->jobId, $job->getId()); + $this->assertEquals($this->jobId, $job->id()); } public function testGetsJob() @@ -111,7 +111,7 @@ public function testGetsJobsWithoutToken() $this->client->setConnection($this->connection->reveal()); $jobs = iterator_to_array($this->client->jobs()); - $this->assertEquals($this->jobId, $jobs[0]->getId()); + $this->assertEquals($this->jobId, $jobs[0]->id()); } public function testGetsJobsWithToken() @@ -135,7 +135,7 @@ public function testGetsJobsWithToken() $this->client->setConnection($this->connection->reveal()); $job = iterator_to_array($this->client->jobs()); - $this->assertEquals($this->jobId, $job[1]->getId()); + $this->assertEquals($this->jobId, $job[1]->id()); } public function testGetsDataset() @@ -169,7 +169,7 @@ public function testGetsDatasetsWithoutToken() $this->client->setConnection($this->connection->reveal()); $datasets = iterator_to_array($this->client->datasets()); - $this->assertEquals($this->datasetId, $datasets[0]->getId()); + $this->assertEquals($this->datasetId, $datasets[0]->id()); } public function testGetsDatasetsWithToken() @@ -193,7 +193,7 @@ public function testGetsDatasetsWithToken() $this->client->setConnection($this->connection->reveal()); $dataset = iterator_to_array($this->client->datasets()); - $this->assertEquals($this->datasetId, $dataset[1]->getId()); + $this->assertEquals($this->datasetId, $dataset[1]->id()); } public function testCreatesDataset() diff --git a/tests/BigQuery/DatasetTest.php b/tests/BigQuery/DatasetTest.php index 5ceac9a3fd8d..c4a03ec05f9f 100644 --- a/tests/BigQuery/DatasetTest.php +++ b/tests/BigQuery/DatasetTest.php @@ -79,7 +79,7 @@ public function testUpdatesData() $dataset = $this->getDataset($this->connection, ['friendlyName' => 'another name']); $dataset->update($updateData); - $this->assertEquals($updateData['friendlyName'], $dataset->getInfo()['friendlyName']); + $this->assertEquals($updateData['friendlyName'], $dataset->info()['friendlyName']); } public function testGetsTable() @@ -113,7 +113,7 @@ public function testGetsTablesWithoutToken() $dataset = $this->getDataset($this->connection); $tables = iterator_to_array($dataset->tables()); - $this->assertEquals($this->tableId, $tables[0]->getId()); + $this->assertEquals($this->tableId, $tables[0]->id()); } public function testGetsTablesWithToken() @@ -137,7 +137,7 @@ public function testGetsTablesWithToken() $dataset = $this->getDataset($this->connection); $tables = iterator_to_array($dataset->tables()); - $this->assertEquals($this->tableId, $tables[1]->getId()); + $this->assertEquals($this->tableId, $tables[1]->id()); } public function testCreatesTable() @@ -166,7 +166,7 @@ public function testGetsInfo() $this->connection->getDataset(Argument::any())->shouldNotBeCalled(); $dataset = $this->getDataset($this->connection, $datasetInfo); - $this->assertEquals($datasetInfo, $dataset->getInfo()); + $this->assertEquals($datasetInfo, $dataset->info()); } public function testGetsInfoWithReload() @@ -177,21 +177,21 @@ public function testGetsInfoWithReload() ->shouldBeCalledTimes(1); $dataset = $this->getDataset($this->connection); - $this->assertEquals($datasetInfo, $dataset->getInfo()); + $this->assertEquals($datasetInfo, $dataset->info()); } public function testGetsId() { $dataset = $this->getDataset($this->connection); - $this->assertEquals($this->datasetId, $dataset->getId()); + $this->assertEquals($this->datasetId, $dataset->id()); } public function testGetsIdentity() { $dataset = $this->getDataset($this->connection); - $this->assertEquals($this->datasetId, $dataset->getIdentity()['datasetId']); - $this->assertEquals($this->projectId, $dataset->getIdentity()['projectId']); + $this->assertEquals($this->datasetId, $dataset->identity()['datasetId']); + $this->assertEquals($this->projectId, $dataset->identity()['projectId']); } } diff --git a/tests/BigQuery/JobTest.php b/tests/BigQuery/JobTest.php index c4eadeabb6ca..9e386eb149c5 100644 --- a/tests/BigQuery/JobTest.php +++ b/tests/BigQuery/JobTest.php @@ -78,7 +78,7 @@ public function testGetsQueryResults() ->shouldBeCalledTimes(1); $job = $this->getJob($this->connection); - $this->assertInstanceOf(QueryResults::class, $job->getQueryResults()); + $this->assertInstanceOf(QueryResults::class, $job->queryResults()); } public function testIsCompleteTrue() @@ -101,7 +101,7 @@ public function testGetsInfo() $this->connection->getJob(Argument::any())->shouldNotBeCalled(); $job = $this->getJob($this->connection, $this->jobInfo); - $this->assertEquals($this->jobInfo, $job->getInfo()); + $this->assertEquals($this->jobInfo, $job->info()); } public function testGetsInfoWithRealod() @@ -111,21 +111,21 @@ public function testGetsInfoWithRealod() ->shouldBeCalledTimes(1); $job = $this->getJob($this->connection); - $this->assertEquals($this->jobInfo, $job->getInfo()); + $this->assertEquals($this->jobInfo, $job->info()); } public function testGetsId() { $job = $this->getJob($this->connection); - $this->assertEquals($this->jobId, $job->getId()); + $this->assertEquals($this->jobId, $job->id()); } public function testGetsIdentity() { $job = $this->getJob($this->connection); - $this->assertEquals($this->jobId, $job->getIdentity()['jobId']); - $this->assertEquals($this->projectId, $job->getIdentity()['projectId']); + $this->assertEquals($this->jobId, $job->identity()['jobId']); + $this->assertEquals($this->projectId, $job->identity()['projectId']); } } diff --git a/tests/BigQuery/QueryResultsTest.php b/tests/BigQuery/QueryResultsTest.php index 9aaa4838b836..5783f91a279a 100644 --- a/tests/BigQuery/QueryResultsTest.php +++ b/tests/BigQuery/QueryResultsTest.php @@ -55,7 +55,7 @@ public function testGetsRowsThrowsExceptionWhenQueryNotComplete() unset($this->queryData['rows']); $this->connection->getQueryResults()->shouldNotBeCalled(); $queryResults = $this->getQueryResults($this->connection, $this->queryData); - $queryResults->getRows()->next(); + $queryResults->rows()->next(); } public function testGetsRowsWithNoResults() @@ -63,7 +63,7 @@ public function testGetsRowsWithNoResults() $this->connection->getQueryResults()->shouldNotBeCalled(); unset($this->queryData['rows']); $queryResults = $this->getQueryResults($this->connection, $this->queryData); - $rows = iterator_to_array($queryResults->getRows()); + $rows = iterator_to_array($queryResults->rows()); $this->assertEmpty($rows); } @@ -72,7 +72,7 @@ public function testGetsRowsWithoutToken() { $this->connection->getQueryResults()->shouldNotBeCalled(); $queryResults = $this->getQueryResults($this->connection, $this->queryData); - $rows = iterator_to_array($queryResults->getRows()); + $rows = iterator_to_array($queryResults->rows()); $this->assertEquals('Alton', $rows[0]['first_name']); } @@ -86,7 +86,7 @@ public function testGetsRowsWithToken() $this->connection, $this->queryData + ['pageToken' => 'abcd'] ); - $rows = iterator_to_array($queryResults->getRows()); + $rows = iterator_to_array($queryResults->rows()); $this->assertEquals('Alton', $rows[1]['first_name']); } @@ -110,7 +110,7 @@ public function testGetsInfo() { $queryResults = $this->getQueryResults($this->connection, $this->queryData); - $this->assertEquals($this->queryData, $queryResults->getInfo()); + $this->assertEquals($this->queryData, $queryResults->info()); } public function testReloadsInfo() @@ -127,7 +127,7 @@ public function testGetsIdentity() { $queryResults = $this->getQueryResults($this->connection); - $this->assertEquals($this->jobId, $queryResults->getIdentity()['jobId']); - $this->assertEquals($this->projectId, $queryResults->getIdentity()['projectId']); + $this->assertEquals($this->jobId, $queryResults->identity()['jobId']); + $this->assertEquals($this->projectId, $queryResults->identity()['projectId']); } } diff --git a/tests/BigQuery/TableTest.php b/tests/BigQuery/TableTest.php index 3f55cc1347f6..e88c509ec4c8 100644 --- a/tests/BigQuery/TableTest.php +++ b/tests/BigQuery/TableTest.php @@ -109,7 +109,7 @@ public function testGetsRowsWithNoResults() ->shouldBeCalledTimes(1); $table = $this->getTable($this->connection); - $rows = iterator_to_array($table->getRows()); + $rows = iterator_to_array($table->rows()); $this->assertEmpty($rows); } @@ -124,7 +124,7 @@ public function testGetsRowsWithoutToken() ->shouldBeCalledTimes(1); $table = $this->getTable($this->connection); - $rows = iterator_to_array($table->getRows()); + $rows = iterator_to_array($table->rows()); $this->assertEquals( $this->rowData['rows'][0]['f'][0]['v'], @@ -148,7 +148,7 @@ public function testGetsRowsWithToken() ->shouldBeCalledTimes(2); $table = $this->getTable($this->connection); - $rows = iterator_to_array($table->getRows()); + $rows = iterator_to_array($table->rows()); $this->assertEquals($name, $rows[1]['first_name']); } @@ -181,7 +181,7 @@ public function testRunsCopyJob() $job = $table->copy($destinationTable); $this->assertInstanceOf(Job::class, $job); - $this->assertEquals($this->insertJobResponse, $job->getInfo()); + $this->assertEquals($this->insertJobResponse, $job->info()); } public function testRunsExportJob() @@ -209,7 +209,7 @@ public function testRunsExportJob() $job = $table->export($destinationObject); $this->assertInstanceOf(Job::class, $job); - $this->assertEquals($this->insertJobResponse, $job->getInfo()); + $this->assertEquals($this->insertJobResponse, $job->info()); } public function testRunsLoadJob() @@ -239,7 +239,7 @@ public function testRunsLoadJob() $job = $table->load($data); $this->assertInstanceOf(Job::class, $job); - $this->assertEquals($this->insertJobResponse, $job->getInfo()); + $this->assertEquals($this->insertJobResponse, $job->info()); } public function testRunsLoadJobFromStorage() @@ -267,7 +267,7 @@ public function testRunsLoadJobFromStorage() $job = $table->loadFromStorage($sourceObject); $this->assertInstanceOf(Job::class, $job); - $this->assertEquals($this->insertJobResponse, $job->getInfo()); + $this->assertEquals($this->insertJobResponse, $job->info()); } public function testGetsInfo() @@ -276,7 +276,7 @@ public function testGetsInfo() $this->connection->getTable(Argument::any())->shouldNotBeCalled(); $table = $this->getTable($this->connection, $tableInfo); - $this->assertEquals($tableInfo, $table->getInfo()); + $this->assertEquals($tableInfo, $table->info()); } public function testGetsInfoWithReload() @@ -287,21 +287,21 @@ public function testGetsInfoWithReload() ->shouldBeCalledTimes(1); $table = $this->getTable($this->connection); - $this->assertEquals($tableInfo, $table->getInfo()); + $this->assertEquals($tableInfo, $table->info()); } public function testGetsId() { $table = $this->getTable($this->connection); - $this->assertEquals($this->tableId, $table->getId()); + $this->assertEquals($this->tableId, $table->id()); } public function testGetsIdentity() { $table = $this->getTable($this->connection); - $this->assertEquals($this->tableId, $table->getIdentity()['tableId']); - $this->assertEquals($this->projectId, $table->getIdentity()['projectId']); + $this->assertEquals($this->tableId, $table->identity()['tableId']); + $this->assertEquals($this->projectId, $table->identity()['projectId']); } } diff --git a/tests/Storage/BucketTest.php b/tests/Storage/BucketTest.php index 1d4ddc12a5ed..6d2d18af0ddb 100644 --- a/tests/Storage/BucketTest.php +++ b/tests/Storage/BucketTest.php @@ -137,7 +137,7 @@ public function testGetsObjectsWithoutToken() $bucket = new Bucket($this->connection->reveal(), 'bucket'); $objects = iterator_to_array($bucket->objects()); - $this->assertEquals('file.txt', $objects[0]->getName()); + $this->assertEquals('file.txt', $objects[0]->name()); } public function testGetsObjectsWithToken() @@ -159,7 +159,7 @@ public function testGetsObjectsWithToken() $bucket = new Bucket($this->connection->reveal(), 'bucket'); $objects = iterator_to_array($bucket->objects()); - $this->assertEquals('file2.txt', $objects[1]->getName()); + $this->assertEquals('file2.txt', $objects[1]->name()); } public function testDelete() @@ -186,7 +186,7 @@ public function testUpdatesData() $bucket->update($versioningData); - $this->assertTrue($bucket->getInfo()['versioning']['enabled']); + $this->assertTrue($bucket->info()['versioning']['enabled']); } public function testGetsInfo() @@ -198,7 +198,7 @@ public function testGetsInfo() ]; $bucket = new Bucket($this->connection->reveal(), 'bucket', $bucketInfo); - $this->assertEquals($bucketInfo, $bucket->getInfo()); + $this->assertEquals($bucketInfo, $bucket->info()); } public function testGetsInfoWithForce() @@ -208,16 +208,18 @@ public function testGetsInfoWithForce() 'etag' => 'ABC', 'kind' => 'storage#bucket' ]; - $this->connection->getBucket(Argument::any())->willReturn($bucketInfo); + $this->connection->getBucket(Argument::any()) + ->willReturn($bucketInfo) + ->shouldBeCalledTimes(1); $bucket = new Bucket($this->connection->reveal(), 'bucket'); - $this->assertEquals($bucketInfo, $bucket->getInfo(['force' => true])); + $this->assertEquals($bucketInfo, $bucket->info()); } public function testGetsName() { $bucket = new Bucket($this->connection->reveal(), $name = 'bucket'); - $this->assertEquals($name, $bucket->getName()); + $this->assertEquals($name, $bucket->name()); } } diff --git a/tests/Storage/ObjectTest.php b/tests/Storage/ObjectTest.php index 9c6bf58cebb3..ccb77e4691ff 100644 --- a/tests/Storage/ObjectTest.php +++ b/tests/Storage/ObjectTest.php @@ -69,7 +69,7 @@ public function testUpdatesData() $object->update($data); - $this->assertEquals($data['contentType'], $object->getInfo()['contentType']); + $this->assertEquals($data['contentType'], $object->info()['contentType']); } public function testDownloadsAsString() @@ -102,10 +102,10 @@ public function testGetsInfo() ]; $object = new Object($this->connection->reveal(), 'object.txt', 'bucket', null, $objectInfo); - $this->assertEquals($objectInfo, $object->getInfo()); + $this->assertEquals($objectInfo, $object->info()); } - public function testGetsInfoWithForce() + public function testGetsInfoWithReload() { $objectInfo = [ 'name' => 'object.txt', @@ -113,24 +113,26 @@ public function testGetsInfoWithForce() 'etag' => 'ABC', 'kind' => 'storage#object' ]; - $this->connection->getObject(Argument::any())->willReturn($objectInfo); - $object = new Object($this->connection->reveal(), 'object.txt', 'bucket', null, $objectInfo); + $this->connection->getObject(Argument::any()) + ->willReturn($objectInfo) + ->shouldBeCalledTimes(1); + $object = new Object($this->connection->reveal(), 'object.txt', 'bucket'); - $this->assertEquals($objectInfo, $object->getInfo(['force' => true])); + $this->assertEquals($objectInfo, $object->info()); } public function testGetsName() { $object = new Object($this->connection->reveal(), $name = 'object.txt', 'bucket'); - $this->assertEquals($name, $object->getName()); + $this->assertEquals($name, $object->name()); } public function testGetsIdentity() { $object = new Object($this->connection->reveal(), $name = 'object.txt', $bucketName = 'bucket'); - $this->assertEquals($name, $object->getIdentity()['object']); - $this->assertEquals($bucketName, $object->getIdentity()['bucket']); + $this->assertEquals($name, $object->identity()['object']); + $this->assertEquals($bucketName, $object->identity()['bucket']); } } diff --git a/tests/Storage/StorageClientTest.php b/tests/Storage/StorageClientTest.php index f8a04614afbe..4657ac574c36 100644 --- a/tests/Storage/StorageClientTest.php +++ b/tests/Storage/StorageClientTest.php @@ -47,7 +47,7 @@ public function testGetsBucketsWithoutToken() $this->client->setConnection($this->connection->reveal()); $buckets = iterator_to_array($this->client->buckets()); - $this->assertEquals('bucket1', $buckets[0]->getName()); + $this->assertEquals('bucket1', $buckets[0]->name()); } public function testGetsBucketsWithToken() @@ -69,7 +69,7 @@ public function testGetsBucketsWithToken() $this->client->setConnection($this->connection->reveal()); $bucket = iterator_to_array($this->client->buckets()); - $this->assertEquals('bucket2', $bucket[1]->getName()); + $this->assertEquals('bucket2', $bucket[1]->name()); } public function testCreatesBucket()