File tree 6 files changed +118
-2
lines changed
6 files changed +118
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
All notable changes of the PHPUnit 10.5 release series are documented in this file using the [ Keep a CHANGELOG] ( https://keepachangelog.com/ ) principles.
4
4
5
+ ## [ 10.5.10] - 2024-MM-DD
6
+
7
+ ### Fixed
8
+
9
+ * [ #5692 ] ( https://github.com/sebastianbergmann/phpunit/issues/5692 ) : ` --log-events-text ` and ` --log-events-verbose-text ` require the destination file to exit
10
+
5
11
## [ 10.5.9] - 2024-01-22
6
12
7
13
### Fixed
@@ -97,6 +103,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
97
103
98
104
* [ #5563 ] ( https://github.com/sebastianbergmann/phpunit/issues/5563 ) : ` createMockForIntersectionOfInterfaces() ` does not automatically register mock object for expectation verification
99
105
106
+ [ 10.5.10 ] : https://github.com/sebastianbergmann/phpunit/compare/10.5.9...10.5
100
107
[ 10.5.9 ] : https://github.com/sebastianbergmann/phpunit/compare/10.5.8...10.5.9
101
108
[ 10.5.8 ] : https://github.com/sebastianbergmann/phpunit/compare/10.5.7...10.5.8
102
109
[ 10.5.7 ] : https://github.com/sebastianbergmann/phpunit/compare/10.5.6...10.5.7
Original file line number Diff line number Diff line change 17
17
use function is_numeric ;
18
18
use function sprintf ;
19
19
use PHPUnit \Runner \TestSuiteSorter ;
20
+ use PHPUnit \Util \Filesystem ;
20
21
use SebastianBergmann \CliParser \Exception as CliParserException ;
21
22
use SebastianBergmann \CliParser \Parser as CliParser ;
22
23
@@ -805,12 +806,30 @@ public function fromParameters(array $parameters): Configuration
805
806
break ;
806
807
807
808
case '--log-events-text ' :
808
- $ logEventsText = $ option [1 ];
809
+ $ logEventsText = Filesystem::resolveStreamOrFile ($ option [1 ]);
810
+
811
+ if ($ logEventsText === false ) {
812
+ throw new Exception (
813
+ sprintf (
814
+ 'The path "%s" specified for the --log-events-text option could not be resolved ' ,
815
+ $ option [1 ],
816
+ ),
817
+ );
818
+ }
809
819
810
820
break ;
811
821
812
822
case '--log-events-verbose-text ' :
813
- $ logEventsVerboseText = $ option [1 ];
823
+ $ logEventsVerboseText = Filesystem::resolveStreamOrFile ($ option [1 ]);
824
+
825
+ if ($ logEventsVerboseText === false ) {
826
+ throw new Exception (
827
+ sprintf (
828
+ 'The path "%s" specified for the --log-events-verbose-text option could not be resolved ' ,
829
+ $ option [1 ],
830
+ ),
831
+ );
832
+ }
814
833
815
834
break ;
816
835
Original file line number Diff line number Diff line change 9
9
*/
10
10
namespace PHPUnit \Util ;
11
11
12
+ use function basename ;
13
+ use function dirname ;
12
14
use function is_dir ;
13
15
use function mkdir ;
16
+ use function realpath ;
17
+ use function str_starts_with ;
14
18
15
19
/**
16
20
* @internal This class is not covered by the backward compatibility promise for PHPUnit
@@ -21,4 +25,24 @@ public static function createDirectory(string $directory): bool
21
25
{
22
26
return !(!is_dir ($ directory ) && !@mkdir ($ directory , 0o777 , true ) && !is_dir ($ directory ));
23
27
}
28
+
29
+ /**
30
+ * @psalm-param non-empty-string $path
31
+ *
32
+ * @return false|non-empty-string
33
+ */
34
+ public static function resolveStreamOrFile (string $ path ): false |string
35
+ {
36
+ if (str_starts_with ($ path , 'php:// ' ) || str_starts_with ($ path , 'socket:// ' )) {
37
+ return $ path ;
38
+ }
39
+
40
+ $ directory = dirname ($ path );
41
+
42
+ if (is_dir ($ directory )) {
43
+ return realpath ($ directory ) . DIRECTORY_SEPARATOR . basename ($ path );
44
+ }
45
+
46
+ return false ;
47
+ }
24
48
}
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test fails with invalid path
3
+ --FILE--
4
+ <?php declare (strict_types=1 );
5
+ $ traceFile = sys_get_temp_dir () . '/invalid-directory/invalid.file ' ;
6
+
7
+ $ _SERVER ['argv ' ][] = '--do-not-cache-result ' ;
8
+ $ _SERVER ['argv ' ][] = '--no-configuration ' ;
9
+ $ _SERVER ['argv ' ][] = '--no-output ' ;
10
+ $ _SERVER ['argv ' ][] = '--log-events-text ' ;
11
+ $ _SERVER ['argv ' ][] = $ traceFile ;
12
+
13
+ require __DIR__ . '/../../bootstrap.php ' ;
14
+
15
+ (new PHPUnit \TextUI \Application )->run ($ _SERVER ['argv ' ]);
16
+ --EXPECTF --
17
+ PHPUnit %s by Sebastian Bergmann and contributors.
18
+
19
+ The path "%s " specified for the --log-events-text option could not be resolved
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test fails with invalid path
3
+ --FILE--
4
+ <?php declare (strict_types=1 );
5
+ $ traceFile = sys_get_temp_dir () . '/invalid-directory/invalid.file ' ;
6
+
7
+ $ _SERVER ['argv ' ][] = '--do-not-cache-result ' ;
8
+ $ _SERVER ['argv ' ][] = '--no-configuration ' ;
9
+ $ _SERVER ['argv ' ][] = '--no-output ' ;
10
+ $ _SERVER ['argv ' ][] = '--log-events-verbose-text ' ;
11
+ $ _SERVER ['argv ' ][] = $ traceFile ;
12
+
13
+ require __DIR__ . '/../../bootstrap.php ' ;
14
+
15
+ (new PHPUnit \TextUI \Application )->run ($ _SERVER ['argv ' ]);
16
+ --EXPECTF --
17
+ PHPUnit %s by Sebastian Bergmann and contributors.
18
+
19
+ The path "%s " specified for the --log-events-verbose-text option could not be resolved
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /*
3
+ * This file is part of PHPUnit.
4
+ *
5
+ * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ namespace PHPUnit \Util ;
11
+
12
+ use PHPUnit \Framework \Attributes \CoversClass ;
13
+ use PHPUnit \Framework \Attributes \Small ;
14
+ use PHPUnit \Framework \TestCase ;
15
+
16
+ #[CoversClass(Filesystem::class)]
17
+ #[Small]
18
+ final class FilesystemTest extends TestCase
19
+ {
20
+ public function testCanResolveStreamOrFile (): void
21
+ {
22
+ $ this ->assertSame ('php://stdout ' , Filesystem::resolveStreamOrFile ('php://stdout ' ));
23
+ $ this ->assertSame ('socket://hostname:port ' , Filesystem::resolveStreamOrFile ('socket://hostname:port ' ));
24
+ $ this ->assertSame (__FILE__ , Filesystem::resolveStreamOrFile (__FILE__ ));
25
+ $ this ->assertSame (__DIR__ . '/does-not-exist ' , Filesystem::resolveStreamOrFile (__DIR__ . '/does-not-exist ' ));
26
+ $ this ->assertFalse (Filesystem::resolveStreamOrFile (__DIR__ . '/does-not-exist/does-not-exist ' ));
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments