From c74cb772b570cf9ca2dacb88cae69ac217ce3556 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Fri, 1 Dec 2017 11:44:28 -0200 Subject: [PATCH] Refactoring tests --- tests/Adapters/DirectoryTest.php | 40 ++++++++++++++--------------- tests/Adapters/FileTest.php | 18 ++++++------- tests/ChildProcess/ProcessTest.php | 2 +- tests/Eio/ConstTypeDetectorTest.php | 2 +- tests/ModeTypeDetectorTest.php | 2 +- tests/Stream/WritableStreamTest.php | 2 +- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/Adapters/DirectoryTest.php b/tests/Adapters/DirectoryTest.php index fe58cc9b..e08c9a59 100644 --- a/tests/Adapters/DirectoryTest.php +++ b/tests/Adapters/DirectoryTest.php @@ -69,7 +69,7 @@ public function testCreate(LoopInterface $loop, FilesystemInterface $filesystem) { $dir = $this->tmpDir . 'path'; $this->await($filesystem->dir($dir)->createRecursive(), $loop); - $this->assertTrue(file_exists($dir)); + $this->assertFileExists($dir); $this->assertSame('0760', substr(sprintf('%o', fileperms($dir)), -4)); } @@ -80,7 +80,7 @@ public function testCreateRecursive(LoopInterface $loop, FilesystemInterface $fi { $dir = $this->tmpDir . 'path' . DIRECTORY_SEPARATOR . 'to' . DIRECTORY_SEPARATOR . 'reactphp' . DIRECTORY_SEPARATOR . 'filesystem'; $this->await($filesystem->dir($dir)->createRecursive(), $loop); - $this->assertTrue(file_exists($dir)); + $this->assertFileExists($dir); } /** @@ -90,9 +90,9 @@ public function testRemove(LoopInterface $loop, FilesystemInterface $filesystem) { $dir = $this->tmpDir . 'path'; mkdir($dir); - $this->assertTrue(file_exists($dir)); + $this->assertFileExists($dir); $this->await($filesystem->dir($dir)->remove(), $loop); - $this->assertFalse(file_exists($dir)); + $this->assertFileNotExists($dir); } /** @@ -104,11 +104,11 @@ public function testRemoveSubDir(LoopInterface $loop, FilesystemInterface $files $subDir = $this->tmpDir . 'path' . DIRECTORY_SEPARATOR . 'sub'; mkdir($dir); mkdir($subDir); - $this->assertTrue(file_exists($dir)); - $this->assertTrue(file_exists($subDir)); + $this->assertFileExists($dir); + $this->assertFileExists($subDir); $this->await($filesystem->dir($subDir)->remove(), $loop); - $this->assertTrue(file_exists($dir)); - $this->assertFalse(file_exists($subDir)); + $this->assertFileExists($dir); + $this->assertFileNotExists($subDir); } /** @@ -120,11 +120,11 @@ public function testRemoveRecursive(LoopInterface $loop, FilesystemInterface $fi $subDir = $this->tmpDir . 'path' . DIRECTORY_SEPARATOR . 'sub'; mkdir($dir); mkdir($subDir); - $this->assertTrue(file_exists($dir)); - $this->assertTrue(file_exists($subDir)); + $this->assertFileExists($dir); + $this->assertFileExists($subDir); $this->await($filesystem->dir($dir)->removeRecursive(), $loop); - $this->assertFalse(file_exists($subDir)); - $this->assertFalse(file_exists($dir)); + $this->assertFileNotExists($subDir); + $this->assertFileNotExists($dir); } /** @@ -138,8 +138,8 @@ public function testChmod(LoopInterface $loop, FilesystemInterface $filesystem) mkdir($subDir); chmod($dir, 0777); chmod($subDir, 0777); - $this->assertTrue(file_exists($dir)); - $this->assertTrue(file_exists($subDir)); + $this->assertFileExists($dir); + $this->assertFileExists($subDir); $this->assertSame('0777', substr(sprintf('%o', fileperms($dir)), -4)); $this->assertSame('0777', substr(sprintf('%o', fileperms($subDir)), -4)); clearstatcache(); @@ -161,8 +161,8 @@ public function testChmodRecursive(LoopInterface $loop, FilesystemInterface $fil mkdir($subDir); chmod($dir, 0777); chmod($subDir, 0777); - $this->assertTrue(file_exists($dir)); - $this->assertTrue(file_exists($subDir)); + $this->assertFileExists($dir); + $this->assertFileExists($subDir); $this->assertSame('0777', substr(sprintf('%o', fileperms($dir)), -4)); $this->assertSame('0777', substr(sprintf('%o', fileperms($subDir)), -4)); clearstatcache(); @@ -183,8 +183,8 @@ public function testChown(LoopInterface $loop, FilesystemInterface $filesystem) mkdir($dir, 0777); mkdir($subDir, 0777); clearstatcache(); - $this->assertTrue(file_exists($dir)); - $this->assertTrue(file_exists($subDir)); + $this->assertFileExists($dir); + $this->assertFileExists($subDir); clearstatcache(); $stat = stat($dir); sleep(2); @@ -203,8 +203,8 @@ public function testChownRecursive(LoopInterface $loop, FilesystemInterface $fil $subDir = $this->tmpDir . 'path' . DIRECTORY_SEPARATOR . 'sub'; mkdir($dir, 0777); mkdir($subDir, 0777); - $this->assertTrue(file_exists($dir)); - $this->assertTrue(file_exists($subDir)); + $this->assertFileExists($dir); + $this->assertFileExists($subDir); clearstatcache(); $stat = stat($dir); $subStat = stat($subDir); diff --git a/tests/Adapters/FileTest.php b/tests/Adapters/FileTest.php index 863677c7..6462df33 100644 --- a/tests/Adapters/FileTest.php +++ b/tests/Adapters/FileTest.php @@ -43,7 +43,7 @@ public function testTime(LoopInterface $loop, FilesystemInterface $filesystem) { $actualStat = lstat(__FILE__); $result = $this->await($filesystem->file(__FILE__)->time(), $loop); - $this->assertSame(3, count($result)); + $this->assertCount(3, $result); $this->assertInstanceOf('DateTime', $result['atime']); $this->assertEquals($actualStat['atime'], $result['atime']->format('U')); $this->assertInstanceOf('DateTime', $result['mtime']); @@ -105,7 +105,7 @@ public function testRemove(LoopInterface $loop, FilesystemInterface $filesystem) $this->checkIfTimedOut(); } while (!file_exists($tempFile)); $this->await($filesystem->file($tempFile)->remove(), $loop); - $this->assertFalse(file_exists($tempFile)); + $this->assertFileNotExists($tempFile); } /** @@ -126,9 +126,9 @@ public function testCreate(LoopInterface $loop, FilesystemInterface $filesystem) public function testTouch(LoopInterface $loop, FilesystemInterface $filesystem) { $tempFile = $this->tmpDir . uniqid('', true); - $this->assertFalse(file_exists($tempFile)); + $this->assertFileNotExists($tempFile); $this->await($filesystem->file($tempFile)->touch(), $loop); - $this->assertTrue(file_exists($tempFile)); + $this->assertFileExists($tempFile); } /** @@ -143,7 +143,7 @@ public function testGetContents(LoopInterface $loop, FilesystemInterface $filesy usleep(500); $this->checkIfTimedOut(); } while (!file_exists($tempFile)); - $this->assertTrue(file_exists($tempFile)); + $this->assertFileExists($tempFile); $fileContents = $this->await($filesystem->file($tempFile)->getContents(), $loop); $this->assertSame($contents, $fileContents); } @@ -161,10 +161,10 @@ public function testCopy(LoopInterface $loop, FilesystemInterface $filesystem) usleep(500); $this->checkIfTimedOut(); } while (!file_exists($tempFileSource)); - $this->assertTrue(file_exists($tempFileSource)); + $this->assertFileExists($tempFileSource); $this->assertSame($contents, file_get_contents($tempFileSource)); $this->await($filesystem->file($tempFileSource)->copy($filesystem->file($tempFileDestination)), $loop); - $this->assertSame(file_get_contents($tempFileSource), file_get_contents($tempFileDestination)); + $this->assertFileEquals($tempFileSource, $tempFileDestination); } /** @@ -182,7 +182,7 @@ public function testCopyToDirectory(LoopInterface $loop, FilesystemInterface $fi usleep(500); $this->checkIfTimedOut(); } while (!file_exists($tempFileSource) && !file_exists($tempFileDestination)); - $this->assertTrue(file_exists($tempFileSource)); + $this->assertFileExists($tempFileSource); $this->assertSame($contents, file_get_contents($tempFileSource)); $promise = $filesystem->file($tempFileSource)->copy($filesystem->dir($tempFileDestination)); $timer = $loop->addTimer(self::TIMEOUT, function () use ($loop) { @@ -197,7 +197,7 @@ public function testCopyToDirectory(LoopInterface $loop, FilesystemInterface $fi usleep(500); $this->checkIfTimedOut(); } while (!file_exists($tempFileDestination . $filename) || stat($tempFileDestination . $filename)['size'] == 0); - $this->assertSame(file_get_contents($tempFileSource), file_get_contents($tempFileDestination . $filename)); + $this->assertFileEquals($tempFileSource, $tempFileDestination . $filename); } /** diff --git a/tests/ChildProcess/ProcessTest.php b/tests/ChildProcess/ProcessTest.php index 645ff05c..a3bfa27a 100644 --- a/tests/ChildProcess/ProcessTest.php +++ b/tests/ChildProcess/ProcessTest.php @@ -50,7 +50,7 @@ public function testStat() 'mtime', 'ctime', ] as $item) { - $this->assertTrue(isset($result[$item])); + $this->assertArrayHasKey($item, $result); } $resultCallbackRan = true; }); diff --git a/tests/Eio/ConstTypeDetectorTest.php b/tests/Eio/ConstTypeDetectorTest.php index 7c675b3d..e8a51a67 100644 --- a/tests/Eio/ConstTypeDetectorTest.php +++ b/tests/Eio/ConstTypeDetectorTest.php @@ -62,7 +62,7 @@ public function testDetectUnknown() (new ConstTypeDetector($filesystem))->detect([ 'type' => 123, ])->otherwise(function ($result) use (&$callbackFired) { - $this->assertSame(null, $result); + $this->assertNull($result); $callbackFired = true; }); diff --git a/tests/ModeTypeDetectorTest.php b/tests/ModeTypeDetectorTest.php index c195c37d..4777b6bf 100644 --- a/tests/ModeTypeDetectorTest.php +++ b/tests/ModeTypeDetectorTest.php @@ -69,7 +69,7 @@ public function testDetectUnknown() (new ModeTypeDetector($filesystem))->detect([ 'path' => 'foo.bar', ])->otherwise(function ($result) use (&$callbackFired) { - $this->assertSame(null, $result); + $this->assertNull($result); $callbackFired = true; }); diff --git a/tests/Stream/WritableStreamTest.php b/tests/Stream/WritableStreamTest.php index baef7552..094da399 100644 --- a/tests/Stream/WritableStreamTest.php +++ b/tests/Stream/WritableStreamTest.php @@ -89,7 +89,7 @@ public function testIsNotWritable($className) $stream = (new $className($path, $fd, $filesystem)); $stream->close(); - $this->assertTrue(!$stream->isWritable()); + $this->assertFalse($stream->isWritable()); } /**