Skip to content
Permalink
Browse files

DX PHPUnit - use dedicated assertions

  • Loading branch information...
keradus committed Nov 12, 2017
1 parent 0eed145 commit ff023ed24e95b96415d78a54da8d7bf8b87c5201
@@ -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);
@@ -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);
@@ -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);
}
/**
@@ -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);
}
/**
@@ -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']));
@@ -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');
@@ -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);
@@ -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;
@@ -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);
}
/**
@@ -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));
}
@@ -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);
@@ -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());
@@ -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();
}
@@ -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);
}
@@ -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');
}
@@ -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');
@@ -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);
@@ -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);
@@ -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);
@@ -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');
}
@@ -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']);
}
/**
@@ -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']);
}
/**
@@ -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);
@@ -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);
}
/**
@@ -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);
@@ -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);
@@ -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 ++;
}
);
@@ -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 ++;
}
);
@@ -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 ++;
}
);
@@ -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 ++;
}
);
@@ -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');
@@ -159,7 +159,7 @@ public function testUndefinedValidViewOptions()
{
$result = $this->subject->viewOptions([], false);
$this->assertTrue(is_array($result));
$this->assertInternalType('array', $result);
$this->assertEmpty($result);
}

0 comments on commit ff023ed

Please sign in to comment.
You can’t perform that action at this time.