Skip to content

Commit

Permalink
Refactored tests (#769)
Browse files Browse the repository at this point in the history
* Refactored tests

* Use assertLessThanOrEqual or assertGreaterThanOrEqual

* Use assertContains and assertNotContains when comparing string

* Use assertStringEqualsFile when comparing file and string

* Use assertInternalType when checking types

* Use assertContains instead in_array

* Use assertInstanceOf
  • Loading branch information
carusogabriel authored and jdpedrie committed Dec 4, 2017
1 parent 288c3da commit 385e3ef
Show file tree
Hide file tree
Showing 50 changed files with 165 additions and 165 deletions.
4 changes: 2 additions & 2 deletions tests/snippets/Core/Iam/PolicyBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testClass()
$snippet = $this->snippetFromClass(PolicyBuilder::class);
$res = $snippet->invoke('result');

$this->assertTrue(is_array($res->returnVal()));
$this->assertInternalType('array', $res->returnVal());
}

public function testSetBindings()
Expand Down Expand Up @@ -97,6 +97,6 @@ public function testResult()
$snippet->addLocal('builder', $this->pb);

$res = $snippet->invoke('policy');
$this->assertTrue(is_array($res->returnVal()));
$this->assertInternalType('array', $res->returnVal());
}
}
4 changes: 2 additions & 2 deletions tests/snippets/Datastore/DatastoreClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testKeys()
$snippet->addLocal('datastore', $this->client);

$res = $snippet->invoke('keys');
$this->assertTrue(is_array($res->returnVal()));
$this->assertInternalType('array', $res->returnVal());
$this->assertEquals(10, count($res->returnVal()));
$this->assertInstanceOf(Key::class, $res->returnVal()[0]);
$this->assertEquals('Person', $res->returnVal()[0]->keyObject()['path'][0]['kind']);
Expand All @@ -144,7 +144,7 @@ public function testKeysWithAncestors()

$res = $snippet->invoke('keys');

$this->assertTrue(is_array($res->returnVal()));
$this->assertInternalType('array', $res->returnVal());
$this->assertEquals(3, count($res->returnVal()));
$this->assertInstanceOf(Key::class, $res->returnVal()[0]);

Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/PubSub/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ public function testInfo()
$snippet->addLocal('message', $this->message);

$res = $snippet->invoke('info');
$this->assertTrue(is_array($res->returnVal()));
$this->assertInternalType('array', $res->returnVal());
}
}
4 changes: 2 additions & 2 deletions tests/snippets/Spanner/KeySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testAddKey()
$this->assertEmpty($this->keyset->keys());

$res = $snippet->invoke();
$this->assertEquals(1, count($this->keyset->keys()));
$this->assertCount(1, $this->keyset->keys());
}

public function testSetKeys()
Expand All @@ -110,7 +110,7 @@ public function testSetKeys()
$this->assertEmpty($this->keyset->keys());

$res = $snippet->invoke();
$this->assertEquals(2, count($this->keyset->keys()));
$this->assertCount(2, $this->keyset->keys());
}

public function testMatchAll()
Expand Down
18 changes: 9 additions & 9 deletions tests/snippets/Storage/StorageObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ public function testSignedUrl()
$this->object->___setProperty('connection', $conn->reveal());

$res = $snippet->invoke('url');
$this->assertTrue(strpos($res->returnVal(), 'https://storage.googleapis.com/my-bucket/my-object') !== false);
$this->assertTrue(strpos($res->returnVal(), 'Expires=') !== false);
$this->assertTrue(strpos($res->returnVal(), 'Signature=') !== false);
$this->assertContains('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal());
$this->assertContains('Expires=', $res->returnVal());
$this->assertContains('Signature=', $res->returnVal());
}

public function testSignedUrlUpdate()
Expand All @@ -414,9 +414,9 @@ public function testSignedUrlUpdate()
$this->object->___setProperty('connection', $conn->reveal());

$res = $snippet->invoke('url');
$this->assertTrue(strpos($res->returnVal(), 'https://storage.googleapis.com/my-bucket/my-object') !== false);
$this->assertTrue(strpos($res->returnVal(), 'Expires=') !== false);
$this->assertTrue(strpos($res->returnVal(), 'Signature=') !== false);
$this->assertContains('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal());
$this->assertContains('Expires=', $res->returnVal());
$this->assertContains('Signature=', $res->returnVal());
}

public function testSignedUploadUrl()
Expand All @@ -440,9 +440,9 @@ public function testSignedUploadUrl()
$this->object->___setProperty('connection', $conn->reveal());

$res = $snippet->invoke('url');
$this->assertTrue(strpos($res->returnVal(), 'https://storage.googleapis.com/my-bucket/my-object') !== false);
$this->assertTrue(strpos($res->returnVal(), 'Expires=') !== false);
$this->assertTrue(strpos($res->returnVal(), 'Signature=') !== false);
$this->assertContains('https://storage.googleapis.com/my-bucket/my-object', $res->returnVal());
$this->assertContains('Expires=', $res->returnVal());
$this->assertContains('Signature=', $res->returnVal());
}

public function testBeginSignedUploadSession()
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/Vision/AnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ public function testError()
]));

$res = $snippet->invoke('error');
$this->assertTrue(is_array($res->returnVal()));
$this->assertInternalType('array', $res->returnVal());
}
}
4 changes: 2 additions & 2 deletions tests/system/Datastore/AllocateKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testAllocateId()
$key = self::$client->key($kind);
$path = self::$client->allocateId($key)->path()[0];

$this->assertTrue(is_numeric($path['id']));
$this->assertInternalType('numeric', $path['id']);
$this->assertEquals($kind, $path['kind']);
}

Expand All @@ -41,7 +41,7 @@ public function testAllocateIds()

foreach ($allocatedKeys as $key) {
$path = $key->path()[0];
$this->assertTrue(is_numeric($path['id']));
$this->assertInternalType('numeric', $path['id']);
$this->assertEquals($kind, $path['kind']);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/system/ServiceWhitelist/WhitelistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ private function checkException(callable $call)

$this->assertTrue($thrown);
$this->assertInstanceOf(NotFoundException::class, $ex);
$this->assertTrue(strpos($ex->getMessage(), self::MESSAGE) !== false);
$this->assertContains(self::MESSAGE, $ex->getMessage());
}
}
56 changes: 28 additions & 28 deletions tests/system/Spanner/ReadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function testRangeReadSingleKeyOpen()

$res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0]));
$rows = iterator_to_array($res->rows());
$this->assertFalse(in_array(self::$dataset[0], $rows));
$this->assertFalse(in_array(self::$dataset[10], $rows));
$this->assertNotContains(self::$dataset[0], $rows);
$this->assertNotContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -106,8 +106,8 @@ public function testRangeReadSingleKeyClosed()

$res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0]));
$rows = iterator_to_array($res->rows());
$this->assertTrue(in_array(self::$dataset[0], $rows));
$this->assertTrue(in_array(self::$dataset[10], $rows));
$this->assertContains(self::$dataset[0], $rows);
$this->assertContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -127,8 +127,8 @@ public function testRangeReadSingleKeyOpenClosed()

$res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0]));
$rows = iterator_to_array($res->rows());
$this->assertFalse(in_array(self::$dataset[0], $rows));
$this->assertTrue(in_array(self::$dataset[10], $rows));
$this->assertNotContains(self::$dataset[0], $rows);
$this->assertContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -148,8 +148,8 @@ public function testRangeReadSingleKeyClosedOpen()

$res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0]));
$rows = iterator_to_array($res->rows());
$this->assertTrue(in_array(self::$dataset[0], $rows));
$this->assertFalse(in_array(self::$dataset[10], $rows));
$this->assertContains(self::$dataset[0], $rows);
$this->assertNotContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -168,8 +168,8 @@ public function testRangeReadPartialKeyOpen()

$res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0]));
$rows = iterator_to_array($res->rows());
$this->assertFalse(in_array(self::$dataset[0], $rows));
$this->assertFalse(in_array(self::$dataset[10], $rows));
$this->assertNotContains(self::$dataset[0], $rows);
$this->assertNotContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -190,8 +190,8 @@ public function testRangeReadPartialKeyClosed()

$res = $db->read(self::$rangeTableName, $keyset, array_keys(self::$dataset[0]));
$rows = iterator_to_array($res->rows());
$this->assertTrue(in_array(self::$dataset[0], $rows));
$this->assertTrue(in_array(self::$dataset[10], $rows));
$this->assertContains(self::$dataset[0], $rows);
$this->assertContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -212,8 +212,8 @@ public function testRangeReadIndexSingleKeyOpen()
'index' => $this->getIndexName(self::$rangeTableName, 'complex')
]);
$rows = iterator_to_array($res->rows());
$this->assertFalse(in_array(self::$dataset[0], $rows));
$this->assertFalse(in_array(self::$dataset[10], $rows));
$this->assertNotContains(self::$dataset[0], $rows);
$this->assertNotContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -236,8 +236,8 @@ public function testRangeReadIndexSingleKeyClosed()
'index' => $this->getIndexName(self::$rangeTableName, 'complex')
]);
$rows = iterator_to_array($res->rows());
$this->assertTrue(in_array(self::$dataset[0], $rows));
$this->assertTrue(in_array(self::$dataset[10], $rows));
$this->assertContains(self::$dataset[0], $rows);
$this->assertContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -259,8 +259,8 @@ public function testRangeReadIndexSingleKeyOpenClosed()
'index' => $this->getIndexName(self::$rangeTableName, 'complex')
]);
$rows = iterator_to_array($res->rows());
$this->assertFalse(in_array(self::$dataset[0], $rows));
$this->assertTrue(in_array(self::$dataset[10], $rows));
$this->assertNotContains(self::$dataset[0], $rows);
$this->assertContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -282,8 +282,8 @@ public function testRangeReadIndexSingleKeyClosedOpen()
'index' => $this->getIndexName(self::$rangeTableName, 'complex')
]);
$rows = iterator_to_array($res->rows());
$this->assertTrue(in_array(self::$dataset[0], $rows));
$this->assertFalse(in_array(self::$dataset[10], $rows));
$this->assertContains(self::$dataset[0], $rows);
$this->assertNotContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -304,8 +304,8 @@ public function testRangeReadIndexPartialKeyOpen()
'index' => $this->getIndexName(self::$rangeTableName, 'complex')
]);
$rows = iterator_to_array($res->rows());
$this->assertFalse(in_array(self::$dataset[0], $rows));
$this->assertFalse(in_array(self::$dataset[10], $rows));
$this->assertNotContains(self::$dataset[0], $rows);
$this->assertNotContains(self::$dataset[10], $rows);
}

/**
Expand All @@ -328,8 +328,8 @@ public function testRangeReadIndexPartialKeyClosed()
'index' => $this->getIndexName(self::$rangeTableName, 'complex')
]);
$rows = iterator_to_array($res->rows());
$this->assertTrue(in_array(self::$dataset[0], $rows));
$this->assertTrue(in_array(self::$dataset[10], $rows));
$this->assertContains(self::$dataset[0], $rows);
$this->assertContains(self::$dataset[10], $rows);
}

/**
Expand Down Expand Up @@ -398,8 +398,8 @@ public function testReadPoint()
$res = $db->read(self::$readTableName, $keyset, array_keys($dataset[0]));
$rows = $res->rows();
foreach ($rows as $index => $row) {
$this->assertTrue(in_array($row, $dataset));
$this->assertTrue(in_array($row, $points));
$this->assertContains($row, $dataset);
$this->assertContains($row, $points);
}
}

Expand Down Expand Up @@ -428,8 +428,8 @@ public function testReadPointOverIndex()
]);
$rows = $res->rows();
foreach ($rows as $index => $row) {
$this->assertTrue(in_array($row, $dataset));
$this->assertTrue(in_array($row, $points));
$this->assertContains($row, $dataset);
$this->assertContains($row, $points);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/system/Spanner/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testConcurrentTransactionsIncrementValueWithRead()
])->rows()->current();

$this->assertEquals(2, $row['number']);
$this->assertTrue($iterations > 2);
$this->assertGreaterThan(2, $iterations);
}

/**
Expand Down Expand Up @@ -194,7 +194,7 @@ public function testConcurrentTransactionsIncrementValueWithExecute()
])->rows()->current();

$this->assertEquals(2, $row['number']);
$this->assertTrue($iterations > 2);
$this->assertGreaterThan(2, $iterations);
}

public function testStrongRead()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Storage/ManageObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testDownloadsAsString()
{
$content = self::$object->downloadAsString();

$this->assertTrue(is_string($content));
$this->assertInternalType('string', $content);
}

public function testDownloadsAsStream()
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Storage/StreamWrapper/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public function testMkDir()
{
$dir = self::generateUrl('test_directory');
$this->assertTrue(mkdir($dir));
$this->assertTrue(file_exists($dir . '/'));
$this->assertFileExists($dir . '/');
$this->assertTrue(is_dir($dir . '/'));
}

public function testRmDir()
{
$dir = self::generateUrl('test_directory/');
$this->assertTrue(rmdir($dir));
$this->assertFalse(file_exists($dir . '/'));
$this->assertFileNotExists($dir . '/');
}

public function testMkDirCreatesBucket()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Storage/StreamWrapper/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testGetImageSizeWithInfo($image, $width, $height)
$size = getimagesize($url, $info);
$this->assertEquals($width, $size[0]);
$this->assertEquals($height, $size[1]);
$this->assertTrue(count(array_keys($info)) > 1);
$this->assertGreaterThan(1, array_keys($info));
}

public function imageProvider()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Storage/StreamWrapper/ReadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testFread()

public function testFileGetContents()
{
$this->assertEquals('somedata', file_get_contents($this->file));
$this->assertStringEqualsFile($this->file, 'somedata');
}

public function testGetLines()
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Storage/StreamWrapper/RenameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testRenameFile()
$oldFile = self::generateUrl(self::TEST_FILE);
$newFile = self::generateUrl(self::NEW_TEST_FILE);
$this->assertTrue(rename($oldFile, $newFile));
$this->assertTrue(file_exists($newFile));
$this->assertFileExists($newFile);
}

public function testRenameDirectory()
Expand All @@ -48,7 +48,7 @@ public function testRenameDirectory()
$newFolder = self::generateUrl('new_folder');
$newFile = $newFolder . '/bar.txt';
$this->assertTrue(rename($oldFolder, $newFolder));
$this->assertTrue(file_exists($newFile));
$this->assertFileExists($newFile);
}

}
4 changes: 2 additions & 2 deletions tests/system/Storage/StreamWrapper/UrlStatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function testIsReadable()

public function testFileExists()
{
$this->assertTrue(file_exists(self::$dirUrl));
$this->assertTrue(file_exists(self::$fileUrl));
$this->assertFileExists(self::$dirUrl);
$this->assertFileExists(self::$fileUrl);
}

public function testIsLink()
Expand Down
Loading

0 comments on commit 385e3ef

Please sign in to comment.