Skip to content

Commit

Permalink
DX PHPUnit - use dedicated assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Nov 12, 2017
1 parent 0eed145 commit ff023ed
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions tests/TestCase/Cache/Engine/FileEngineTest.php
Expand Up @@ -418,7 +418,7 @@ public function testPathDoesNotExist()
]);

Cache::read('Test', 'file_test');
$this->assertTrue(file_exists($dir), 'Dir should exist.');
$this->assertFileExists($dir, 'Dir should exist.');

// Cleanup
rmdir($dir);
Expand All @@ -441,7 +441,7 @@ public function testPathDoesNotExistDebugOff()
]);

Cache::read('Test', 'file_test');
$this->assertTrue(file_exists($dir), 'Dir should exist.');
$this->assertFileExists($dir, 'Dir should exist.');

// Cleanup
rmdir($dir);
Expand Down
Expand Up @@ -488,8 +488,8 @@ public function testStartupCallback()
$_SERVER['CONTENT_TYPE'] = 'application/xml';
$this->Controller->request = new ServerRequest();
$this->RequestHandler->beforeRender($event);
$this->assertTrue(is_array($this->Controller->request->data));
$this->assertFalse(is_object($this->Controller->request->data));
$this->assertInternalType('array', $this->Controller->request->data);
$this->assertNotInternalType('object', $this->Controller->request->data);
}

/**
Expand All @@ -505,8 +505,8 @@ public function testStartupCallbackCharset()
$_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8';
$this->Controller->request = new ServerRequest();
$this->RequestHandler->startup($event);
$this->assertTrue(is_array($this->Controller->request->data));
$this->assertFalse(is_object($this->Controller->request->data));
$this->assertInternalType('array', $this->Controller->request->data);
$this->assertNotInternalType('object', $this->Controller->request->data);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Core/ConfigureTest.php
Expand Up @@ -111,7 +111,7 @@ public function testRead()
$this->assertTrue($result >= 0);

$result = Configure::read();
$this->assertTrue(is_array($result));
$this->assertInternalType('array', $result);
$this->assertTrue(isset($result['debug']));
$this->assertTrue(isset($result['level1']));

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Error/DebuggerTest.php
Expand Up @@ -103,12 +103,12 @@ public function testDocRef()
public function testExcerpt()
{
$result = Debugger::excerpt(__FILE__, __LINE__ - 1, 2);
$this->assertTrue(is_array($result));
$this->assertInternalType('array', $result);
$this->assertCount(5, $result);
$this->assertRegExp('/function(.+)testExcerpt/', $result[1]);

$result = Debugger::excerpt(__FILE__, 2, 2);
$this->assertTrue(is_array($result));
$this->assertInternalType('array', $result);
$this->assertCount(4, $result);

$this->skipIf(defined('HHVM_VERSION'), 'HHVM does not highlight php code');
Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/Filesystem/FileTest.php
Expand Up @@ -195,7 +195,7 @@ public function testRead()
$expecting = substr($data, 0, 3);
$result = $this->File->read(3);
$this->assertEquals($expecting, $result);
$this->assertTrue(is_resource($this->File->handle));
$this->assertInternalType('resource', $this->File->handle);

$expecting = substr($data, 3, 3);
$result = $this->File->read(3);
Expand All @@ -214,10 +214,10 @@ public function testOffset()
$result = $this->File->offset();
$this->assertFalse($result);

$this->assertFalse(is_resource($this->File->handle));
$this->assertNotInternalType('resource', $this->File->handle);
$success = $this->File->offset(0);
$this->assertTrue($success);
$this->assertTrue(is_resource($this->File->handle));
$this->assertInternalType('resource', $this->File->handle);

$result = $this->File->offset();
$expected = 0;
Expand Down Expand Up @@ -245,19 +245,19 @@ public function testOpen()
$this->File->handle = null;

$r = $this->File->open();
$this->assertTrue(is_resource($this->File->handle));
$this->assertInternalType('resource', $this->File->handle);
$this->assertTrue($r);

$handle = $this->File->handle;
$r = $this->File->open();
$this->assertTrue($r);
$this->assertTrue($handle === $this->File->handle);
$this->assertTrue(is_resource($this->File->handle));
$this->assertInternalType('resource', $this->File->handle);

$r = $this->File->open('r', true);
$this->assertTrue($r);
$this->assertFalse($handle === $this->File->handle);
$this->assertTrue(is_resource($this->File->handle));
$this->assertInternalType('resource', $this->File->handle);
}

/**
Expand All @@ -268,12 +268,12 @@ public function testOpen()
public function testClose()
{
$this->File->handle = null;
$this->assertFalse(is_resource($this->File->handle));
$this->assertNotInternalType('resource', $this->File->handle);
$this->assertTrue($this->File->close());
$this->assertFalse(is_resource($this->File->handle));
$this->assertNotInternalType('resource', $this->File->handle);

$this->File->handle = fopen(__FILE__, 'r');
$this->assertTrue(is_resource($this->File->handle));
$this->assertInternalType('resource', $this->File->handle);
$this->assertTrue($this->File->close());
$this->assertFalse(is_resource($this->File->handle));
}
Expand Down Expand Up @@ -435,15 +435,15 @@ public function testWrite()

$TmpFile = new File($tmpFile);
$this->assertFileNotExists($tmpFile);
$this->assertFalse(is_resource($TmpFile->handle));
$this->assertNotInternalType('resource', $TmpFile->handle);

$testData = ['CakePHP\'s', ' test suite', ' was here ...', ''];
foreach ($testData as $data) {
$r = $TmpFile->write($data);
$this->assertTrue($r);
$this->assertFileExists($tmpFile);
$this->assertEquals($data, file_get_contents($tmpFile));
$this->assertTrue(is_resource($TmpFile->handle));
$this->assertInternalType('resource', $TmpFile->handle);
$TmpFile->close();
}
unlink($tmpFile);
Expand Down
18 changes: 9 additions & 9 deletions tests/TestCase/Filesystem/FolderTest.php
Expand Up @@ -211,7 +211,7 @@ public function testCreateWithTrailingDs()
$result = $Folder->create($path);
$this->assertTrue($result);

$this->assertTrue(is_dir($path), 'Folder was not made');
$this->assertDirectoryExists($path, 'Folder was not made');

$Folder = new Folder(TMP . 'tests' . DS . 'trailing');
$this->assertTrue($Folder->delete());
Expand All @@ -229,7 +229,7 @@ public function testCreateRelative()
$result = $folder->create('tests' . DS . 'relative-test');
$this->assertTrue($result, 'should create');

$this->assertTrue(is_dir($path), 'Folder was not made');
$this->assertDirectoryExists($path, 'Folder was not made');
$folder = new Folder($path);
$folder->delete();
}
Expand Down Expand Up @@ -855,7 +855,7 @@ public function testConstructWithNonExistentPath()
{
$path = TMP . 'tests' . DS;
$Folder = new Folder($path . 'config_non_existent', true);
$this->assertTrue(is_dir($path . 'config_non_existent'));
$this->assertDirectoryExists($path . 'config_non_existent');
$Folder->cd($path);
}

Expand Down Expand Up @@ -1142,7 +1142,7 @@ public function testCopyWithoutRecursive()
$result = $Folder->copy(['to' => $folderThree, 'recursive' => false]);

$this->assertFileExists($folderThree . DS . 'file1.php');
$this->assertFalse(is_dir($folderThree . DS . 'folderA'));
$this->assertDirectoryNotExists($folderThree . DS . 'folderA');
$this->assertFileNotExists($folderThree . DS . 'folderA' . DS . 'fileA.php');
}

Expand Down Expand Up @@ -1215,7 +1215,7 @@ public function testMove()
$result = $Folder->move($folderTwo);
$this->assertTrue($result);
$this->assertFileExists($folderTwo . '/file1.php');
$this->assertTrue(is_dir($folderTwo . '/folderB'));
$this->assertDirectoryExists($folderTwo . '/folderB');
$this->assertFileExists($folderTwo . '/folderB/fileB.php');
$this->assertFileNotExists($fileOne);
$this->assertFileExists($folderTwo . '/folderA');
Expand All @@ -1234,7 +1234,7 @@ public function testMove()
$result = $Folder->move($folderTwo);
$this->assertTrue($result);
$this->assertFileExists($folderTwo . '/file1.php');
$this->assertTrue(is_dir($folderTwo . '/folderA'));
$this->assertDirectoryExists($folderTwo . '/folderA');
$this->assertFileExists($folderTwo . '/folderA/fileA.php');
$this->assertFileNotExists($fileOne);
$this->assertFileNotExists($folderOneA);
Expand Down Expand Up @@ -1284,7 +1284,7 @@ public function testMoveWithSkip()
$result = $Folder->move(['to' => $folderTwo, 'scheme' => Folder::SKIP]);
$this->assertTrue($result);
$this->assertFileExists($folderTwo . '/file1.php');
$this->assertTrue(is_dir($folderTwo . '/folderB'));
$this->assertDirectoryExists($folderTwo . '/folderB');
$this->assertFileExists($folderTwoB . '/fileB.php');
$this->assertFileNotExists($fileOne);
$this->assertFileNotExists($folderOneA);
Expand All @@ -1303,7 +1303,7 @@ public function testMoveWithSkip()
$result = $Folder->move(['to' => $folderTwo, 'scheme' => Folder::SKIP]);
$this->assertTrue($result);
$this->assertFileExists($folderTwo . '/file1.php');
$this->assertTrue(is_dir($folderTwo . '/folderA'));
$this->assertDirectoryExists($folderTwo . '/folderA');
$this->assertFileExists($folderTwo . '/folderA/fileA.php');
$this->assertFileNotExists($fileOne);
$this->assertFileNotExists($folderOneA);
Expand Down Expand Up @@ -1341,7 +1341,7 @@ public function testMoveWithoutRecursive()
$result = $Folder->move(['to' => $folderTwo, 'recursive' => false]);
$this->assertTrue($result);
$this->assertFileExists($folderTwo . '/file1.php');
$this->assertFalse(is_dir($folderTwo . '/folderA'));
$this->assertDirectoryNotExists($folderTwo . '/folderA');
$this->assertFileNotExists($folderTwo . '/folderA/fileA.php');
}

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Http/Client/Adapter/StreamTest.php
Expand Up @@ -297,7 +297,7 @@ public function testSendContextSsl()
foreach ($expected as $k => $v) {
$this->assertEquals($v, $result[$k]);
}
$this->assertTrue(is_readable($result['cafile']));
$this->assertIsReadable($result['cafile']);
}

/**
Expand Down Expand Up @@ -333,7 +333,7 @@ public function testSendContextSslNoVerifyPeerName()
foreach ($expected as $k => $v) {
$this->assertEquals($v, $result[$k]);
}
$this->assertTrue(is_readable($result['cafile']));
$this->assertIsReadable($result['cafile']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Http/Client/ResponseTest.php
Expand Up @@ -134,7 +134,7 @@ public function testBodyJson()

$data = json_encode([]);
$response = new Response([], $data);
$this->assertTrue(is_array($response->json));
$this->assertInternalType('array', $response->json);

$data = json_encode(null);
$response = new Response([], $data);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Http/ServerRequestTest.php
Expand Up @@ -1139,7 +1139,7 @@ public function testMagicisset()

$this->assertTrue(isset($request->controller));
$this->assertFalse(isset($request->notthere));
$this->assertFalse(empty($request->controller));
$this->assertNotEmpty($request->controller);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Mailer/EmailTest.php
Expand Up @@ -1890,7 +1890,7 @@ public function testSendMultipleMIME()

$message = $this->Email->message();
$boundary = $this->Email->getBoundary();
$this->assertFalse(empty($boundary));
$this->assertNotEmpty($boundary);
$this->assertContains('--' . $boundary, $message);
$this->assertContains('--' . $boundary . '--', $message);

Expand All @@ -1899,7 +1899,7 @@ public function testSendMultipleMIME()

$message = $this->Email->message();
$boundary = $this->Email->getBoundary();
$this->assertFalse(empty($boundary));
$this->assertNotEmpty($boundary);
$this->assertContains('--' . $boundary, $message);
$this->assertContains('--' . $boundary . '--', $message);
$this->assertContains('--alt-' . $boundary, $message);
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -6094,7 +6094,7 @@ public function testCallbackArgumentTypes()
$table->association('authors')->target()->getEventManager()->on(
'Model.beforeFind',
function (Event $event, Query $query, ArrayObject $options, $primary) use (&$associationBeforeFindCount) {
$this->assertTrue(is_bool($primary));
$this->assertInternalType('bool', $primary);
$associationBeforeFindCount ++;
}
);
Expand All @@ -6103,7 +6103,7 @@ function (Event $event, Query $query, ArrayObject $options, $primary) use (&$ass
$eventManager->on(
'Model.beforeFind',
function (Event $event, Query $query, ArrayObject $options, $primary) use (&$beforeFindCount) {
$this->assertTrue(is_bool($primary));
$this->assertInternalType('bool', $primary);
$beforeFindCount ++;
}
);
Expand All @@ -6115,7 +6115,7 @@ function (Event $event, Query $query, ArrayObject $options, $primary) use (&$bef
$eventManager->on(
'Model.buildValidator',
$callback = function (Event $event, Validator $validator, $name) use (&$buildValidatorCount) {
$this->assertTrue(is_string($name));
$this->assertInternalType('string', $name);
$buildValidatorCount ++;
}
);
Expand All @@ -6136,15 +6136,15 @@ function (Event $event, RulesChecker $rules) use (&$buildRulesCount) {
$eventManager->on(
'Model.beforeRules',
function (Event $event, Entity $entity, ArrayObject $options, $operation) use (&$beforeRulesCount) {
$this->assertTrue(is_string($operation));
$this->assertInternalType('string', $operation);
$beforeRulesCount ++;
}
);
$eventManager->on(
'Model.afterRules',
function (Event $event, Entity $entity, ArrayObject $options, $result, $operation) use (&$afterRulesCount) {
$this->assertTrue(is_bool($result));
$this->assertTrue(is_string($operation));
$this->assertInternalType('bool', $result);
$this->assertInternalType('string', $operation);
$afterRulesCount ++;
}
);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/Task/AssetsTaskTest.php
Expand Up @@ -133,7 +133,7 @@ public function testSymlinkWhenTargetAlreadyExits()
->setConstructorArgs([$this->io])
->getMock();

$this->assertTrue(is_dir(WWW_ROOT . 'test_theme'));
$this->assertDirectoryExists(WWW_ROOT . 'test_theme');

$shell->expects($this->never())->method('_createSymlink');
$shell->expects($this->never())->method('_copyDirectory');
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/ViewVarsTraitTest.php
Expand Up @@ -159,7 +159,7 @@ public function testUndefinedValidViewOptions()
{
$result = $this->subject->viewOptions([], false);

$this->assertTrue(is_array($result));
$this->assertInternalType('array', $result);
$this->assertEmpty($result);
}

Expand Down

0 comments on commit ff023ed

Please sign in to comment.