Skip to content

Commit acaa05a

Browse files
committed
Some improvements:
- Stricter comparisons in tests - Corrected a few typos - rewrote some assertions to be more clear (Use more specific assertions instead of always `assertTrue`) - use `::class` -
1 parent ff37415 commit acaa05a

9 files changed

+25
-26
lines changed

examples/customDocumentClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function findOneById($id)
203203
try {
204204
return $this->_documentHandler->getById($this->_collectionName, $id);
205205
} catch (ServerException $e) {
206-
if ($e->getServerMessage() == 'document not found') {
206+
if ($e->getServerMessage() === 'document not found') {
207207
return null;
208208
}
209209
throw $e;

tests/AqlUserFunctionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function testGetAQLFunctionsWithNamespaceFilter()
340340
}
341341

342342
/**
343-
* Unregister all AQL functions on a namespace.
343+
* Un-register all AQL functions on a namespace.
344344
*/
345345
public function testUnRegisterAQLFunctionsOnNamespace()
346346
{

tests/BatchTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public function testRemoveByKeysInBatch()
479479
$existing++;
480480
} catch(Exception $e) {}
481481

482-
static::assertTrue($existing == 0, 'Batch removeByKeys not removed all documents!');
482+
static::assertSame(0, $existing, 'Batch removeByKeys did not remove all documents!');
483483
}
484484

485485
public function testCollectionHandlerAllInBatch()
@@ -512,15 +512,15 @@ public function testCollectionHandlerAllInBatch()
512512
$results = $cursor->getAll();
513513

514514
static::assertInstanceOf(Cursor::class, $cursor);
515-
static::assertTrue(count($documentIds) == count($results));
515+
static::assertSame(count($documentIds), count($results));
516516

517517
foreach($results as $result) {
518518
static::assertTrue(isset($documentIds[$result->getId()]));
519519
static::assertEquals($documentIds[$result->getId()], $result);
520520
}
521521
}
522522

523-
public function testfirstExampleBatch()
523+
public function testFirstExampleBatch()
524524
{
525525
$connection = $this->connection;
526526
$collection = $this->collection;
@@ -535,7 +535,7 @@ public function testfirstExampleBatch()
535535

536536
$document = $this->collectionHandler->firstExample($collection->getName(), ['foo'=>'bar']);
537537

538-
static::assertTrue($document->getHandle() === $document1->getHandle());
538+
static::assertSame($document1->getHandle(), $document->getHandle());
539539

540540
try {
541541
$document = $this->collectionHandler->firstExample($collection->getName(), ['foo'=>'bam']);
@@ -559,10 +559,10 @@ public function testfirstExampleBatch()
559559

560560
$document = $part1->getProcessedResponse();
561561

562-
static::assertTrue($document->getHandle() === $document1->getHandle());
562+
static::assertSame($document1->getHandle(), $document->getHandle());
563563

564564
$document = $part2->getProcessedResponse();
565-
static::assertTrue($document === false);
565+
static::assertFalse($document);
566566
}
567567

568568
public function testByExampleBatch()
@@ -584,10 +584,10 @@ public function testByExampleBatch()
584584
$all2 = $this->collectionHandler->byExample($collection->getName(), ['you'=>'me'])->getAll();
585585
$all3 = $this->collectionHandler->byExample($collection->getName(), ['foo'=>'none'])->getAll();
586586

587-
static::assertTrue(count($all1) == 2);
588-
static::assertTrue(count($all2) == 1);
589-
static::assertTrue(count($all3) == 0);
590-
static::assertTrue(reset($all2)->getHandle() === $document1->getHandle());
587+
static::assertCount(2, $all1);
588+
static::assertCount(1, $all2);
589+
static::assertCount(0, $all3);
590+
static::assertSame(reset($all2)->getHandle(), $document1->getHandle());
591591

592592
// now do this in Batch
593593

@@ -608,10 +608,10 @@ public function testByExampleBatch()
608608
$all2 = $part2->getProcessedResponse()->getAll();
609609
$all3 = $part3->getProcessedResponse()->getAll();
610610

611-
static::assertTrue(count($all1) == 2);
612-
static::assertTrue(count($all2) == 1);
613-
static::assertTrue(count($all3) == 0);
614-
static::assertTrue(reset($all2)->getHandle() === $document1->getHandle());
611+
static::assertCount(2, $all1);
612+
static::assertCount(1, $all2);
613+
static::assertCount(0, $all3);
614+
static::assertSame(reset($all2)->getHandle(), $document1->getHandle());
615615
}
616616

617617
public function tearDown()

tests/DocumentExtendedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function setUp()
5252
public function testCreateDocumentWithWrongEncoding()
5353
{
5454
$documentHandler = $this->documentHandler;
55-
$isoKey = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', 'someWrongEncododedAttribute');
55+
$isoKey = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', 'someWrongEncodedAttribute');
5656
$isoValue = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', 'someWrongEncodedValueü');
5757

5858
$document = Document::createFromArray([$isoKey => $isoValue, 'someOtherAttribute' => 'someOtherValue']);

tests/EdgeBasicTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ public function testGetAllIds()
546546

547547
static::assertCount(3, $result);
548548

549-
static::assertTrue(in_array($edgeDocument1, $result));
550-
static::assertTrue(in_array($edgeDocument2, $result));
551-
static::assertTrue(in_array($edgeDocument3, $result));
549+
static::assertTrue(in_array($edgeDocument1, $result, true));
550+
static::assertTrue(in_array($edgeDocument2, $result, true));
551+
static::assertTrue(in_array($edgeDocument3, $result, true));
552552
}
553553

554554
/**

tests/EdgeExtendedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function testReplaceEdgeWithWrongEncoding()
383383
static::assertTrue(is_numeric($edgeId), 'Did not return an id!');
384384

385385
// inject wrong encoding
386-
$isoKey = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', 'someWrongEncododedAttribute');
386+
$isoKey = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', 'someWrongEncodedAttribute');
387387
$isoValue = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', 'someWrongEncodedValueü');
388388

389389
$edge->set($isoKey, $isoValue);

tests/TransactionTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,8 @@ function () {
381381
}
382382
$details = $e->getDetails();
383383

384-
static::assertTrue(
385-
$e->getCode() === 500,
386-
'Did not return code 500, instead returned: ' . $e->getCode() . ' and ' . $details['errorMessage']
384+
static::assertSame(
385+
500, $e->getCode(), 'Did not return code 500, instead returned: ' . $e->getCode() . ' and ' . $details['errorMessage']
387386
);
388387
}
389388

tests/bootstrap-connection-close.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
require __DIR__ . '/../autoload.php';
1313

14-
if (class_exists('\PHPUnit\Framework\TestCase')) {
14+
if (class_exists(\PHPUnit\Framework\TestCase::class)) {
1515
@class_alias(\PHPUnit\Framework\TestCase::class, 'PHPUnit_Framework_TestCase');
1616
}
1717

tests/bootstrap-connection-keep-alive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
require __DIR__ . '/../autoload.php';
1313

14-
if (class_exists('\PHPUnit\Framework\TestCase')) {
14+
if (class_exists(\PHPUnit\Framework\TestCase::class)) {
1515
@class_alias(\PHPUnit\Framework\TestCase::class, 'PHPUnit_Framework_TestCase');
1616
}
1717

0 commit comments

Comments
 (0)