1
1
<?php declare (strict_types=1 );
2
2
3
- namespace Shopware \Tests \Integration \Core \ DevOps \DevOps \StaticAnalyse \Coverage \Command ;
3
+ namespace Shopware \Tests \DevOps \Core \DevOps \StaticAnalyse \Coverage \Command ;
4
4
5
- use Composer \Autoload \ClassLoader ;
6
5
use PHPUnit \Framework \Attributes \After ;
7
6
use PHPUnit \Framework \Attributes \Before ;
8
7
use PHPUnit \Framework \TestCase ;
11
10
use Shopware \Core \DevOps \StaticAnalyze \Coverage \Command \GetClassesPerAreaCommand ;
12
11
use Shopware \Core \Framework \Framework ;
13
12
use Shopware \Core \Framework \Test \TestCaseBase \KernelTestBehaviour ;
14
- use Shopware \Core \Framework \Test \TestCaseHelper \ReflectionHelper ;
15
13
use Shopware \Core \System \System ;
16
14
use Shopware \Elasticsearch \Elasticsearch ;
17
15
use Shopware \Storefront \Storefront ;
18
- use Symfony \Component \Console \Input \ArrayInput ;
19
- use Symfony \Component \Console \Output \BufferedOutput ;
16
+ use Symfony \Component \Console \Tester \CommandTester ;
20
17
use Symfony \Component \Filesystem \Filesystem ;
21
18
use Symfony \Component \Finder \Finder ;
22
19
@@ -31,8 +28,8 @@ class GetClassesPerAreaCommandTest extends TestCase
31
28
#[After]
32
29
public function cleanUp (): void
33
30
{
31
+ $ projectDir = $ _SERVER ['PROJECT_ROOT ' ];
34
32
$ filesystem = new Filesystem ();
35
- $ projectDir = $ this ->getProjectDir ();
36
33
37
34
$ finder = new Finder ();
38
35
$ phpunitFiles = $ finder ->in ($ projectDir )
@@ -43,6 +40,15 @@ public function cleanUp(): void
43
40
$ filesystem ->remove ($ phpunitFiles );
44
41
}
45
42
43
+ protected function setUp (): void
44
+ {
45
+ $ projectDir = $ _SERVER ['PROJECT_ROOT ' ];
46
+
47
+ if (!file_exists ($ projectDir . '/vendor/shopware/core ' ) || !file_exists ($ projectDir . '/vendor/shopware/platform ' )) {
48
+ static ::markTestSkipped ('This test expects shopware installed over composer and does not work with the git setup ' );
49
+ }
50
+ }
51
+
46
52
public function testGetClasses (): void
47
53
{
48
54
// if the test does not find any shopware classes run: composer dump-autoload -o
@@ -107,7 +113,7 @@ public function testGeneratedPhpunitFiles(): void
107
113
}
108
114
109
115
foreach ($ areas as $ area => $ classes ) {
110
- $ phpunitFile = $ this -> getProjectDir () . '/phpunit. ' . $ area . '.xml ' ;
116
+ $ phpunitFile = $ _SERVER [ ' PROJECT_ROOT ' ] . '/phpunit. ' . $ area . '.xml ' ;
111
117
$ coveredFiles = $ this ->getCoveredFiles ($ phpunitFile );
112
118
foreach ($ classes as $ class ) {
113
119
static ::assertContains ((new \ReflectionClass ($ class ))->getFileName (), $ coveredFiles );
@@ -127,29 +133,11 @@ private function isBundleLoaded(string $bundleName): bool
127
133
*/
128
134
private function runCommand (array $ parameters ): string
129
135
{
130
- $ projectDir = $ this -> getProjectDir ( );
136
+ $ tester = new CommandTester ( new GetClassesPerAreaCommand ( $ _SERVER [ ' PROJECT_ROOT ' ]) );
131
137
132
- $ getClassesCommand = new GetClassesPerAreaCommand ($ projectDir );
133
- $ definition = $ getClassesCommand ->getDefinition ();
134
- $ input = new ArrayInput (
135
- $ parameters ,
136
- $ definition
137
- );
138
- $ input ->getOptions ();
139
- $ output = new BufferedOutput ();
140
-
141
- $ refMethod = ReflectionHelper::getMethod (GetClassesPerAreaCommand::class, 'execute ' );
142
- $ refMethod ->invoke ($ getClassesCommand , $ input , $ output );
143
-
144
- return $ output ->fetch ();
145
- }
146
-
147
- private function getProjectDir (): string
148
- {
149
- $ vendorDir = key (ClassLoader::getRegisteredLoaders ());
150
- static ::assertIsString ($ vendorDir );
138
+ $ tester ->execute ($ parameters );
151
139
152
- return \dirname ( $ vendorDir );
140
+ return $ tester -> getDisplay ( );
153
141
}
154
142
155
143
/**
0 commit comments