Skip to content

Commit a25f2b8

Browse files
authored
chore(firestore): fix risky tests (GoogleCloudPlatform#1221)
1 parent a1e6bee commit a25f2b8

File tree

7 files changed

+27
-3
lines changed

7 files changed

+27
-3
lines changed

firestore/src/collection_ref.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ function collection_ref($projectId)
4040
# [START fs_collection_ref]
4141
$collection = $db->collection('users');
4242
# [END fs_collection_ref]
43+
printf('Retrieved collection: %s' . PHP_EOL, $collection->name());
4344
}

firestore/src/document_path_ref.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ function document_path_ref($projectId)
4040
# [START fs_document_path_ref]
4141
$document = $db->document('users/lovelace');
4242
# [END fs_document_path_ref]
43+
printf('Retrieved document from path: %s' . PHP_EOL, $document->name());
4344
}

firestore/src/document_ref.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ function document_ref($projectId)
4040
# [START fs_document_ref]
4141
$document = $db->collection('users')->document('lovelace');
4242
# [END fs_document_ref]
43+
printf('Retrieved document: %s' . PHP_EOL, $document->name());
4344
}

firestore/src/invalid_range_order_by_query.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ function invalid_range_order_by_query($projectId)
3939
]);
4040
$citiesRef = $db->collection('cities');
4141
# [START fs_invalid_range_order_by_query]
42-
$query = $citiesRef
42+
$invalidRangeQuery = $citiesRef
4343
->where('population', '>', 2500000)
4444
->orderBy('country');
4545
# [END fs_invalid_range_order_by_query]
46+
47+
// This will throw an exception
48+
$invalidRangeQuery->documents();
4649
}

firestore/src/invalid_range_query.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ function invalid_range_query($projectId)
4343
->where('state', '>=', 'CA')
4444
->where('population', '>', 1000000);
4545
# [END fs_invalid_range_query]
46+
47+
// This will throw an exception
48+
$invalidRangeQuery->documents();
4649
}

firestore/src/subcollection_ref.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ function subcollection_ref($projectId)
4444
->collection('messages')
4545
->document('message1');
4646
# [END fs_subcollection_ref]
47+
printf('Retrieved document from subcollection: %s' . PHP_EOL, $document->name());
4748
}

firestore/test/firestoreTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Google\Cloud\Firestore\FirestoreClient;
2121
use Google\Cloud\TestUtils\TestTrait;
2222
use Google\Cloud\TestUtils\ExecuteCommandTrait;
23+
use Google\Cloud\Core\Exception\BadRequestException;
2324
use PHPUnit\Framework\TestCase;
2425

2526
/**
@@ -246,7 +247,11 @@ public function testRangeQuery()
246247
*/
247248
public function testInvalidRangeQuery()
248249
{
249-
$output = $this->runFirestoreCommand('invalid-range-query');
250+
$this->expectException(BadRequestException::class);
251+
$this->expectExceptionMessage(
252+
'Cannot have inequality filters on multiple properties'
253+
);
254+
$this->runFirestoreCommand('invalid-range-query');
250255
}
251256

252257
/**
@@ -426,27 +431,35 @@ public function testRangeOrderByQuery()
426431
*/
427432
public function testInvalidRangeOrderByQuery()
428433
{
429-
$output = $this->runFirestoreCommand('invalid-range-order-by-query');
434+
$this->expectException(BadRequestException::class);
435+
$this->expectExceptionMessage(
436+
'inequality filter property and first sort order must be the same'
437+
);
438+
$this->runFirestoreCommand('invalid-range-order-by-query');
430439
}
431440

432441
public function testDocumentRef()
433442
{
434443
$output = $this->runFirestoreCommand('document-ref');
444+
$this->assertContains('Retrieved document: ', $output);
435445
}
436446

437447
public function testCollectionRef()
438448
{
439449
$output = $this->runFirestoreCommand('collection-ref');
450+
$this->assertContains('Retrieved collection: ', $output);
440451
}
441452

442453
public function testDocumentPathRef()
443454
{
444455
$output = $this->runFirestoreCommand('document-path-ref');
456+
$this->assertContains('Retrieved document from path: ', $output);
445457
}
446458

447459
public function testSubcollectionRef()
448460
{
449461
$output = $this->runFirestoreCommand('subcollection-ref');
462+
$this->assertContains('Retrieved document from subcollection: ', $output);
450463
}
451464

452465
/**
@@ -568,6 +581,7 @@ public function testPaginatedQueryCursor()
568581
public function testMultipleCursorConditions()
569582
{
570583
$output = $this->runFirestoreCommand('multiple-cursor-conditions');
584+
$this->assertContains('Document TOK returned by start at ', $output);
571585
}
572586

573587
private static function runFirestoreCommand($commandName)

0 commit comments

Comments
 (0)