11
11
use Magento \TestFramework \Workaround \Override \Config ;
12
12
use Magento \TestFramework \Workaround \Override \WrapperGenerator ;
13
13
use PHPUnit \Framework \TestSuite ;
14
+ use PHPUnit \TextUI \Configuration \Configuration as LegacyConfiguration ;
14
15
use PHPUnit \TextUI \Configuration \Registry ;
15
- use PHPUnit \TextUI \Configuration \TestSuiteCollection ;
16
- use PHPUnit \TextUI \Configuration \TestSuiteMapper ;
16
+ use PHPUnit \TextUI \Configuration \TestSuite as LegacyTestSuiteConfiguration ;
17
+ use PHPUnit \TextUI \Configuration \TestSuiteCollection as LegacyTestSuiteCollection ;
18
+ use PHPUnit \TextUI \Configuration \TestSuiteMapper as LegacyTestSuiteMapper ;
19
+ use PHPUnit \TextUI \XmlConfiguration \Configuration ;
20
+ use PHPUnit \TextUI \XmlConfiguration \Loader ;
21
+ use PHPUnit \TextUI \XmlConfiguration \TestSuite as TestSuiteConfiguration ;
22
+ use PHPUnit \TextUI \XmlConfiguration \TestSuiteCollection ;
23
+ use PHPUnit \TextUI \XmlConfiguration \TestSuiteMapper ;
17
24
18
25
/**
19
26
* Integration tests wrapper.
@@ -24,20 +31,20 @@ class IntegrationTest extends TestSuite
24
31
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
25
32
* @param string $className
26
33
* @return TestSuite
34
+ * @throws \ReflectionException
27
35
*/
28
36
public static function suite ($ className )
29
37
{
30
38
$ generator = new WrapperGenerator ();
31
39
$ overrideConfig = Config::getInstance ();
32
- $ configuration = Registry:: getInstance ()-> get ( self ::getConfigurationFile () );
40
+ $ configuration = self ::getConfiguration ( );
33
41
$ suitesConfig = $ configuration ->testSuite ();
34
42
$ suite = new TestSuite ();
35
- /** @var \PHPUnit\TextUI\Configuration\TestSuite $suiteConfig */
36
43
foreach ($ suitesConfig as $ suiteConfig ) {
37
44
if ($ suiteConfig ->name () === 'Magento Integration Tests ' ) {
38
45
continue ;
39
46
}
40
- $ suites = ( new TestSuiteMapper ())-> map (TestSuiteCollection:: fromArray ([ $ suiteConfig]), '' );
47
+ $ suites = self :: getSuites ( $ suiteConfig );
41
48
/** @var TestSuite $testSuite */
42
49
foreach ($ suites as $ testSuite ) {
43
50
/** @var TestSuite $test */
@@ -71,4 +78,39 @@ private static function getConfigurationFile(): string
71
78
72
79
return $ shortConfig ? $ shortConfig : $ longConfig ;
73
80
}
81
+
82
+ /**
83
+ * Retrieve configuration depends on used phpunit version
84
+ *
85
+ * @return Configuration|LegacyConfiguration
86
+ */
87
+ private static function getConfiguration ()
88
+ {
89
+ // Compatibility with phpunit < 9.3
90
+ if (!class_exists (Configuration::class)) {
91
+ // @phpstan-ignore-next-line
92
+ return Registry::getInstance ()->get (self ::getConfigurationFile ());
93
+ }
94
+
95
+ // @phpstan-ignore-next-line
96
+ return (new Loader ())->load (self ::getConfigurationFile ());
97
+ }
98
+
99
+ /**
100
+ * Retrieve test suites by suite config depends on used phpunit version
101
+ *
102
+ * @param TestSuiteConfiguration|LegacyTestSuiteConfiguration $suiteConfig
103
+ * @return TestSuite
104
+ */
105
+ private static function getSuites ($ suiteConfig )
106
+ {
107
+ // Compatibility with phpunit < 9.3
108
+ if (!class_exists (Configuration::class)) {
109
+ // @phpstan-ignore-next-line
110
+ return (new LegacyTestSuiteMapper ())->map (LegacyTestSuiteCollection::fromArray ([$ suiteConfig ]), '' );
111
+ }
112
+
113
+ // @phpstan-ignore-next-line
114
+ return (new TestSuiteMapper ())->map (TestSuiteCollection::fromArray ([$ suiteConfig ]), '' );
115
+ }
74
116
}
0 commit comments