Browse Source

Refactoring tests

Gabriel Caruso 8 years ago
parent
commit
0eaf968db8

+ 5 - 5
tests/TestCase/Console/ConsoleOptionParserTest.php

@@ -370,7 +370,7 @@ class ConsoleOptionParserTest extends TestCase
         $this->assertEquals($parser, $result, 'addOptions is not chainable.');
 
         $result = $parser->options();
-        $this->assertEquals(3, count($result), 'Not enough options');
+        $this->assertCount(3, $result, 'Not enough options');
     }
 
     /**
@@ -519,7 +519,7 @@ class ConsoleOptionParserTest extends TestCase
             ->addArgument('other', ['index' => 0]);
 
         $result = $parser->arguments();
-        $this->assertEquals(1, count($result), 'Overwrite did not occur');
+        $this->assertCount(1, $result, 'Overwrite did not occur');
     }
 
     /**
@@ -618,7 +618,7 @@ class ConsoleOptionParserTest extends TestCase
         $this->assertEquals($parser, $result, 'addArguments is not chainable.');
 
         $result = $parser->arguments();
-        $this->assertEquals(2, count($result), 'Not enough arguments');
+        $this->assertCount(2, $result, 'Not enough arguments');
     }
 
     /**
@@ -702,7 +702,7 @@ class ConsoleOptionParserTest extends TestCase
         $this->assertCount(1, $result);
         $parser->removeSubcommand('test');
         $result = $parser->subcommands();
-        $this->assertEquals(0, count($result), 'Remove a subcommand does not work');
+        $this->assertCount(0, $result, 'Remove a subcommand does not work');
     }
 
     /**
@@ -719,7 +719,7 @@ class ConsoleOptionParserTest extends TestCase
         ]);
         $this->assertEquals($parser, $result, 'Adding a subcommands is not chainable');
         $result = $parser->subcommands();
-        $this->assertEquals(2, count($result), 'Not enough subcommands');
+        $this->assertCount(2, $result, 'Not enough subcommands');
     }
 
     /**

+ 2 - 2
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -1574,10 +1574,10 @@ class AuthComponentTest extends TestCase
             $this->assertEquals($data['User']['Group']['name'], $result);
 
             $result = $this->Auth->user('invalid');
-            $this->assertEquals(null, $result);
+            $this->assertNull($result);
 
             $result = $this->Auth->user('Company.invalid');
-            $this->assertEquals(null, $result);
+            $this->assertNull($result);
 
             $result = $this->Auth->user('is_admin');
             $this->assertFalse($result);

+ 2 - 2
tests/TestCase/Core/ConfigureTest.php

@@ -116,7 +116,7 @@ class ConfigureTest extends TestCase
         $this->assertTrue(isset($result['level1']));
 
         $result = Configure::read('something_I_just_made_up_now');
-        $this->assertEquals(null, $result, 'Missing key should return null.');
+        $this->assertNull($result, 'Missing key should return null.');
 
         $default = 'default';
         $result = Configure::read('something_I_just_made_up_now', $default);
@@ -142,7 +142,7 @@ class ConfigureTest extends TestCase
         $writeResult = Configure::write('SomeName.someKey', null);
         $this->assertTrue($writeResult);
         $result = Configure::read('SomeName.someKey');
-        $this->assertEquals(null, $result);
+        $this->assertNull($result);
 
         $expected = ['One' => ['Two' => ['Three' => ['Four' => ['Five' => 'cool']]]]];
         $writeResult = Configure::write('Key', $expected);

+ 3 - 3
tests/TestCase/Core/PluginTest.php

@@ -191,7 +191,7 @@ class PluginTest extends TestCase
         $expected = ['TestPlugin', 'TestPluginTwo'];
         $this->assertEquals($expected, Plugin::loaded());
         $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
-        $this->assertEquals(null, Configure::read('PluginTest.test_plugin_two.bootstrap'));
+        $this->assertNull(Configure::read('PluginTest.test_plugin_two.bootstrap'));
     }
 
     /**
@@ -361,11 +361,11 @@ class PluginTest extends TestCase
         $this->assertEquals($expected, Plugin::loaded());
         $this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap'));
         $this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
-        $this->assertEquals(null, Configure::read('PluginTest.test_plugin.bootstrap'));
+        $this->assertNull(Configure::read('PluginTest.test_plugin.bootstrap'));
         $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
         $this->assertEquals('loaded plugin four bootstrap', Configure::read('PluginTest.test_plugin_four.bootstrap'));
 
         // TestPluginThree won't get loaded by loadAll() since it's in a sub directory.
-        $this->assertEquals(null, Configure::read('PluginTest.test_plugin_three.bootstrap'));
+        $this->assertNull(Configure::read('PluginTest.test_plugin_three.bootstrap'));
     }
 }

+ 1 - 1
tests/TestCase/Filesystem/FolderTest.php

@@ -1126,7 +1126,7 @@ class FolderTest extends TestCase
 
         $this->assertFileExists($folderThree . DS . 'file1.php');
         $this->assertFileExists($folderThree . DS . 'file2.php');
-        $this->assertTrue(!file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
+        $this->assertFileNotExists($folderThree . DS . 'folderA' . DS . 'fileA.php');
         $this->assertFileExists($folderThree . DS . 'folderB' . DS . 'fileB.php');
     }
 

+ 6 - 6
tests/TestCase/Http/Client/Adapter/StreamTest.php

@@ -384,15 +384,15 @@ class StreamTest extends TestCase
         $this->assertEquals(200, $responses[2]->getStatusCode());
 
         $this->assertEquals('value', $responses[0]->getCookie('first'));
-        $this->assertEquals(null, $responses[0]->getCookie('second'));
-        $this->assertEquals(null, $responses[0]->getCookie('third'));
+        $this->assertNull($responses[0]->getCookie('second'));
+        $this->assertNull($responses[0]->getCookie('third'));
 
-        $this->assertEquals(null, $responses[1]->getCookie('first'));
+        $this->assertNull($responses[1]->getCookie('first'));
         $this->assertEquals('val', $responses[1]->getCookie('second'));
-        $this->assertEquals(null, $responses[1]->getCookie('third'));
+        $this->assertNull($responses[1]->getCookie('third'));
 
-        $this->assertEquals(null, $responses[2]->getCookie('first'));
-        $this->assertEquals(null, $responses[2]->getCookie('second'));
+        $this->assertNull($responses[2]->getCookie('first'));
+        $this->assertNull($responses[2]->getCookie('second'));
         $this->assertEquals('works', $responses[2]->getCookie('third'));
     }
 

+ 1 - 1
tests/TestCase/Http/ResponseTest.php

@@ -140,7 +140,7 @@ class ResponseTest extends TestCase
 
             $response = new Response();
             $response->body(null);
-            $this->assertEquals(null, $response->body());
+            $this->assertNull($response->body());
         });
     }
 

+ 2 - 2
tests/TestCase/Http/SessionTest.php

@@ -219,7 +219,7 @@ class SessionTest extends TestCase
         ]);
         $this->assertEquals(1, $session->read('one'));
         $this->assertEquals(['something'], $session->read('three'));
-        $this->assertEquals(null, $session->read('null'));
+        $this->assertNull($session->read('null'));
     }
 
     /**
@@ -456,7 +456,7 @@ class SessionTest extends TestCase
         $this->assertFalse($session->read('SessionTestCase'));
 
         $session->write('SessionTestCase', null);
-        $this->assertEquals(null, $session->read('SessionTestCase'));
+        $this->assertNull($session->read('SessionTestCase'));
     }
 
     /**

+ 4 - 4
tests/TestCase/Network/SocketTest.php

@@ -142,14 +142,14 @@ class SocketTest extends TestCase
             $this->Socket->connect();
             $this->assertEquals('127.0.0.1', $this->Socket->address());
             $this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
-            $this->assertEquals(null, $this->Socket->lastError());
+            $this->assertNull($this->Socket->lastError());
             $this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
 
             $this->Socket = new Socket(['host' => '127.0.0.1']);
             $this->Socket->connect();
             $this->assertEquals('127.0.0.1', $this->Socket->address());
             $this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
-            $this->assertEquals(null, $this->Socket->lastError());
+            $this->assertNull($this->Socket->lastError());
             $this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
         } catch (SocketException $e) {
             $this->markTestSkipped('Cannot test network, skipping.');
@@ -181,12 +181,12 @@ class SocketTest extends TestCase
         $this->Socket = new Socket(['timeout' => 5]);
         try {
             $this->Socket->connect();
-            $this->assertEquals(null, $this->Socket->read(26));
+            $this->assertNull($this->Socket->read(26));
 
             $config = ['host' => 'google.com', 'port' => 80, 'timeout' => 1];
             $this->Socket = new Socket($config);
             $this->assertTrue($this->Socket->connect());
-            $this->assertEquals(null, $this->Socket->read(26));
+            $this->assertNull($this->Socket->read(26));
             $this->assertEquals('2: ' . 'Connection timed out', $this->Socket->lastError());
         } catch (SocketException $e) {
             $this->markTestSkipped('Cannot test network, skipping.');

+ 2 - 2
tests/TestCase/ORM/AssociationTest.php

@@ -252,9 +252,9 @@ class AssociationTest extends TestCase
     public function testCascadeCallbacks()
     {
         $this->deprecated(function () {
-            $this->assertSame(false, $this->association->cascadeCallbacks());
+            $this->assertFalse($this->association->cascadeCallbacks());
             $this->association->cascadeCallbacks(true);
-            $this->assertSame(true, $this->association->cascadeCallbacks());
+            $this->assertTrue($this->association->cascadeCallbacks());
         });
     }
 

+ 3 - 3
tests/TestCase/ORM/Behavior/TreeBehaviorTest.php

@@ -1287,7 +1287,7 @@ class TreeBehaviorTest extends TestCase
         $this->assertSame($entity, $table->removeFromTree($entity));
         $this->assertEquals(21, $entity->lft);
         $this->assertEquals(22, $entity->rght);
-        $this->assertEquals(null, $entity->parent_id);
+        $this->assertNull($entity->parent_id);
         $result = $table->find()->order('lft')->enableHydration(false);
         $expected = [
             ' 1:18 -  1:electronics',
@@ -1319,7 +1319,7 @@ class TreeBehaviorTest extends TestCase
         $result = $table->find('threaded')->order('lft')->enableHydration(false)->toArray();
         $this->assertEquals(21, $entity->lft);
         $this->assertEquals(22, $entity->rght);
-        $this->assertEquals(null, $entity->parent_id);
+        $this->assertNull($entity->parent_id);
         $result = $table->find()->order('lft')->enableHydration(false);
         $expected = [
             ' 1:18 -  1:electronics',
@@ -1350,7 +1350,7 @@ class TreeBehaviorTest extends TestCase
         $result = $table->find('threaded')->order('lft')->enableHydration(false)->toArray();
         $this->assertEquals(21, $entity->lft);
         $this->assertEquals(22, $entity->rght);
-        $this->assertEquals(null, $entity->parent_id);
+        $this->assertNull($entity->parent_id);
 
         $expected = [
             ' 1: 8 -  2:televisions',

+ 1 - 1
tests/TestCase/View/Helper/TimeHelperTest.php

@@ -631,7 +631,7 @@ class TimeHelperTest extends TestCase
     public function testNullDateFormat()
     {
         $result = $this->Time->format(null);
-        $this->assertSame(false, $result);
+        $this->assertFalse($result);
 
         $fallback = 'Date invalid or not set';
         $result = $this->Time->format(null, \IntlDateFormatter::FULL, $fallback);