99 */
1010namespace PHPUnit \TextUI \Configuration ;
1111
12- use Webmozart \Glob \Glob ;
1312use function array_map ;
13+ use function basename ;
14+ use function dirname ;
15+ use function preg_match ;
16+ use function rtrim ;
17+ use function sprintf ;
18+ use function str_ends_with ;
19+ use function str_starts_with ;
20+ use Webmozart \Glob \Glob ;
1421
1522/**
1623 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@@ -44,6 +51,23 @@ public static function instance(): self
4451 return self ::$ instance ;
4552 }
4653
54+ /**
55+ * Convert the directory filter to a glob.
56+ *
57+ * To ensure that `foo/**` will match `foo/bar.php` we match both the
58+ * globstar and the wildcard.
59+ */
60+ public static function toGlob (FilterDirectory $ directory ): string
61+ {
62+ $ path = rtrim ($ directory ->path (), '/ ' );
63+
64+ return sprintf (
65+ '{(%s)|(%s)} ' ,
66+ Glob::toRegEx (sprintf ('%s/**/* ' , $ path ), 0 , '' ),
67+ Glob::toRegEx (sprintf ('%s/* ' , $ path ), 0 , '' ),
68+ );
69+ }
70+
4771 public function __construct (Source $ source )
4872 {
4973 $ this ->source = $ source ;
@@ -63,8 +87,9 @@ public function __construct(Source $source)
6387 public function includes (string $ path ): bool
6488 {
6589 $ included = false ;
66- $ dirPath = rtrim (dirname ($ path ), '/ ' ) . '/ ' ;
90+ $ dirPath = rtrim (dirname ($ path ), '/ ' ) . '/ ' ;
6791 $ filename = basename ($ path );
92+
6893 foreach ($ this ->source ->includeFiles () as $ file ) {
6994 if ($ file ->path () === $ path ) {
7095 $ included = true ;
@@ -92,23 +117,6 @@ public function includes(string $path): bool
92117 return $ included ;
93118 }
94119
95- /**
96- * Convert the directory filter to a glob.
97- *
98- * To ensure that `foo/**` will match `foo/bar.php` we match both the
99- * globstar and the wildcard.
100- */
101- public static function toGlob (FilterDirectory $ directory ): string
102- {
103- $ path = rtrim ($ directory ->path (), '/ ' );
104-
105- return sprintf (
106- '{(%s)|(%s)} ' ,
107- Glob::toRegEx (sprintf ('%s/**/* ' , $ path ), 0 , '' ),
108- Glob::toRegEx (sprintf ('%s/* ' , $ path ), 0 , '' ),
109- );
110- }
111-
112120 private static function filenameMatches (FilterDirectory $ directory , string $ filename ): bool
113121 {
114122 return str_starts_with ($ filename , $ directory ->prefix ()) && str_ends_with ($ filename , $ directory ->suffix ());
0 commit comments