@@ -26,9 +26,7 @@ class Job
2626
2727 /** waiting time between process activity check in microseconds */
2828 public const RunSleep = 10000 ;
29- public const
30- RunAsync = 1 ,
31- RunCollectErrors = 2 ;
29+ public const RunAsync = 1 ;
3230
3331 private Test $ test ;
3432 private PhpInterpreter $ interpreter ;
@@ -41,9 +39,7 @@ class Job
4139
4240 /** @var resource|null */
4341 private $ stdout ;
44-
45- /** @var resource|null */
46- private $ stderr ;
42+ private ?string $ stderrFile ;
4743 private int $ exitCode = self ::CodeNone;
4844
4945 /** @var string[] output headers */
@@ -66,6 +62,14 @@ public function __construct(Test $test, PhpInterpreter $interpreter, ?array $env
6662 }
6763
6864
65+ public function setTempDirectory (?string $ path ): void
66+ {
67+ $ this ->stderrFile = $ path === null
68+ ? null
69+ : $ path . DIRECTORY_SEPARATOR . 'Job.pid- ' . getmypid () . '. ' . uniqid () . '.stderr ' ;
70+ }
71+
72+
6973 public function setEnvironmentVariable (string $ name , string $ value ): void
7074 {
7175 $ this ->envVars [$ name ] = $ value ;
@@ -80,7 +84,7 @@ public function getEnvironmentVariable(string $name): string
8084
8185 /**
8286 * Runs single test.
83- * @param int $flags self::RUN_ASYNC | self::RUN_COLLECT_ERRORS
87+ * @param int $flags self::RUN_ASYNC
8488 */
8589 public function run (int $ flags = 0 ): void
8690 {
@@ -102,7 +106,7 @@ public function run(int $flags = 0): void
102106 [
103107 ['pipe ' , 'r ' ],
104108 ['pipe ' , 'w ' ],
105- ['pipe ' , 'w ' ],
109+ $ this -> stderrFile ? [ ' file ' , $ this -> stderrFile , ' w ' ] : ['pipe ' , 'w ' ],
106110 ],
107111 $ pipes ,
108112 dirname ($ this ->test ->getFile ()),
@@ -114,19 +118,15 @@ public function run(int $flags = 0): void
114118 putenv ($ name );
115119 }
116120
117- [$ stdin , $ this ->stdout , $ stderr ] = $ pipes ;
121+ [$ stdin , $ this ->stdout ] = $ pipes ;
118122 fclose ($ stdin );
119- if ($ flags & self ::RunCollectErrors) {
120- $ this ->stderr = $ stderr ;
121- } else {
122- fclose ($ stderr );
123+
124+ if (isset ($ pipes [2 ])) {
125+ fclose ($ pipes [2 ]);
123126 }
124127
125128 if ($ flags & self ::RunAsync) {
126129 stream_set_blocking ($ this ->stdout , false ); // on Windows does not work with proc_open()
127- if ($ this ->stderr ) {
128- stream_set_blocking ($ this ->stderr , false );
129- }
130130 } else {
131131 while ($ this ->isRunning ()) {
132132 usleep (self ::RunSleep); // stream_select() doesn't work with proc_open()
@@ -145,9 +145,6 @@ public function isRunning(): bool
145145 }
146146
147147 $ this ->test ->stdout .= stream_get_contents ($ this ->stdout );
148- if ($ this ->stderr ) {
149- $ this ->test ->stderr .= stream_get_contents ($ this ->stderr );
150- }
151148
152149 $ status = proc_get_status ($ this ->proc );
153150 if ($ status ['running ' ]) {
@@ -157,8 +154,9 @@ public function isRunning(): bool
157154 $ this ->duration += microtime (true );
158155
159156 fclose ($ this ->stdout );
160- if ($ this ->stderr ) {
161- fclose ($ this ->stderr );
157+ if ($ this ->stderrFile ) {
158+ $ this ->test ->stderr .= file_get_contents ($ this ->stderrFile );
159+ unlink ($ this ->stderrFile );
162160 }
163161
164162 $ code = proc_close ($ this ->proc );
0 commit comments