Skip to content

Commit 085a89a

Browse files
authored
Merge pull request #15 from carusogabriel/refactoring-tests
Refactoring tests
2 parents 7fc2f00 + c74cb77 commit 085a89a

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']);
@@ -108,7 +108,7 @@ public function testRemove(LoopInterface $loop, FilesystemInterface $filesystem)
108108
$this->checkIfTimedOut();
109109
} while (!file_exists($tempFile));
110110
$this->await($filesystem->file($tempFile)->remove(), $loop);
111-
$this->assertFalse(file_exists($tempFile));
111+
$this->assertFileNotExists($tempFile);
112112
}
113113

114114
/**
@@ -129,9 +129,9 @@ public function testCreate(LoopInterface $loop, FilesystemInterface $filesystem)
129129
public function testTouch(LoopInterface $loop, FilesystemInterface $filesystem)
130130
{
131131
$tempFile = $this->tmpDir . uniqid('', true);
132-
$this->assertFalse(file_exists($tempFile));
132+
$this->assertFileNotExists($tempFile);
133133
$this->await($filesystem->file($tempFile)->touch(), $loop);
134-
$this->assertTrue(file_exists($tempFile));
134+
$this->assertFileExists($tempFile);
135135
}
136136

137137
/**
@@ -146,7 +146,7 @@ public function testGetContents(LoopInterface $loop, FilesystemInterface $filesy
146146
usleep(500);
147147
$this->checkIfTimedOut();
148148
} while (!file_exists($tempFile));
149-
$this->assertTrue(file_exists($tempFile));
149+
$this->assertFileExists($tempFile);
150150
$fileContents = $this->await($filesystem->file($tempFile)->getContents(), $loop);
151151
$this->assertSame($contents, $fileContents);
152152
}
@@ -164,10 +164,10 @@ public function testCopy(LoopInterface $loop, FilesystemInterface $filesystem)
164164
usleep(500);
165165
$this->checkIfTimedOut();
166166
} while (!file_exists($tempFileSource));
167-
$this->assertTrue(file_exists($tempFileSource));
167+
$this->assertFileExists($tempFileSource);
168168
$this->assertSame($contents, file_get_contents($tempFileSource));
169169
$this->await($filesystem->file($tempFileSource)->copy($filesystem->file($tempFileDestination)), $loop);
170-
$this->assertSame(file_get_contents($tempFileSource), file_get_contents($tempFileDestination));
170+
$this->assertFileEquals($tempFileSource, $tempFileDestination);
171171
}
172172

173173
/**
@@ -185,7 +185,7 @@ public function testCopyToDirectory(LoopInterface $loop, FilesystemInterface $fi
185185
usleep(500);
186186
$this->checkIfTimedOut();
187187
} while (!file_exists($tempFileSource) && !file_exists($tempFileDestination));
188-
$this->assertTrue(file_exists($tempFileSource));
188+
$this->assertFileExists($tempFileSource);
189189
$this->assertSame($contents, file_get_contents($tempFileSource));
190190
$promise = $filesystem->file($tempFileSource)->copy($filesystem->dir($tempFileDestination));
191191
$timer = $loop->addTimer(self::TIMEOUT, function () use ($loop) {
@@ -200,7 +200,7 @@ public function testCopyToDirectory(LoopInterface $loop, FilesystemInterface $fi
200200
usleep(500);
201201
$this->checkIfTimedOut();
202202
} while (!file_exists($tempFileDestination . $filename) || stat($tempFileDestination . $filename)['size'] == 0);
203-
$this->assertSame(file_get_contents($tempFileSource), file_get_contents($tempFileDestination . $filename));
203+
$this->assertFileEquals($tempFileSource, $tempFileDestination . $filename);
204204
}
205205

206206
/**

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)