@@ -27,9 +27,7 @@ class Job
2727 /** waiting time between process activity check in microseconds */
2828 public const RUN_USLEEP = 10000 ;
2929
30- public const
31- RUN_ASYNC = 1 ,
32- RUN_COLLECT_ERRORS = 2 ;
30+ public const RUN_ASYNC = 1 ;
3331
3432 /** @var Test */
3533 private $ test ;
@@ -46,8 +44,8 @@ class Job
4644 /** @var resource|null */
4745 private $ stdout ;
4846
49- /** @var resource |null */
50- private $ stderr ;
47+ /** @var string |null */
48+ private $ stderrFile ;
5149
5250 /** @var int */
5351 private $ exitCode = self ::CODE_NONE ;
@@ -74,6 +72,14 @@ public function __construct(Test $test, PhpInterpreter $interpreter, ?array $env
7472 }
7573
7674
75+ public function setTempDirectory (?string $ path ): void
76+ {
77+ $ this ->stderrFile = $ path === null
78+ ? null
79+ : $ path . DIRECTORY_SEPARATOR . 'Job.pid- ' . getmypid () . '. ' . uniqid () . '.stderr ' ;
80+ }
81+
82+
7783 public function setEnvironmentVariable (string $ name , string $ value ): void
7884 {
7985 $ this ->envVars [$ name ] = $ value ;
@@ -88,7 +94,7 @@ public function getEnvironmentVariable(string $name): string
8894
8995 /**
9096 * Runs single test.
91- * @param int $flags self::RUN_ASYNC | self::RUN_COLLECT_ERRORS
97+ * @param int $flags self::RUN_ASYNC
9298 */
9399 public function run (int $ flags = 0 ): void
94100 {
@@ -110,7 +116,7 @@ public function run(int $flags = 0): void
110116 [
111117 ['pipe ' , 'r ' ],
112118 ['pipe ' , 'w ' ],
113- ['pipe ' , 'w ' ],
119+ $ this -> stderrFile ? [ ' file ' , $ this -> stderrFile , ' w ' ] : ['pipe ' , 'w ' ],
114120 ],
115121 $ pipes ,
116122 dirname ($ this ->test ->getFile ()),
@@ -122,19 +128,15 @@ public function run(int $flags = 0): void
122128 putenv ($ name );
123129 }
124130
125- [$ stdin , $ this ->stdout , $ stderr ] = $ pipes ;
131+ [$ stdin , $ this ->stdout ] = $ pipes ;
126132 fclose ($ stdin );
127- if ($ flags & self ::RUN_COLLECT_ERRORS ) {
128- $ this ->stderr = $ stderr ;
129- } else {
130- fclose ($ stderr );
133+
134+ if (isset ($ pipes [2 ])) {
135+ fclose ($ pipes [2 ]);
131136 }
132137
133138 if ($ flags & self ::RUN_ASYNC ) {
134139 stream_set_blocking ($ this ->stdout , false ); // on Windows does not work with proc_open()
135- if ($ this ->stderr ) {
136- stream_set_blocking ($ this ->stderr , false );
137- }
138140 } else {
139141 while ($ this ->isRunning ()) {
140142 usleep (self ::RUN_USLEEP ); // stream_select() doesn't work with proc_open()
@@ -153,9 +155,6 @@ public function isRunning(): bool
153155 }
154156
155157 $ this ->test ->stdout .= stream_get_contents ($ this ->stdout );
156- if ($ this ->stderr ) {
157- $ this ->test ->stderr .= stream_get_contents ($ this ->stderr );
158- }
159158
160159 $ status = proc_get_status ($ this ->proc );
161160 if ($ status ['running ' ]) {
@@ -165,8 +164,9 @@ public function isRunning(): bool
165164 $ this ->duration += microtime (true );
166165
167166 fclose ($ this ->stdout );
168- if ($ this ->stderr ) {
169- fclose ($ this ->stderr );
167+ if ($ this ->stderrFile ) {
168+ $ this ->test ->stderr .= file_get_contents ($ this ->stderrFile );
169+ unlink ($ this ->stderrFile );
170170 }
171171
172172 $ code = proc_close ($ this ->proc );
0 commit comments