File tree Expand file tree Collapse file tree 1 file changed +33
-2
lines changed Expand file tree Collapse file tree 1 file changed +33
-2
lines changed Original file line number Diff line number Diff line change 1111
1212namespace FOS \HttpCache \Test ;
1313
14+ use PHPUnit \Event \Code \TestMethod ;
1415use PHPUnit \Event \TestRunner \ExecutionStarted ;
1516use PHPUnit \Event \TestRunner \ExecutionStartedSubscriber ;
17+ use PHPUnit \Event \TestSuite \TestSuite ;
18+ use PHPUnit \Metadata \Group ;
1619
1720class WebServerSubscriber implements ExecutionStartedSubscriber
1821{
1922 /**
2023 * PHP web server PID.
2124 */
2225 private int $ pid ;
26+ private bool $ isTopLevel = true ;
2327
2428 public function notify (ExecutionStarted $ event ): void
2529 {
26- if (isset ($ this ->pid )) {
27- // TODO: can we detect if 'webserver' is in the list of groups of the test suite?
30+ if (!$ this ->isTopLevel ) {
31+ return ;
32+ }
33+ $ this ->isTopLevel = false ;
34+
35+ if (isset ($ this ->pid )
36+ || !$ this ->hasTestsWithGroup ($ event ->testSuite (), 'webserver ' )
37+ ) {
2838 return ;
2939 }
3040
@@ -35,6 +45,27 @@ public function notify(ExecutionStarted $event): void
3545 });
3646 }
3747
48+ private function hasTestsWithGroup (TestSuite $ testSuite , string $ group ): bool
49+ {
50+ foreach ($ testSuite ->tests () as $ test ) {
51+ if (!$ test ->isTestMethod ()) {
52+ continue ;
53+ }
54+
55+ assert ($ test instanceof TestMethod);
56+
57+ foreach ($ test ->metadata ()->isGroup () as $ testGroup ) {
58+ assert ($ testGroup instanceof Group);
59+
60+ if ($ testGroup ->groupName () === $ group ) {
61+ return true ;
62+ }
63+ }
64+ }
65+
66+ return false ;
67+ }
68+
3869 /**
3970 * Start PHP built-in web server.
4071 *
You can’t perform that action at this time.
0 commit comments