Skip to content

Commit df920be

Browse files
committed
Test reading and writing from and to binary files
1 parent 35bf3e6 commit df920be

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/Adapters/FileTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ public function testGetContents(LoopInterface $loop, FilesystemInterface $filesy
151151
$this->assertSame($contents, $fileContents);
152152
}
153153

154+
/**
155+
* @dataProvider filesystemProvider
156+
*/
157+
public function testGetBinaryContents(LoopInterface $loop, FilesystemInterface $filesystem)
158+
{
159+
$file = __DIR__ . DIRECTORY_SEPARATOR . 'reactphp-logo.png';
160+
$this->assertFileExists($file);
161+
$fileContents = $this->await($filesystem->file($file)->getContents(), $loop);
162+
$this->assertSame(file_get_contents($file), $fileContents);
163+
}
164+
154165
/**
155166
* @dataProvider filesystemProvider
156167
*/
@@ -257,4 +268,16 @@ public function testPutContents(LoopInterface $loop, FilesystemInterface $filesy
257268
$this->assertFileExists($tempFile);
258269
$this->assertSame($contents, file_get_contents($tempFile));
259270
}
271+
/**
272+
* @dataProvider filesystemProvider
273+
*/
274+
public function testPutBinaryContents(LoopInterface $loop, FilesystemInterface $filesystem)
275+
{
276+
$contents = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'reactphp-logo.png');
277+
$filename = uniqid('', true);
278+
$tempFile = $this->tmpDir . $filename;
279+
$this->await($filesystem->file($tempFile)->putContents($contents), $loop);
280+
$this->assertFileExists($tempFile);
281+
$this->assertSame($contents, file_get_contents($tempFile));
282+
}
260283
}

tests/Adapters/reactphp-logo.png

57.5 KB
Loading

0 commit comments

Comments
 (0)