Skip to content

Commit

Permalink
Refactoring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carusogabriel authored and markstory committed Dec 1, 2017
1 parent 22b1ff6 commit 0eaf968
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions tests/TestCase/Console/ConsoleOptionParserTest.php
Expand Up @@ -370,7 +370,7 @@ public function testAddOptions()
$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');
}

/**
Expand Down Expand Up @@ -519,7 +519,7 @@ public function testPositionalArgOverwrite()
->addArgument('other', ['index' => 0]);

$result = $parser->arguments();
$this->assertEquals(1, count($result), 'Overwrite did not occur');
$this->assertCount(1, $result, 'Overwrite did not occur');
}

/**
Expand Down Expand Up @@ -618,7 +618,7 @@ public function testAddArguments()
$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');
}

/**
Expand Down Expand Up @@ -702,7 +702,7 @@ public function testRemoveSubcommand()
$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');
}

/**
Expand All @@ -719,7 +719,7 @@ public function testAddSubcommands()
]);
$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');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -1574,10 +1574,10 @@ public function testUser()
$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);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Core/ConfigureTest.php
Expand Up @@ -116,7 +116,7 @@ public function testRead()
$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);
Expand All @@ -142,7 +142,7 @@ public function testWrite()
$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);
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Core/PluginTest.php
Expand Up @@ -191,7 +191,7 @@ public function testLoadMultipleWithDefaultsAndOverride()
$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'));
}

/**
Expand Down Expand Up @@ -361,11 +361,11 @@ public function testLoadAllWithDefaultsAndOverride()
$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'));
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Filesystem/FolderTest.php
Expand Up @@ -1126,7 +1126,7 @@ public function testCopyWithOverwrite()

$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');
}

Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/Http/Client/Adapter/StreamTest.php
Expand Up @@ -384,15 +384,15 @@ public function testCreateResponseWithRedirects()
$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'));
}

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

$response = new Response();
$response->body(null);
$this->assertEquals(null, $response->body());
$this->assertNull($response->body());
});
}

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Http/SessionTest.php
Expand Up @@ -219,7 +219,7 @@ public function testWriteArray()
]);
$this->assertEquals(1, $session->read('one'));
$this->assertEquals(['something'], $session->read('three'));
$this->assertEquals(null, $session->read('null'));
$this->assertNull($session->read('null'));
}

/**
Expand Down Expand Up @@ -456,7 +456,7 @@ public function testReadingSavedEmpty()
$this->assertFalse($session->read('SessionTestCase'));

$session->write('SessionTestCase', null);
$this->assertEquals(null, $session->read('SessionTestCase'));
$this->assertNull($session->read('SessionTestCase'));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Network/SocketTest.php
Expand Up @@ -142,14 +142,14 @@ public function testSocketHost()
$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.');
Expand Down Expand Up @@ -181,12 +181,12 @@ public function testSocketReading()
$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.');
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/ORM/AssociationTest.php
Expand Up @@ -252,9 +252,9 @@ public function testTargetTableDescendant()
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());
});
}

Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/ORM/Behavior/TreeBehaviorTest.php
Expand Up @@ -1287,7 +1287,7 @@ public function testRemoveFromLeafFromTree()
$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',
Expand Down Expand Up @@ -1319,7 +1319,7 @@ public function testRemoveMiddleNodeFromTree()
$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',
Expand Down Expand Up @@ -1350,7 +1350,7 @@ public function testRemoveRootFromTree()
$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',
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/Helper/TimeHelperTest.php
Expand Up @@ -631,7 +631,7 @@ public function assertTimeFormat($expected, $result)
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);
Expand Down

0 comments on commit 0eaf968

Please sign in to comment.