Skip to content
Permalink
Browse files

minor fixes to unit tests (#10052)

Use PHPUnit assertions better.
  • Loading branch information...
gemal authored and markstory committed Jan 18, 2017
1 parent 322aa7a commit e808d232498b9c85fc5155cb475fcce765e2c70f
Showing with 166 additions and 166 deletions.
  1. +1 −1 src/TestSuite/IntegrationTestCase.php
  2. +19 −19 tests/TestCase/Cache/Engine/FileEngineTest.php
  3. +2 −2 tests/TestCase/Collection/CollectionTest.php
  4. +8 −8 tests/TestCase/Console/ConsoleOptionParserTest.php
  5. +9 −9 tests/TestCase/Console/ShellTest.php
  6. +5 −5 tests/TestCase/Controller/Component/AuthComponentTest.php
  7. +1 −1 tests/TestCase/Controller/Component/RequestHandlerComponentTest.php
  8. +2 −2 tests/TestCase/Controller/ComponentTest.php
  9. +2 −2 tests/TestCase/Core/Configure/Engine/IniConfigTest.php
  10. +2 −2 tests/TestCase/Core/Configure/Engine/JsonConfigTest.php
  11. +2 −2 tests/TestCase/Core/Configure/Engine/PhpConfigTest.php
  12. +2 −2 tests/TestCase/Core/ConfigureTest.php
  13. +1 −1 tests/TestCase/Error/DebuggerTest.php
  14. +1 −1 tests/TestCase/Error/ErrorHandlerTest.php
  15. +6 −6 tests/TestCase/Filesystem/FileTest.php
  16. +56 −56 tests/TestCase/Filesystem/FolderTest.php
  17. +14 −14 tests/TestCase/Log/Engine/FileLogTest.php
  18. +3 −3 tests/TestCase/Network/ResponseTest.php
  19. +1 −1 tests/TestCase/ORM/Behavior/TreeBehaviorTest.php
  20. +2 −2 tests/TestCase/ORM/MarshallerTest.php
  21. +3 −3 tests/TestCase/ORM/QueryTest.php
  22. +5 −5 tests/TestCase/ORM/TableTest.php
  23. +1 −1 tests/TestCase/Routing/Route/RouteTest.php
  24. +7 −7 tests/TestCase/Shell/Task/AssetsTaskTest.php
  25. +6 −6 tests/TestCase/Shell/Task/ExtractTaskTest.php
  26. +1 −1 tests/TestCase/Utility/HashTest.php
  27. +1 −1 tests/TestCase/Utility/XmlTest.php
  28. +2 −2 tests/TestCase/View/Helper/HtmlHelperTest.php
  29. +1 −1 tests/TestCase/View/ViewVarsTraitTest.php
@@ -700,7 +700,7 @@ public function assertRedirect($url = null, $message = '')
}
$result = $this->_response->header();
if ($url === null) {
$this->assertTrue(!empty($result['Location']), $message);
$this->assertNotEmpty($result['Location'], $message);
return;
}
@@ -95,7 +95,7 @@ public function testReadAndwrite()
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('test', $data, 'file_test');
$this->assertTrue(file_exists(TMP . 'tests/cake_test'));
$this->assertFileExists(TMP . 'tests/cake_test');
$result = Cache::read('test', 'file_test');
$expecting = $data;
@@ -166,7 +166,7 @@ public function testDeleteCache()
$result = Cache::delete('delete_test', 'file_test');
$this->assertTrue($result);
$this->assertFalse(file_exists(TMP . 'tests/delete_test'));
$this->assertFileNotExists(TMP . 'tests/delete_test');
$result = Cache::delete('delete_test', 'file_test');
$this->assertFalse($result);
@@ -205,30 +205,30 @@ public function testClear()
Cache::write('serialize_test1', $data, 'file_test');
Cache::write('serialize_test2', $data, 'file_test');
Cache::write('serialize_test3', $data, 'file_test');
$this->assertTrue(file_exists(TMP . 'tests/cake_serialize_test1'));
$this->assertTrue(file_exists(TMP . 'tests/cake_serialize_test2'));
$this->assertTrue(file_exists(TMP . 'tests/cake_serialize_test3'));
$this->assertFileExists(TMP . 'tests/cake_serialize_test1');
$this->assertFileExists(TMP . 'tests/cake_serialize_test2');
$this->assertFileExists(TMP . 'tests/cake_serialize_test3');
sleep(1);
$result = Cache::clear(true, 'file_test');
$this->assertTrue($result);
$this->assertFalse(file_exists(TMP . 'tests/cake_serialize_test1'));
$this->assertFalse(file_exists(TMP . 'tests/cake_serialize_test2'));
$this->assertFalse(file_exists(TMP . 'tests/cake_serialize_test3'));
$this->assertFileNotExists(TMP . 'tests/cake_serialize_test1');
$this->assertFileNotExists(TMP . 'tests/cake_serialize_test2');
$this->assertFileNotExists(TMP . 'tests/cake_serialize_test3');
$data = 'this is a test of the emergency broadcasting system';
Cache::write('serialize_test1', $data, 'file_test');
Cache::write('serialize_test2', $data, 'file_test');
Cache::write('serialize_test3', $data, 'file_test');
$this->assertTrue(file_exists(TMP . 'tests/cake_serialize_test1'));
$this->assertTrue(file_exists(TMP . 'tests/cake_serialize_test2'));
$this->assertTrue(file_exists(TMP . 'tests/cake_serialize_test3'));
$this->assertFileExists(TMP . 'tests/cake_serialize_test1');
$this->assertFileExists(TMP . 'tests/cake_serialize_test2');
$this->assertFileExists(TMP . 'tests/cake_serialize_test3');
$result = Cache::clear(false, 'file_test');
$this->assertTrue($result);
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
$this->assertFileNotExists(CACHE . 'cake_serialize_test1');
$this->assertFileNotExists(CACHE . 'cake_serialize_test2');
$this->assertFileNotExists(CACHE . 'cake_serialize_test3');
}
/**
@@ -307,7 +307,7 @@ public function testKeyPath()
{
$result = Cache::write('views.countries.something', 'here', 'file_test');
$this->assertTrue($result);
$this->assertTrue(file_exists(TMP . 'tests/cake_views_countries_something'));
$this->assertFileExists(TMP . 'tests/cake_views_countries_something');
$result = Cache::read('views.countries.something', 'file_test');
$this->assertEquals('here', $result);
@@ -317,11 +317,11 @@ public function testKeyPath()
$result = Cache::write('domain.test.com:8080', 'here', 'file_test');
$this->assertTrue($result);
$this->assertTrue(file_exists(TMP . 'tests/cake_domain_test_com_8080'));
$this->assertFileExists(TMP . 'tests/cake_domain_test_com_8080');
$result = Cache::write('command>dir|more', 'here', 'file_test');
$this->assertTrue($result);
$this->assertTrue(file_exists(TMP . 'tests/cake_command_dir_more'));
$this->assertFileExists(TMP . 'tests/cake_command_dir_more');
}
/**
@@ -526,13 +526,13 @@ public function testClearingWithRepeatWrites()
$this->assertEquals('rchavik', Cache::read('user', 'repeat'));
Cache::delete('user', 'repeat');
$this->assertEquals(false, Cache::read('user', 'repeat'));
$this->assertFalse(Cache::read('user', 'repeat'));
$this->assertTrue(Cache::write('user', 'ADmad', 'repeat'));
$this->assertEquals('ADmad', Cache::read('user', 'repeat'));
Cache::clearGroup('users', 'repeat');
$this->assertEquals(false, Cache::read('user', 'repeat'));
$this->assertFalse(Cache::read('user', 'repeat'));
$this->assertTrue(Cache::write('user', 'markstory', 'repeat'));
$this->assertEquals('markstory', Cache::read('user', 'repeat'));
@@ -574,7 +574,7 @@ public function testShuffle()
{
$data = [1, 2, 3, 4];
$collection = (new Collection($data))->shuffle();
$this->assertEquals(count($data), count(iterator_to_array($collection)));
$this->assertCount(count($data), iterator_to_array($collection));
foreach ($collection as $value) {
$this->assertContains($value, $data);
@@ -590,7 +590,7 @@ public function testSample()
{
$data = [1, 2, 3, 4];
$collection = (new Collection($data))->sample(2);
$this->assertEquals(2, count(iterator_to_array($collection)));
$this->assertCount(2, iterator_to_array($collection));
foreach ($collection as $value) {
$this->assertContains($value, $data);
@@ -588,7 +588,7 @@ public function testAddSubcommandObject()
$parser = new ConsoleOptionParser('test', false);
$parser->addSubcommand(new ConsoleInputSubcommand('test'));
$result = $parser->subcommands();
$this->assertEquals(1, count($result));
$this->assertCount(1, $result);
$this->assertEquals('test', $result['test']->name());
}
@@ -602,7 +602,7 @@ public function testRemoveSubcommand()
$parser = new ConsoleOptionParser('test', false);
$parser->addSubcommand(new ConsoleInputSubcommand('test'));
$result = $parser->subcommands();
$this->assertEquals(1, count($result));
$this->assertCount(1, $result);
$parser->removeSubcommand('test');
$result = $parser->subcommands();
$this->assertEquals(0, count($result), 'Remove a subcommand does not work');
@@ -704,10 +704,10 @@ public function testBuildFromArray()
$this->assertTrue(isset($options['other']));
$args = $parser->arguments();
$this->assertEquals(2, count($args));
$this->assertCount(2, $args);
$commands = $parser->subcommands();
$this->assertEquals(1, count($commands));
$this->assertCount(1, $commands);
}
/**
@@ -800,8 +800,8 @@ public function testToArray()
$this->assertTrue(isset($options['name']));
$this->assertTrue(isset($options['other']));
$this->assertEquals(2, count($result['arguments']));
$this->assertEquals(1, count($result['subcommands']));
$this->assertCount(2, $result['arguments']);
$this->assertCount(1, $result['subcommands']);
}
/**
@@ -830,7 +830,7 @@ public function testMerge()
$this->assertTrue(isset($options['file']));
$this->assertTrue(isset($options['output']));
$this->assertEquals(2, count($result['arguments']));
$this->assertEquals(6, count($result['options']));
$this->assertCount(2, $result['arguments']);
$this->assertCount(6, $result['options']);
}
}
@@ -505,7 +505,7 @@ public function testCreateFileNonInteractive()
$contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertFileExists($file);
$this->assertEquals(file_get_contents($file), $contents);
}
@@ -527,11 +527,11 @@ public function testCreateFileNoReply()
->will($this->returnValue('n'));
touch($file);
$this->assertTrue(file_exists($file));
$this->assertFileExists($file);
$contents = "My content";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue(file_exists($file));
$this->assertFileExists($file);
$this->assertTextEquals('', file_get_contents($file));
$this->assertFalse($result, 'Did not create file.');
}
@@ -554,11 +554,11 @@ public function testCreateFileOverwrite()
->will($this->returnValue('y'));
touch($file);
$this->assertTrue(file_exists($file));
$this->assertFileExists($file);
$contents = "My content";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue(file_exists($file));
$this->assertFileExists($file);
$this->assertTextEquals($contents, file_get_contents($file));
$this->assertTrue($result, 'Did create file.');
}
@@ -576,7 +576,7 @@ public function testCreateFileOverwriteNonInteractive()
new Folder($path, true);
touch($file);
$this->assertTrue(file_exists($file));
$this->assertFileExists($file);
$this->io->expects($this->never())->method('askChoice');
@@ -609,10 +609,10 @@ public function testCreateFileOverwriteAll()
foreach ($files as $file => $contents) {
touch($file);
$this->assertTrue(file_exists($file));
$this->assertFileExists($file);
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue(file_exists($file));
$this->assertFileExists($file);
$this->assertTextEquals($contents, file_get_contents($file));
$this->assertTrue($result, 'Did create file.');
}
@@ -636,7 +636,7 @@ public function testCreateFileNoPermissions()
chmod($path, 0444);
$this->Shell->createFile($file, 'testing');
$this->assertFalse(file_exists($file));
$this->assertFileNotExists($file);
chmod($path, 0744);
rmdir($path);
@@ -367,10 +367,10 @@ public function testLoadAuthorizeResets()
{
$this->Controller->Auth->config('authorize', ['Controller']);
$result = $this->Controller->Auth->constructAuthorize();
$this->assertEquals(1, count($result));
$this->assertCount(1, $result);
$result = $this->Controller->Auth->constructAuthorize();
$this->assertEquals(1, count($result));
$this->assertCount(1, $result);
}
/**
@@ -410,10 +410,10 @@ public function testLoadAuthenticateResets()
{
$this->Controller->Auth->config('authenticate', ['Form']);
$result = $this->Controller->Auth->constructAuthenticate();
$this->assertEquals(1, count($result));
$this->assertCount(1, $result);
$result = $this->Controller->Auth->constructAuthenticate();
$this->assertEquals(1, count($result));
$this->assertCount(1, $result);
}
/**
@@ -445,7 +445,7 @@ public function testSameAuthenticateWithDifferentHashers()
]);
$objects = $this->Controller->Auth->constructAuthenticate();
$this->assertEquals(2, count($objects));
$this->assertCount(2, $objects);
$this->assertInstanceOf('Cake\Auth\FormAuthenticate', $objects['FormSimple']);
$this->assertInstanceOf('Cake\Auth\FormAuthenticate', $objects['FormBlowfish']);
@@ -356,7 +356,7 @@ public function testIsAjaxParams()
$this->RequestHandler->initialize([]);
$this->Controller->beforeFilter($event);
$this->RequestHandler->startup($event);
$this->assertEquals(true, $this->Controller->request->params['isAjax']);
$this->assertTrue($this->Controller->request->params['isAjax']);
}
/**
@@ -68,8 +68,8 @@ public function testNestedComponentLoading()
$this->assertInstanceOf(OrangeComponent::class, $Apple->Orange, 'class is wrong');
$this->assertInstanceOf(BananaComponent::class, $Apple->Orange->Banana, 'class is wrong');
$this->assertTrue(empty($Apple->Session));
$this->assertTrue(empty($Apple->Orange->Session));
$this->assertEmpty($Apple->Session);
$this->assertEmpty($Apple->Orange->Session);
}
/**
@@ -233,7 +233,7 @@ public function testDump()
{
$engine = new IniConfig(TMP);
$result = $engine->dump('test', $this->testData);
$this->assertTrue($result > 0);
$this->assertGreaterThan(0, $result);
$expected = <<<INI
[One]
@@ -253,7 +253,7 @@ public function testDump()
$this->assertTextEquals($expected, $result);
$result = $engine->dump('test', $this->testData);
$this->assertTrue($result > 0);
$this->assertGreaterThan(0, $result);
$contents = file_get_contents($file);
$this->assertTextEquals($expected, $contents);
@@ -154,7 +154,7 @@ public function testDump()
{
$engine = new JsonConfig(TMP);
$result = $engine->dump('test', $this->testData);
$this->assertTrue($result > 0);
$this->assertGreaterThan(0, $result);
$expected = '{
"One": {
"two": "value",
@@ -176,7 +176,7 @@ public function testDump()
$this->assertTextEquals($expected, $contents);
$result = $engine->dump('test', $this->testData);
$this->assertTrue($result > 0);
$this->assertGreaterThan(0, $result);
$contents = file_get_contents($file);
$this->assertTextEquals($expected, $contents);
@@ -140,7 +140,7 @@ public function testDump()
{
$engine = new PhpConfig(TMP);
$result = $engine->dump('test', $this->testData);
$this->assertTrue($result > 0);
$this->assertGreaterThan(0, $result);
$expected = <<<PHP
<?php
return array (
@@ -168,7 +168,7 @@ public function testDump()
$this->assertTextEquals($expected, $contents);
$result = $engine->dump('test', $this->testData);
$this->assertTrue($result > 0);
$this->assertGreaterThan(0, $result);
$contents = file_get_contents($file);
$this->assertTextEquals($expected, $contents);
@@ -515,7 +515,7 @@ public function testDump()
Configure::config('test_Engine', new PhpConfig(TMP));
$result = Configure::dump('config_test', 'test_Engine');
$this->assertTrue($result > 0);
$this->assertGreaterThan(0, $result);
$result = file_get_contents(TMP . 'config_test.php');
$this->assertContains('<?php', $result);
$this->assertContains('return ', $result);
@@ -535,7 +535,7 @@ public function testDumpPartial()
Configure::write('Error', ['test' => 'value']);
$result = Configure::dump('config_test', 'test_Engine', ['Error']);
$this->assertTrue($result > 0);
$this->assertGreaterThan(0, $result);
$result = file_get_contents(TMP . 'config_test.php');
$this->assertContains('<?php', $result);
$this->assertContains('return ', $result);
@@ -117,7 +117,7 @@ public function testExcerpt()
$this->assertRegExp($pattern, $result[0]);
$return = Debugger::excerpt('[internal]', 2, 2);
$this->assertTrue(empty($return));
$this->assertEmpty($return);
$result = Debugger::excerpt(__FILE__, __LINE__, 5);
$this->assertCount(11, $result);
@@ -178,7 +178,7 @@ public function testErrorSuppressed()
@include 'invalid.file';
//@codingStandardsIgnoreEnd
$result = ob_get_clean();
$this->assertTrue(empty($result));
$this->assertEmpty($result);
}
/**
Oops, something went wrong.

0 comments on commit e808d23

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