Skip to content

Commit 329a429

Browse files
committed
Properly testing stream
1 parent 8539509 commit 329a429

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

tests/Unit/Extension/Core/CoreTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace PhpBench\Pipeline\Tests\Unit\Extension\Core;
44

5-
use PHPUnit\Framework\TestCase;
65
use PhpBench\Pipeline\Core\PipelineBuilder;
76
use PhpBench\Pipeline\Extension\Core\CoreExtension;
7+
use PhpBench\Pipeline\Tests\Unit\PipelineTestCase;
88

9-
class CoreTestCase extends TestCase
9+
class CoreTestCase extends PipelineTestCase
1010
{
1111
protected function pipeline(): PipelineBuilder
1212
{

tests/Unit/Extension/Core/Stage/Output/StreamOutputTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,31 @@
77

88
class StreamOutputTest extends CoreTestCase
99
{
10+
private $path;
11+
12+
public function setUp()
13+
{
14+
$this->clearWorkspace();
15+
$this->path = $this->workspacePath('test.log');;
16+
}
17+
1018
public function testWritesToStream()
1119
{
1220
$result = $this->pipeline()
13-
->stage('output/stream', ['stream' => 'php://temp'])
21+
->stage('output/stream', ['stream' => $this->path])
1422
->generator(['hello'])->current();
1523

16-
$this->assertEquals(['hello'], $result);
24+
$contents = file_get_contents($this->path);
25+
$this->assertEquals('hello', trim($contents));
26+
}
27+
28+
public function testSerializesNonScalarValues()
29+
{
30+
$result = $this->pipeline()
31+
->stage('output/stream', ['stream' => $this->path])
32+
->generator([ [ 'hello' ] ])->current();
33+
34+
$contents = file_get_contents($this->path);
35+
$this->assertEquals('a:1:{i:0;s:5:"hello";}', trim($contents));
1736
}
1837
}

tests/Unit/PipelineTestCase.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace PhpBench\Pipeline\Tests\Unit;
4+
5+
use Symfony\Component\Filesystem\Filesystem;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class PipelineTestCase extends TestCase
9+
{
10+
public function workspaceDir()
11+
{
12+
return __DIR__ . '/../Workspace';
13+
}
14+
15+
public function workspacePath(string $path)
16+
{
17+
return $this->workspaceDir() . '/' . $path;
18+
}
19+
20+
public function clearWorkspace()
21+
{
22+
if (file_exists($this->workspaceDir())) {
23+
$filesystem = new Filesystem();
24+
$filesystem->remove($this->workspaceDir());
25+
}
26+
27+
mkdir($this->workspaceDir());
28+
}
29+
}

0 commit comments

Comments
 (0)