Skip to content

Commit

Permalink
Refactoring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carusogabriel committed Dec 3, 2017
1 parent 2218373 commit ceac931
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion tests/TestCase/Auth/FallbackPasswordHasherTest.php
Expand Up @@ -73,7 +73,7 @@ public function testCheckWithConfigs()

$hash = $simple->hash('foo');
$legacyHash = $legacy->hash('foo');
$this->assertTrue($hash !== $legacyHash);
$this->assertNotSame($hash, $legacyHash);
$this->assertTrue($hasher->check('foo', $hash));
$this->assertTrue($hasher->check('foo', $legacyHash));
}
Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/Cache/CacheTest.php
Expand Up @@ -598,13 +598,13 @@ public function testWriteEmptyValues()
{
$this->_configCache();
Cache::write('App.falseTest', false, 'tests');
$this->assertSame(Cache::read('App.falseTest', 'tests'), false);
$this->assertFalse(Cache::read('App.falseTest', 'tests'));

Cache::write('App.trueTest', true, 'tests');
$this->assertSame(Cache::read('App.trueTest', 'tests'), true);
$this->assertTrue(Cache::read('App.trueTest', 'tests'));

Cache::write('App.nullTest', null, 'tests');
$this->assertSame(Cache::read('App.nullTest', 'tests'), null);
$this->assertNull(Cache::read('App.nullTest', 'tests'));

Cache::write('App.zeroTest', 0, 'tests');
$this->assertSame(Cache::read('App.zeroTest', 'tests'), 0);
Expand Down Expand Up @@ -645,9 +645,9 @@ public function testReadWriteMany()

$read = Cache::readMany(array_keys($data), 'tests');

$this->assertSame($read['App.falseTest'], false);
$this->assertSame($read['App.trueTest'], true);
$this->assertSame($read['App.nullTest'], null);
$this->assertFalse($read['App.falseTest']);
$this->assertTrue($read['App.trueTest']);
$this->assertNull($read['App.nullTest']);
$this->assertSame($read['App.zeroTest'], 0);
$this->assertSame($read['App.zeroTest2'], '0');
}
Expand All @@ -672,11 +672,11 @@ public function testDeleteMany()
Cache::deleteMany(array_keys($data), 'tests');
$read = Cache::readMany(array_merge(array_keys($data), ['App.keepTest']), 'tests');

$this->assertSame($read['App.falseTest'], false);
$this->assertSame($read['App.trueTest'], false);
$this->assertSame($read['App.nullTest'], false);
$this->assertSame($read['App.zeroTest'], false);
$this->assertSame($read['App.zeroTest2'], false);
$this->assertFalse($read['App.falseTest']);
$this->assertFalse($read['App.trueTest']);
$this->assertFalse($read['App.nullTest']);
$this->assertFalse($read['App.zeroTest']);
$this->assertFalse($read['App.zeroTest2']);
$this->assertSame($read['App.keepTest'], 'keepMe');
}

Expand Down
24 changes: 12 additions & 12 deletions tests/TestCase/Cache/Engine/MemcachedEngineTest.php
Expand Up @@ -494,12 +494,12 @@ public function testReadMany()

$read = Cache::readMany(array_merge(array_keys($data), ['App.doesNotExist']), 'memcached');

$this->assertSame($read['App.falseTest'], false);
$this->assertSame($read['App.trueTest'], true);
$this->assertSame($read['App.nullTest'], null);
$this->assertFalse($read['App.falseTest']);
$this->assertTrue($read['App.trueTest']);
$this->assertNull($read['App.nullTest']);
$this->assertSame($read['App.zeroTest'], 0);
$this->assertSame($read['App.zeroTest2'], '0');
$this->assertSame($read['App.doesNotExist'], false);
$this->assertFalse($read['App.doesNotExist']);
}

/**
Expand All @@ -519,9 +519,9 @@ public function testWriteMany()
];
Cache::writeMany($data, 'memcached');

$this->assertSame(Cache::read('App.falseTest', 'memcached'), false);
$this->assertSame(Cache::read('App.trueTest', 'memcached'), true);
$this->assertSame(Cache::read('App.nullTest', 'memcached'), null);
$this->assertFalse(Cache::read('App.falseTest', 'memcached'));
$this->assertTrue(Cache::read('App.trueTest', 'memcached'));
$this->assertNull(Cache::read('App.nullTest', 'memcached'));
$this->assertSame(Cache::read('App.zeroTest', 'memcached'), 0);
$this->assertSame(Cache::read('App.zeroTest2', 'memcached'), '0');
}
Expand Down Expand Up @@ -608,11 +608,11 @@ public function testDeleteMany()

Cache::deleteMany(array_merge(array_keys($data), ['App.doesNotExist']), 'memcached');

$this->assertSame(Cache::read('App.falseTest', 'memcached'), false);
$this->assertSame(Cache::read('App.trueTest', 'memcached'), false);
$this->assertSame(Cache::read('App.nullTest', 'memcached'), false);
$this->assertSame(Cache::read('App.zeroTest', 'memcached'), false);
$this->assertSame(Cache::read('App.zeroTest2', 'memcached'), false);
$this->assertFalse(Cache::read('App.falseTest', 'memcached'));
$this->assertFalse(Cache::read('App.trueTest', 'memcached'));
$this->assertFalse(Cache::read('App.nullTest', 'memcached'));
$this->assertFalse(Cache::read('App.zeroTest', 'memcached'));
$this->assertFalse(Cache::read('App.zeroTest2', 'memcached'));
$this->assertSame(Cache::read('App.keepTest', 'memcached'), 'keepMe');
}

Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/Console/ConsoleIoTest.php
Expand Up @@ -589,7 +589,7 @@ public function testCreateFileSuccess()

$this->assertTrue($result);
$this->assertFileExists($file);
$this->assertEquals($contents, file_get_contents($file));
$this->assertStringEqualsFile($file, $contents);
}

/**
Expand Down Expand Up @@ -660,7 +660,7 @@ public function testCreateFileOverwriteNo()

$this->assertFalse($result);
$this->assertFileExists($file);
$this->assertEquals('original', file_get_contents($file));
$this->assertStringEqualsFile($file, 'original');
}

/**
Expand All @@ -682,7 +682,7 @@ public function testCreateFileOverwriteParam()

$this->assertTrue($result);
$this->assertFileExists($file);
$this->assertEquals($contents, file_get_contents($file));
$this->assertStringEqualsFile($file, $contents);
}

/**
Expand All @@ -704,15 +704,15 @@ public function testCreateFileOverwriteAll()
->will($this->returnValue('a'));

$this->io->createFile($file, 'new content');
$this->assertEquals('new content', file_get_contents($file));
$this->assertStringEqualsFile($file, 'new content');

$this->io->createFile($file, 'newer content');
$this->assertEquals('newer content', file_get_contents($file));
$this->assertStringEqualsFile($file, 'newer content');

$this->io->createFile($file, 'newest content', false);
$this->assertEquals(
$this->assertStringEqualsFile(
$file,
'newest content',
file_get_contents($file),
'overwrite state replaces parameter'
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -583,7 +583,7 @@ public function testCreateFileNonInteractive()
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertFileExists($file);
$this->assertEquals(file_get_contents($file), $contents);
$this->assertStringEqualsFile($file, $contents);
}

/**
Expand Down Expand Up @@ -660,7 +660,7 @@ public function testCreateFileOverwriteNonInteractive()
$this->Shell->interactive = false;
$result = $this->Shell->createFile($file, 'My content');
$this->assertTrue($result);
$this->assertEquals(file_get_contents($file), 'My content');
$this->assertStringEqualsFile($file, 'My content');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Core/ConfigureTest.php
Expand Up @@ -108,7 +108,7 @@ public function testRead()
$this->assertEquals('something_else', $result);

$result = Configure::read('debug');
$this->assertTrue($result >= 0);
$this->assertGreaterThanOrEqual(0, $result);

$result = Configure::read();
$this->assertInternalType('array', $result);
Expand Down Expand Up @@ -198,7 +198,7 @@ public function testDelete()

Configure::delete('SomeName.someKey');
$result = Configure::read('SomeName.someKey');
$this->assertTrue($result === null);
$this->assertNull($result);

Configure::write('SomeName', ['someKey' => 'myvalue', 'otherKey' => 'otherValue']);

Expand All @@ -211,10 +211,10 @@ public function testDelete()
Configure::delete('SomeName');

$result = Configure::read('SomeName.someKey');
$this->assertTrue($result === null);
$this->assertNull($result);

$result = Configure::read('SomeName.otherKey');
$this->assertTrue($result === null);
$this->assertNull($result);
}

/**
Expand Down Expand Up @@ -482,7 +482,7 @@ public function testEngineSetup()
Configure::config('test', $engine);
$configured = Configure::configured();

$this->assertTrue(in_array('test', $configured));
$this->assertContains('test', $configured);

$this->assertTrue(Configure::configured('test'));
$this->assertFalse(Configure::configured('fake_garbage'));
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/Filesystem/FileTest.php
Expand Up @@ -183,7 +183,7 @@ public function testRead()
$result = $this->File->read();
$expecting = file_get_contents(__FILE__);
$this->assertEquals($expecting, $result);
$this->assertTrue(!is_resource($this->File->handle));
$this->assertNotInternalType('resource', $this->File->handle);

$this->File->lock = true;
$result = $this->File->read();
Expand Down Expand Up @@ -251,12 +251,12 @@ public function testOpen()
$handle = $this->File->handle;
$r = $this->File->open();
$this->assertTrue($r);
$this->assertTrue($handle === $this->File->handle);
$this->assertSame($handle, $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->assertNotSame($handle, $this->File->handle);
$this->assertInternalType('resource', $this->File->handle);
}

Expand Down Expand Up @@ -442,7 +442,7 @@ public function testWrite()
$r = $TmpFile->write($data);
$this->assertTrue($r);
$this->assertFileExists($tmpFile);
$this->assertEquals($data, file_get_contents($tmpFile));
$this->assertStringEqualsFile($tmpFile, $data);
$this->assertInternalType('resource', $TmpFile->handle);
$TmpFile->close();
}
Expand Down Expand Up @@ -474,15 +474,15 @@ public function testAppend()
$this->assertTrue($r);
$this->assertFileExists($tmpFile);
$data = $data . $fragment;
$this->assertEquals($data, file_get_contents($tmpFile));
$this->assertStringEqualsFile($tmpFile, $data);
$newSize = $TmpFile->size();
$this->assertTrue($newSize > $size);
$size = $newSize;
$TmpFile->close();
}

$TmpFile->append('');
$this->assertEquals($data, file_get_contents($tmpFile));
$this->assertStringEqualsFile($tmpFile, $data);
$TmpFile->close();
}

Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Filesystem/FolderTest.php
Expand Up @@ -1068,8 +1068,8 @@ public function testCopyWithSkip()
$result = $Folder->copy(['to' => $folderThree, 'scheme' => Folder::SKIP]);
$this->assertTrue($result);
$this->assertFileExists($folderThree . DS . 'file2.php');
$this->assertEquals('touched', file_get_contents($folderThree . DS . 'file2.php'));
$this->assertEquals('untouched', file_get_contents($folderThree . DS . 'folderB' . DS . 'fileB.php'));
$this->assertStringEqualsFile($folderThree . DS . 'file2.php', 'touched');
$this->assertStringEqualsFile($folderThree . DS . 'folderB' . DS . 'fileB.php', 'untouched');
}

/**
Expand All @@ -1092,7 +1092,7 @@ public function testCopyWithSkipFileSkipped()
$Folder = new Folder($folderOne);
$result = $Folder->copy(['to' => $folderTwo, 'scheme' => Folder::SKIP]);
$this->assertTrue($result);
$this->assertEquals('Folder Two File', file_get_contents($folderTwo . DS . 'fileA.txt'));
$this->assertStringEqualsFile($folderTwo . DS . 'fileA.txt', 'Folder Two File');
}

/**
Expand Down Expand Up @@ -1260,7 +1260,7 @@ public function testMove()
$result = $Folder->move($folderTwo);
$this->assertTrue($result);
$this->assertFileExists($folderTwo . '/file1.php');
$this->assertEquals('', file_get_contents($folderTwoB . '/fileB.php'));
$this->assertStringEqualsFile($folderTwoB . '/fileB.php', '');
$this->assertFileNotExists($fileOne);
$this->assertFileNotExists($folderOneA);
$this->assertFileNotExists($fileOneA);
Expand Down Expand Up @@ -1327,7 +1327,7 @@ public function testMoveWithSkip()
$result = $Folder->move(['to' => $folderTwo, 'scheme' => Folder::SKIP]);
$this->assertTrue($result);
$this->assertFileExists($folderTwo . '/file1.php');
$this->assertEquals('untouched', file_get_contents($folderTwoB . '/fileB.php'));
$this->assertStringEqualsFile($folderTwoB . '/fileB.php', 'untouched');
$this->assertFileNotExists($fileOne);
$this->assertFileNotExists($folderOneA);
$this->assertFileNotExists($fileOneA);
Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/Http/ResponseTest.php
Expand Up @@ -718,7 +718,7 @@ public function testCompress()
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip';
$result = $response->compress();
$this->assertTrue($result);
$this->assertTrue(in_array('ob_gzhandler', ob_list_handlers()));
$this->assertContains('ob_gzhandler', ob_list_handlers());

ob_get_clean();
}
Expand Down Expand Up @@ -2039,7 +2039,7 @@ public function testFileWithDownloadAndName()
$result = $response->send();
$output = ob_get_clean();
$this->assertEquals("/* this is the test asset css file */\n", $output);
$this->assertNotSame(false, $result);
$this->assertNotFalse($result);
$this->assertEquals('text/css', $response->getType());
$this->assertEquals('bytes', $response->getHeaderLine('Accept-Ranges'));
$this->assertEquals('binary', $response->getHeaderLine('Content-Transfer-Encoding'));
Expand Down Expand Up @@ -2075,7 +2075,7 @@ public function testFileWithUnknownFileTypeGeneric()
$result = $response->send();
$output = ob_get_clean();
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
$this->assertNotSame(false, $result);
$this->assertNotFalse($result);
$this->assertEquals('text/html', $response->getType());
$this->assertEquals('bytes', $response->getHeaderLine('Accept-Ranges'));
$this->assertEquals('binary', $response->getHeaderLine('Content-Transfer-Encoding'));
Expand Down Expand Up @@ -2131,7 +2131,7 @@ public function testFileWithUnknownFileTypeOpera()
$result = $response->send();
$output = ob_get_clean();
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
$this->assertNotSame(false, $result);
$this->assertNotFalse($result);
$this->assertEquals('application/octet-stream', $response->getType());
$this->assertEquals('bytes', $response->getHeaderLine('Accept-Ranges'));
$this->assertEquals('binary', $response->getHeaderLine('Content-Transfer-Encoding'));
Expand Down Expand Up @@ -2187,7 +2187,7 @@ public function testFileWithUnknownFileTypeIE()
$result = $response->send();
$output = ob_get_clean();
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
$this->assertNotSame(false, $result);
$this->assertNotFalse($result);
$this->assertEquals('application/force-download', $response->getType());
$this->assertEquals('bytes', $response->getHeaderLine('Accept-Ranges'));
$this->assertEquals('binary', $response->getHeaderLine('Content-Transfer-Encoding'));
Expand Down Expand Up @@ -2459,7 +2459,7 @@ public function testFileRange()
$result = $response->send();
$output = ob_get_clean();
$this->assertEquals('is the test asset ', $output);
$this->assertNotSame(false, $result);
$this->assertNotFalse($result);

$this->assertEquals(
'attachment; filename="test_asset.css"',
Expand Down Expand Up @@ -2707,7 +2707,7 @@ public function testFileRangeNoDownload()
$this->assertEquals('text/css', $response->getType());
$this->assertEquals(206, $response->getStatusCode());
$this->assertEquals('is the test asset ', $output);
$this->assertNotSame(false, $result);
$this->assertNotFalse($result);
});
}

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

$session->write('SessionTestCase', '0');
$this->assertEquals('0', $session->read('SessionTestCase'));
$this->assertFalse($session->read('SessionTestCase') === 0);
$this->assertNotSame($session->read('SessionTestCase'), 0);

$session->write('SessionTestCase', false);
$this->assertFalse($session->read('SessionTestCase'));
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Network/SocketTest.php
Expand Up @@ -143,14 +143,14 @@ public function testSocketHost()
$this->assertEquals('127.0.0.1', $this->Socket->address());
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
$this->assertNull($this->Socket->lastError());
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
$this->assertContains('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->assertNull($this->Socket->lastError());
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
$this->assertContains('127.0.0.1', $this->Socket->addresses());
} catch (SocketException $e) {
$this->markTestSkipped('Cannot test network, skipping.');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -981,7 +981,7 @@ public function testBelongsToManyWithMixedData()

$this->assertTrue($article->tags[0]->isNew());
$this->assertTrue($article->tags[1]->isNew());
$this->assertEquals($article->tags[2]->isNew(), false);
$this->assertFalse($article->tags[2]->isNew());

$tagCount = $tags->find()->count();
$this->articles->save($article);
Expand Down

0 comments on commit ceac931

Please sign in to comment.