Skip to content

Commit

Permalink
Merge pull request #4 from open-source-contributions/enhance_tests
Browse files Browse the repository at this point in the history
Enhance temp file initialization for tests
  • Loading branch information
devtronic committed Sep 10, 2019
2 parents b7e85d7 + 543cd3f commit 27f1f91
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tests/FileStreamTest.php
Expand Up @@ -17,6 +17,13 @@

class FileStreamTest extends TestCase
{
protected $tempFile;

protected function setUp()
{
$this->tempFile = tempnam(sys_get_temp_dir(), 'stream_test');
}

public function testConstructor()
{
$stream = new FileStream(__FILE__, true, false);
Expand All @@ -26,17 +33,12 @@ public function testConstructor()
$this->assertFalse($stream->isWritable());
$stream->close();

$tempFile = tempnam(sys_get_temp_dir(), 'stream_test');
$stream = new FileStream($tempFile, true, true);
$stream = new FileStream($this->tempFile, true, true);
$this->assertInstanceOf(StreamInterface::class, $stream);
$this->assertEquals(0, $stream->getSize());
$this->assertTrue($stream->isReadable());
$this->assertTrue($stream->isWritable());
$stream->close();

if (is_file($tempFile)) {
@unlink($tempFile);
}
}

public function testConstructorFailsNoFile()
Expand All @@ -45,4 +47,9 @@ public function testConstructorFailsNoFile()
$this->expectExceptionMessage('fopen(21312asd): failed to open stream: No such file or directory');
new FileStream('21312asd', true, false);
}
}

protected function tearDown()
{
unlink($this->tempFile);
}
}

0 comments on commit 27f1f91

Please sign in to comment.