Skip to content

Commit ceac931

Browse files
committed
Refactoring tests
1 parent 2218373 commit ceac931

File tree

15 files changed

+64
-64
lines changed

15 files changed

+64
-64
lines changed

tests/TestCase/Auth/FallbackPasswordHasherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testCheckWithConfigs()
7373

7474
$hash = $simple->hash('foo');
7575
$legacyHash = $legacy->hash('foo');
76-
$this->assertTrue($hash !== $legacyHash);
76+
$this->assertNotSame($hash, $legacyHash);
7777
$this->assertTrue($hasher->check('foo', $hash));
7878
$this->assertTrue($hasher->check('foo', $legacyHash));
7979
}

tests/TestCase/Cache/CacheTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,13 @@ public function testWriteEmptyValues()
598598
{
599599
$this->_configCache();
600600
Cache::write('App.falseTest', false, 'tests');
601-
$this->assertSame(Cache::read('App.falseTest', 'tests'), false);
601+
$this->assertFalse(Cache::read('App.falseTest', 'tests'));
602602

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

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

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

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

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

675-
$this->assertSame($read['App.falseTest'], false);
676-
$this->assertSame($read['App.trueTest'], false);
677-
$this->assertSame($read['App.nullTest'], false);
678-
$this->assertSame($read['App.zeroTest'], false);
679-
$this->assertSame($read['App.zeroTest2'], false);
675+
$this->assertFalse($read['App.falseTest']);
676+
$this->assertFalse($read['App.trueTest']);
677+
$this->assertFalse($read['App.nullTest']);
678+
$this->assertFalse($read['App.zeroTest']);
679+
$this->assertFalse($read['App.zeroTest2']);
680680
$this->assertSame($read['App.keepTest'], 'keepMe');
681681
}
682682

tests/TestCase/Cache/Engine/MemcachedEngineTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,12 @@ public function testReadMany()
494494

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

497-
$this->assertSame($read['App.falseTest'], false);
498-
$this->assertSame($read['App.trueTest'], true);
499-
$this->assertSame($read['App.nullTest'], null);
497+
$this->assertFalse($read['App.falseTest']);
498+
$this->assertTrue($read['App.trueTest']);
499+
$this->assertNull($read['App.nullTest']);
500500
$this->assertSame($read['App.zeroTest'], 0);
501501
$this->assertSame($read['App.zeroTest2'], '0');
502-
$this->assertSame($read['App.doesNotExist'], false);
502+
$this->assertFalse($read['App.doesNotExist']);
503503
}
504504

505505
/**
@@ -519,9 +519,9 @@ public function testWriteMany()
519519
];
520520
Cache::writeMany($data, 'memcached');
521521

522-
$this->assertSame(Cache::read('App.falseTest', 'memcached'), false);
523-
$this->assertSame(Cache::read('App.trueTest', 'memcached'), true);
524-
$this->assertSame(Cache::read('App.nullTest', 'memcached'), null);
522+
$this->assertFalse(Cache::read('App.falseTest', 'memcached'));
523+
$this->assertTrue(Cache::read('App.trueTest', 'memcached'));
524+
$this->assertNull(Cache::read('App.nullTest', 'memcached'));
525525
$this->assertSame(Cache::read('App.zeroTest', 'memcached'), 0);
526526
$this->assertSame(Cache::read('App.zeroTest2', 'memcached'), '0');
527527
}
@@ -608,11 +608,11 @@ public function testDeleteMany()
608608

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

611-
$this->assertSame(Cache::read('App.falseTest', 'memcached'), false);
612-
$this->assertSame(Cache::read('App.trueTest', 'memcached'), false);
613-
$this->assertSame(Cache::read('App.nullTest', 'memcached'), false);
614-
$this->assertSame(Cache::read('App.zeroTest', 'memcached'), false);
615-
$this->assertSame(Cache::read('App.zeroTest2', 'memcached'), false);
611+
$this->assertFalse(Cache::read('App.falseTest', 'memcached'));
612+
$this->assertFalse(Cache::read('App.trueTest', 'memcached'));
613+
$this->assertFalse(Cache::read('App.nullTest', 'memcached'));
614+
$this->assertFalse(Cache::read('App.zeroTest', 'memcached'));
615+
$this->assertFalse(Cache::read('App.zeroTest2', 'memcached'));
616616
$this->assertSame(Cache::read('App.keepTest', 'memcached'), 'keepMe');
617617
}
618618

tests/TestCase/Console/ConsoleIoTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ public function testCreateFileSuccess()
589589

590590
$this->assertTrue($result);
591591
$this->assertFileExists($file);
592-
$this->assertEquals($contents, file_get_contents($file));
592+
$this->assertStringEqualsFile($file, $contents);
593593
}
594594

595595
/**
@@ -660,7 +660,7 @@ public function testCreateFileOverwriteNo()
660660

661661
$this->assertFalse($result);
662662
$this->assertFileExists($file);
663-
$this->assertEquals('original', file_get_contents($file));
663+
$this->assertStringEqualsFile($file, 'original');
664664
}
665665

666666
/**
@@ -682,7 +682,7 @@ public function testCreateFileOverwriteParam()
682682

683683
$this->assertTrue($result);
684684
$this->assertFileExists($file);
685-
$this->assertEquals($contents, file_get_contents($file));
685+
$this->assertStringEqualsFile($file, $contents);
686686
}
687687

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

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

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

712712
$this->io->createFile($file, 'newest content', false);
713-
$this->assertEquals(
713+
$this->assertStringEqualsFile(
714+
$file,
714715
'newest content',
715-
file_get_contents($file),
716716
'overwrite state replaces parameter'
717717
);
718718
}

tests/TestCase/Console/ShellTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ public function testCreateFileNonInteractive()
583583
$result = $this->Shell->createFile($file, $contents);
584584
$this->assertTrue($result);
585585
$this->assertFileExists($file);
586-
$this->assertEquals(file_get_contents($file), $contents);
586+
$this->assertStringEqualsFile($file, $contents);
587587
}
588588

589589
/**
@@ -660,7 +660,7 @@ public function testCreateFileOverwriteNonInteractive()
660660
$this->Shell->interactive = false;
661661
$result = $this->Shell->createFile($file, 'My content');
662662
$this->assertTrue($result);
663-
$this->assertEquals(file_get_contents($file), 'My content');
663+
$this->assertStringEqualsFile($file, 'My content');
664664
}
665665

666666
/**

tests/TestCase/Core/ConfigureTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testRead()
108108
$this->assertEquals('something_else', $result);
109109

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

113113
$result = Configure::read();
114114
$this->assertInternalType('array', $result);
@@ -198,7 +198,7 @@ public function testDelete()
198198

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

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

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

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

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

220220
/**
@@ -482,7 +482,7 @@ public function testEngineSetup()
482482
Configure::config('test', $engine);
483483
$configured = Configure::configured();
484484

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

487487
$this->assertTrue(Configure::configured('test'));
488488
$this->assertFalse(Configure::configured('fake_garbage'));

tests/TestCase/Filesystem/FileTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function testRead()
183183
$result = $this->File->read();
184184
$expecting = file_get_contents(__FILE__);
185185
$this->assertEquals($expecting, $result);
186-
$this->assertTrue(!is_resource($this->File->handle));
186+
$this->assertNotInternalType('resource', $this->File->handle);
187187

188188
$this->File->lock = true;
189189
$result = $this->File->read();
@@ -251,12 +251,12 @@ public function testOpen()
251251
$handle = $this->File->handle;
252252
$r = $this->File->open();
253253
$this->assertTrue($r);
254-
$this->assertTrue($handle === $this->File->handle);
254+
$this->assertSame($handle, $this->File->handle);
255255
$this->assertInternalType('resource', $this->File->handle);
256256

257257
$r = $this->File->open('r', true);
258258
$this->assertTrue($r);
259-
$this->assertFalse($handle === $this->File->handle);
259+
$this->assertNotSame($handle, $this->File->handle);
260260
$this->assertInternalType('resource', $this->File->handle);
261261
}
262262

@@ -442,7 +442,7 @@ public function testWrite()
442442
$r = $TmpFile->write($data);
443443
$this->assertTrue($r);
444444
$this->assertFileExists($tmpFile);
445-
$this->assertEquals($data, file_get_contents($tmpFile));
445+
$this->assertStringEqualsFile($tmpFile, $data);
446446
$this->assertInternalType('resource', $TmpFile->handle);
447447
$TmpFile->close();
448448
}
@@ -474,15 +474,15 @@ public function testAppend()
474474
$this->assertTrue($r);
475475
$this->assertFileExists($tmpFile);
476476
$data = $data . $fragment;
477-
$this->assertEquals($data, file_get_contents($tmpFile));
477+
$this->assertStringEqualsFile($tmpFile, $data);
478478
$newSize = $TmpFile->size();
479479
$this->assertTrue($newSize > $size);
480480
$size = $newSize;
481481
$TmpFile->close();
482482
}
483483

484484
$TmpFile->append('');
485-
$this->assertEquals($data, file_get_contents($tmpFile));
485+
$this->assertStringEqualsFile($tmpFile, $data);
486486
$TmpFile->close();
487487
}
488488

tests/TestCase/Filesystem/FolderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,8 @@ public function testCopyWithSkip()
10681068
$result = $Folder->copy(['to' => $folderThree, 'scheme' => Folder::SKIP]);
10691069
$this->assertTrue($result);
10701070
$this->assertFileExists($folderThree . DS . 'file2.php');
1071-
$this->assertEquals('touched', file_get_contents($folderThree . DS . 'file2.php'));
1072-
$this->assertEquals('untouched', file_get_contents($folderThree . DS . 'folderB' . DS . 'fileB.php'));
1071+
$this->assertStringEqualsFile($folderThree . DS . 'file2.php', 'touched');
1072+
$this->assertStringEqualsFile($folderThree . DS . 'folderB' . DS . 'fileB.php', 'untouched');
10731073
}
10741074

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

10981098
/**
@@ -1260,7 +1260,7 @@ public function testMove()
12601260
$result = $Folder->move($folderTwo);
12611261
$this->assertTrue($result);
12621262
$this->assertFileExists($folderTwo . '/file1.php');
1263-
$this->assertEquals('', file_get_contents($folderTwoB . '/fileB.php'));
1263+
$this->assertStringEqualsFile($folderTwoB . '/fileB.php', '');
12641264
$this->assertFileNotExists($fileOne);
12651265
$this->assertFileNotExists($folderOneA);
12661266
$this->assertFileNotExists($fileOneA);
@@ -1327,7 +1327,7 @@ public function testMoveWithSkip()
13271327
$result = $Folder->move(['to' => $folderTwo, 'scheme' => Folder::SKIP]);
13281328
$this->assertTrue($result);
13291329
$this->assertFileExists($folderTwo . '/file1.php');
1330-
$this->assertEquals('untouched', file_get_contents($folderTwoB . '/fileB.php'));
1330+
$this->assertStringEqualsFile($folderTwoB . '/fileB.php', 'untouched');
13311331
$this->assertFileNotExists($fileOne);
13321332
$this->assertFileNotExists($folderOneA);
13331333
$this->assertFileNotExists($fileOneA);

tests/TestCase/Http/ResponseTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ public function testCompress()
718718
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip';
719719
$result = $response->compress();
720720
$this->assertTrue($result);
721-
$this->assertTrue(in_array('ob_gzhandler', ob_list_handlers()));
721+
$this->assertContains('ob_gzhandler', ob_list_handlers());
722722

723723
ob_get_clean();
724724
}
@@ -2039,7 +2039,7 @@ public function testFileWithDownloadAndName()
20392039
$result = $response->send();
20402040
$output = ob_get_clean();
20412041
$this->assertEquals("/* this is the test asset css file */\n", $output);
2042-
$this->assertNotSame(false, $result);
2042+
$this->assertNotFalse($result);
20432043
$this->assertEquals('text/css', $response->getType());
20442044
$this->assertEquals('bytes', $response->getHeaderLine('Accept-Ranges'));
20452045
$this->assertEquals('binary', $response->getHeaderLine('Content-Transfer-Encoding'));
@@ -2075,7 +2075,7 @@ public function testFileWithUnknownFileTypeGeneric()
20752075
$result = $response->send();
20762076
$output = ob_get_clean();
20772077
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
2078-
$this->assertNotSame(false, $result);
2078+
$this->assertNotFalse($result);
20792079
$this->assertEquals('text/html', $response->getType());
20802080
$this->assertEquals('bytes', $response->getHeaderLine('Accept-Ranges'));
20812081
$this->assertEquals('binary', $response->getHeaderLine('Content-Transfer-Encoding'));
@@ -2131,7 +2131,7 @@ public function testFileWithUnknownFileTypeOpera()
21312131
$result = $response->send();
21322132
$output = ob_get_clean();
21332133
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
2134-
$this->assertNotSame(false, $result);
2134+
$this->assertNotFalse($result);
21352135
$this->assertEquals('application/octet-stream', $response->getType());
21362136
$this->assertEquals('bytes', $response->getHeaderLine('Accept-Ranges'));
21372137
$this->assertEquals('binary', $response->getHeaderLine('Content-Transfer-Encoding'));
@@ -2187,7 +2187,7 @@ public function testFileWithUnknownFileTypeIE()
21872187
$result = $response->send();
21882188
$output = ob_get_clean();
21892189
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
2190-
$this->assertNotSame(false, $result);
2190+
$this->assertNotFalse($result);
21912191
$this->assertEquals('application/force-download', $response->getType());
21922192
$this->assertEquals('bytes', $response->getHeaderLine('Accept-Ranges'));
21932193
$this->assertEquals('binary', $response->getHeaderLine('Content-Transfer-Encoding'));
@@ -2459,7 +2459,7 @@ public function testFileRange()
24592459
$result = $response->send();
24602460
$output = ob_get_clean();
24612461
$this->assertEquals('is the test asset ', $output);
2462-
$this->assertNotSame(false, $result);
2462+
$this->assertNotFalse($result);
24632463

24642464
$this->assertEquals(
24652465
'attachment; filename="test_asset.css"',
@@ -2707,7 +2707,7 @@ public function testFileRangeNoDownload()
27072707
$this->assertEquals('text/css', $response->getType());
27082708
$this->assertEquals(206, $response->getStatusCode());
27092709
$this->assertEquals('is the test asset ', $output);
2710-
$this->assertNotSame(false, $result);
2710+
$this->assertNotFalse($result);
27112711
});
27122712
}
27132713

tests/TestCase/Http/SessionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public function testReadingSavedEmpty()
450450

451451
$session->write('SessionTestCase', '0');
452452
$this->assertEquals('0', $session->read('SessionTestCase'));
453-
$this->assertFalse($session->read('SessionTestCase') === 0);
453+
$this->assertNotSame($session->read('SessionTestCase'), 0);
454454

455455
$session->write('SessionTestCase', false);
456456
$this->assertFalse($session->read('SessionTestCase'));

tests/TestCase/Network/SocketTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ public function testSocketHost()
143143
$this->assertEquals('127.0.0.1', $this->Socket->address());
144144
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
145145
$this->assertNull($this->Socket->lastError());
146-
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
146+
$this->assertContains('127.0.0.1', $this->Socket->addresses());
147147

148148
$this->Socket = new Socket(['host' => '127.0.0.1']);
149149
$this->Socket->connect();
150150
$this->assertEquals('127.0.0.1', $this->Socket->address());
151151
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
152152
$this->assertNull($this->Socket->lastError());
153-
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
153+
$this->assertContains('127.0.0.1', $this->Socket->addresses());
154154
} catch (SocketException $e) {
155155
$this->markTestSkipped('Cannot test network, skipping.');
156156
}

tests/TestCase/ORM/MarshallerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ public function testBelongsToManyWithMixedData()
981981

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

986986
$tagCount = $tags->find()->count();
987987
$this->articles->save($article);

0 commit comments

Comments
 (0)