File tree Expand file tree Collapse file tree 3 files changed +52
-4
lines changed Expand file tree Collapse file tree 3 files changed +52
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace PhpBench \Pipeline \Tests \Unit \Extension \Core ;
4
4
5
- use PHPUnit \Framework \TestCase ;
6
5
use PhpBench \Pipeline \Core \PipelineBuilder ;
7
6
use PhpBench \Pipeline \Extension \Core \CoreExtension ;
7
+ use PhpBench \Pipeline \Tests \Unit \PipelineTestCase ;
8
8
9
- class CoreTestCase extends TestCase
9
+ class CoreTestCase extends PipelineTestCase
10
10
{
11
11
protected function pipeline (): PipelineBuilder
12
12
{
Original file line number Diff line number Diff line change 7
7
8
8
class StreamOutputTest extends CoreTestCase
9
9
{
10
+ private $ path ;
11
+
12
+ public function setUp ()
13
+ {
14
+ $ this ->clearWorkspace ();
15
+ $ this ->path = $ this ->workspacePath ('test.log ' );;
16
+ }
17
+
10
18
public function testWritesToStream ()
11
19
{
12
20
$ result = $ this ->pipeline ()
13
- ->stage ('output/stream ' , ['stream ' => ' php://temp ' ])
21
+ ->stage ('output/stream ' , ['stream ' => $ this -> path ])
14
22
->generator (['hello ' ])->current ();
15
23
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 ));
17
36
}
18
37
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments