Skip to content

Commit c74cb77

Browse files
committed
Refactoring tests
1 parent 01128b7 commit c74cb77

6 files changed

Lines changed: 33 additions & 33 deletions

File tree

tests/Adapters/DirectoryTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testCreate(LoopInterface $loop, FilesystemInterface $filesystem)
6969
{
7070
$dir = $this->tmpDir . 'path';
7171
$this->await($filesystem->dir($dir)->createRecursive(), $loop);
72-
$this->assertTrue(file_exists($dir));
72+
$this->assertFileExists($dir);
7373
$this->assertSame('0760', substr(sprintf('%o', fileperms($dir)), -4));
7474
}
7575

@@ -80,7 +80,7 @@ public function testCreateRecursive(LoopInterface $loop, FilesystemInterface $fi
8080
{
8181
$dir = $this->tmpDir . 'path' . DIRECTORY_SEPARATOR . 'to' . DIRECTORY_SEPARATOR . 'reactphp' . DIRECTORY_SEPARATOR . 'filesystem';
8282
$this->await($filesystem->dir($dir)->createRecursive(), $loop);
83-
$this->assertTrue(file_exists($dir));
83+
$this->assertFileExists($dir);
8484
}
8585

8686
/**
@@ -90,9 +90,9 @@ public function testRemove(LoopInterface $loop, FilesystemInterface $filesystem)
9090
{
9191
$dir = $this->tmpDir . 'path';
9292
mkdir($dir);
93-
$this->assertTrue(file_exists($dir));
93+
$this->assertFileExists($dir);
9494
$this->await($filesystem->dir($dir)->remove(), $loop);
95-
$this->assertFalse(file_exists($dir));
95+
$this->assertFileNotExists($dir);
9696
}
9797

9898
/**
@@ -104,11 +104,11 @@ public function testRemoveSubDir(LoopInterface $loop, FilesystemInterface $files
104104
$subDir = $this->tmpDir . 'path' . DIRECTORY_SEPARATOR . 'sub';
105105
mkdir($dir);
106106
mkdir($subDir);
107-
$this->assertTrue(file_exists($dir));
108-
$this->assertTrue(file_exists($subDir));
107+
$this->assertFileExists($dir);
108+
$this->assertFileExists($subDir);
109109
$this->await($filesystem->dir($subDir)->remove(), $loop);
110-
$this->assertTrue(file_exists($dir));
111-
$this->assertFalse(file_exists($subDir));
110+
$this->assertFileExists($dir);
111+
$this->assertFileNotExists($subDir);
112112
}
113113

114114
/**
@@ -120,11 +120,11 @@ public function testRemoveRecursive(LoopInterface $loop, FilesystemInterface $fi
120120
$subDir = $this->tmpDir . 'path' . DIRECTORY_SEPARATOR . 'sub';
121121
mkdir($dir);
122122
mkdir($subDir);
123-
$this->assertTrue(file_exists($dir));
124-
$this->assertTrue(file_exists($subDir));
123+
$this->assertFileExists($dir);
124+
$this->assertFileExists($subDir);
125125
$this->await($filesystem->dir($dir)->removeRecursive(), $loop);
126-
$this->assertFalse(file_exists($subDir));
127-
$this->assertFalse(file_exists($dir));
126+
$this->assertFileNotExists($subDir);
127+
$this->assertFileNotExists($dir);
128128
}
129129

130130
/**
@@ -138,8 +138,8 @@ public function testChmod(LoopInterface $loop, FilesystemInterface $filesystem)
138138
mkdir($subDir);
139139
chmod($dir, 0777);
140140
chmod($subDir, 0777);
141-
$this->assertTrue(file_exists($dir));
142-
$this->assertTrue(file_exists($subDir));
141+
$this->assertFileExists($dir);
142+
$this->assertFileExists($subDir);
143143
$this->assertSame('0777', substr(sprintf('%o', fileperms($dir)), -4));
144144
$this->assertSame('0777', substr(sprintf('%o', fileperms($subDir)), -4));
145145
clearstatcache();
@@ -161,8 +161,8 @@ public function testChmodRecursive(LoopInterface $loop, FilesystemInterface $fil
161161
mkdir($subDir);
162162
chmod($dir, 0777);
163163
chmod($subDir, 0777);
164-
$this->assertTrue(file_exists($dir));
165-
$this->assertTrue(file_exists($subDir));
164+
$this->assertFileExists($dir);
165+
$this->assertFileExists($subDir);
166166
$this->assertSame('0777', substr(sprintf('%o', fileperms($dir)), -4));
167167
$this->assertSame('0777', substr(sprintf('%o', fileperms($subDir)), -4));
168168
clearstatcache();
@@ -183,8 +183,8 @@ public function testChown(LoopInterface $loop, FilesystemInterface $filesystem)
183183
mkdir($dir, 0777);
184184
mkdir($subDir, 0777);
185185
clearstatcache();
186-
$this->assertTrue(file_exists($dir));
187-
$this->assertTrue(file_exists($subDir));
186+
$this->assertFileExists($dir);
187+
$this->assertFileExists($subDir);
188188
clearstatcache();
189189
$stat = stat($dir);
190190
sleep(2);
@@ -203,8 +203,8 @@ public function testChownRecursive(LoopInterface $loop, FilesystemInterface $fil
203203
$subDir = $this->tmpDir . 'path' . DIRECTORY_SEPARATOR . 'sub';
204204
mkdir($dir, 0777);
205205
mkdir($subDir, 0777);
206-
$this->assertTrue(file_exists($dir));
207-
$this->assertTrue(file_exists($subDir));
206+
$this->assertFileExists($dir);
207+
$this->assertFileExists($subDir);
208208
clearstatcache();
209209
$stat = stat($dir);
210210
$subStat = stat($subDir);

tests/Adapters/FileTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testTime(LoopInterface $loop, FilesystemInterface $filesystem)
4343
{
4444
$actualStat = lstat(__FILE__);
4545
$result = $this->await($filesystem->file(__FILE__)->time(), $loop);
46-
$this->assertSame(3, count($result));
46+
$this->assertCount(3, $result);
4747
$this->assertInstanceOf('DateTime', $result['atime']);
4848
$this->assertEquals($actualStat['atime'], $result['atime']->format('U'));
4949
$this->assertInstanceOf('DateTime', $result['mtime']);
@@ -105,7 +105,7 @@ public function testRemove(LoopInterface $loop, FilesystemInterface $filesystem)
105105
$this->checkIfTimedOut();
106106
} while (!file_exists($tempFile));
107107
$this->await($filesystem->file($tempFile)->remove(), $loop);
108-
$this->assertFalse(file_exists($tempFile));
108+
$this->assertFileNotExists($tempFile);
109109
}
110110

111111
/**
@@ -126,9 +126,9 @@ public function testCreate(LoopInterface $loop, FilesystemInterface $filesystem)
126126
public function testTouch(LoopInterface $loop, FilesystemInterface $filesystem)
127127
{
128128
$tempFile = $this->tmpDir . uniqid('', true);
129-
$this->assertFalse(file_exists($tempFile));
129+
$this->assertFileNotExists($tempFile);
130130
$this->await($filesystem->file($tempFile)->touch(), $loop);
131-
$this->assertTrue(file_exists($tempFile));
131+
$this->assertFileExists($tempFile);
132132
}
133133

134134
/**
@@ -143,7 +143,7 @@ public function testGetContents(LoopInterface $loop, FilesystemInterface $filesy
143143
usleep(500);
144144
$this->checkIfTimedOut();
145145
} while (!file_exists($tempFile));
146-
$this->assertTrue(file_exists($tempFile));
146+
$this->assertFileExists($tempFile);
147147
$fileContents = $this->await($filesystem->file($tempFile)->getContents(), $loop);
148148
$this->assertSame($contents, $fileContents);
149149
}
@@ -161,10 +161,10 @@ public function testCopy(LoopInterface $loop, FilesystemInterface $filesystem)
161161
usleep(500);
162162
$this->checkIfTimedOut();
163163
} while (!file_exists($tempFileSource));
164-
$this->assertTrue(file_exists($tempFileSource));
164+
$this->assertFileExists($tempFileSource);
165165
$this->assertSame($contents, file_get_contents($tempFileSource));
166166
$this->await($filesystem->file($tempFileSource)->copy($filesystem->file($tempFileDestination)), $loop);
167-
$this->assertSame(file_get_contents($tempFileSource), file_get_contents($tempFileDestination));
167+
$this->assertFileEquals($tempFileSource, $tempFileDestination);
168168
}
169169

170170
/**
@@ -182,7 +182,7 @@ public function testCopyToDirectory(LoopInterface $loop, FilesystemInterface $fi
182182
usleep(500);
183183
$this->checkIfTimedOut();
184184
} while (!file_exists($tempFileSource) && !file_exists($tempFileDestination));
185-
$this->assertTrue(file_exists($tempFileSource));
185+
$this->assertFileExists($tempFileSource);
186186
$this->assertSame($contents, file_get_contents($tempFileSource));
187187
$promise = $filesystem->file($tempFileSource)->copy($filesystem->dir($tempFileDestination));
188188
$timer = $loop->addTimer(self::TIMEOUT, function () use ($loop) {
@@ -197,7 +197,7 @@ public function testCopyToDirectory(LoopInterface $loop, FilesystemInterface $fi
197197
usleep(500);
198198
$this->checkIfTimedOut();
199199
} while (!file_exists($tempFileDestination . $filename) || stat($tempFileDestination . $filename)['size'] == 0);
200-
$this->assertSame(file_get_contents($tempFileSource), file_get_contents($tempFileDestination . $filename));
200+
$this->assertFileEquals($tempFileSource, $tempFileDestination . $filename);
201201
}
202202

203203
/**

tests/ChildProcess/ProcessTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testStat()
5050
'mtime',
5151
'ctime',
5252
] as $item) {
53-
$this->assertTrue(isset($result[$item]));
53+
$this->assertArrayHasKey($item, $result);
5454
}
5555
$resultCallbackRan = true;
5656
});

tests/Eio/ConstTypeDetectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testDetectUnknown()
6262
(new ConstTypeDetector($filesystem))->detect([
6363
'type' => 123,
6464
])->otherwise(function ($result) use (&$callbackFired) {
65-
$this->assertSame(null, $result);
65+
$this->assertNull($result);
6666
$callbackFired = true;
6767
});
6868

tests/ModeTypeDetectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testDetectUnknown()
6969
(new ModeTypeDetector($filesystem))->detect([
7070
'path' => 'foo.bar',
7171
])->otherwise(function ($result) use (&$callbackFired) {
72-
$this->assertSame(null, $result);
72+
$this->assertNull($result);
7373
$callbackFired = true;
7474
});
7575

tests/Stream/WritableStreamTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testIsNotWritable($className)
8989

9090
$stream = (new $className($path, $fd, $filesystem));
9191
$stream->close();
92-
$this->assertTrue(!$stream->isWritable());
92+
$this->assertFalse($stream->isWritable());
9393
}
9494

9595
/**

0 commit comments

Comments
 (0)