kodedphp /
http
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Tests\Koded\Http; |
||
| 4 | |||
| 5 | use Koded\Http\FileStream; |
||
| 6 | use PHPUnit\Framework\TestCase; |
||
| 7 | use RuntimeException; |
||
| 8 | |||
| 9 | class FileStreamTest extends TestCase |
||
| 10 | { |
||
| 11 | private string $file = '/tmp/test'; |
||
| 12 | |||
| 13 | public function test_should_create_only_writable_stream() |
||
| 14 | { |
||
| 15 | $this->expectException(RuntimeException::class); |
||
| 16 | $this->expectExceptionMessage('The stream is not readable'); |
||
| 17 | |||
| 18 | $stream = new FileStream($this->file, 'w'); |
||
| 19 | $stream->write('hello world'); |
||
| 20 | |||
| 21 | $this->assertSame('w', $stream->getMetadata('mode')); |
||
| 22 | $this->assertSame('', $stream->getContents()); |
||
| 23 | |||
| 24 | $this->assertFalse($stream->isReadable()); |
||
| 25 | $this->assertFalse($stream->isSeekable()); |
||
| 26 | $this->assertTrue($stream->isWritable()); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function test_should_create_read_write_stream_by_default() |
||
| 30 | { |
||
| 31 | $stream = new FileStream($this->file, 'w+'); |
||
| 32 | $stream->write('hello world'); |
||
| 33 | |||
| 34 | $this->assertSame('w+', $stream->getMetadata('mode')); |
||
| 35 | $this->assertSame('hello world', $stream->getContents()); |
||
| 36 | |||
| 37 | $this->assertTrue($stream->isReadable()); |
||
| 38 | $this->assertTrue($stream->isSeekable()); |
||
| 39 | $this->assertTrue($stream->isWritable()); |
||
| 40 | } |
||
| 41 | |||
| 42 | protected function tearDown(): void |
||
| 43 | { |
||
| 44 | @unlink($this->file); |
||
|
0 ignored issues
–
show
|
|||
| 45 | } |
||
| 46 | } |
||
| 47 |
If you suppress an error, we recommend checking for the error condition explicitly: