Skip to content

Commit 60ca357

Browse files
committed
NEXT-35982 - Add devops tests to integration job
1 parent 310851d commit 60ca357

File tree

14 files changed

+35
-79
lines changed

14 files changed

+35
-79
lines changed

.gitlab/stages/20-unit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ PHP integration:
9191
--configuration phpunit.xml.dist
9292
--log-junit phpunit.junit.xml
9393
--exclude-group=needsWebserver,skip-paratest,not-deterministic
94-
--testsuite integration
94+
--testsuite integration,devops
9595
--order-by default
9696

9797
PHP bench:

phpstan.neon.dist

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ parameters:
8686
- src/**/*Test.php
8787
- tests/performance/**/*Bench.php
8888
- tests/unit/**/*Test.php
89+
- tests/devops/**/*Test.php
8990
- tests/integration/**/*Test.php
9091
- tests/integration/**/*TestCase.php
9192

tests/integration/Core/DevOps/Docs/Command/App/DocsAppEventCommandTest.php tests/devops/Core/DevOps/Docs/Command/App/DocsAppEventCommandTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php declare(strict_types=1);
22

3-
namespace Shopware\Tests\Integration\Core\DevOps\Docs\Command\App;
3+
namespace Shopware\Tests\DevOps\Core\DevOps\Docs\Command\App;
44

55
use PHPUnit\Framework\Attributes\CoversClass;
66
use PHPUnit\Framework\TestCase;
77
use Shopware\Core\DevOps\Docs\App\DocsAppEventCommand;
8-
use Shopware\Core\Framework\Feature;
98
use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour;
109

1110
/**

tests/integration/Core/DevOps/Docs/Command/Script/ScriptReferenceGeneratorTest.php tests/devops/Core/DevOps/Docs/Command/Script/ScriptReferenceGeneratorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Shopware\Tests\Integration\Core\DevOps\Docs\Command\Script;
3+
namespace Shopware\Tests\DevOps\Core\DevOps\Docs\Command\Script;
44

55
use PHPUnit\Framework\Attributes\CoversClass;
66
use PHPUnit\Framework\TestCase;

tests/integration/Core/DevOps/DevOps/StaticAnalyse/Coverage/Command/GetClassesPerAreaCommandTest.php tests/devops/Core/DevOps/StaticAnalyse/Coverage/Command/GetClassesPerAreaCommandTest.php

+16-28
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php declare(strict_types=1);
22

3-
namespace Shopware\Tests\Integration\Core\DevOps\DevOps\StaticAnalyse\Coverage\Command;
3+
namespace Shopware\Tests\DevOps\Core\DevOps\StaticAnalyse\Coverage\Command;
44

5-
use Composer\Autoload\ClassLoader;
65
use PHPUnit\Framework\Attributes\After;
76
use PHPUnit\Framework\Attributes\Before;
87
use PHPUnit\Framework\TestCase;
@@ -11,12 +10,10 @@
1110
use Shopware\Core\DevOps\StaticAnalyze\Coverage\Command\GetClassesPerAreaCommand;
1211
use Shopware\Core\Framework\Framework;
1312
use Shopware\Core\Framework\Test\TestCaseBase\KernelTestBehaviour;
14-
use Shopware\Core\Framework\Test\TestCaseHelper\ReflectionHelper;
1513
use Shopware\Core\System\System;
1614
use Shopware\Elasticsearch\Elasticsearch;
1715
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;
2017
use Symfony\Component\Filesystem\Filesystem;
2118
use Symfony\Component\Finder\Finder;
2219

@@ -31,8 +28,8 @@ class GetClassesPerAreaCommandTest extends TestCase
3128
#[After]
3229
public function cleanUp(): void
3330
{
31+
$projectDir = $_SERVER['PROJECT_ROOT'];
3432
$filesystem = new Filesystem();
35-
$projectDir = $this->getProjectDir();
3633

3734
$finder = new Finder();
3835
$phpunitFiles = $finder->in($projectDir)
@@ -43,6 +40,15 @@ public function cleanUp(): void
4340
$filesystem->remove($phpunitFiles);
4441
}
4542

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+
4652
public function testGetClasses(): void
4753
{
4854
// if the test does not find any shopware classes run: composer dump-autoload -o
@@ -107,7 +113,7 @@ public function testGeneratedPhpunitFiles(): void
107113
}
108114

109115
foreach ($areas as $area => $classes) {
110-
$phpunitFile = $this->getProjectDir() . '/phpunit.' . $area . '.xml';
116+
$phpunitFile = $_SERVER['PROJECT_ROOT'] . '/phpunit.' . $area . '.xml';
111117
$coveredFiles = $this->getCoveredFiles($phpunitFile);
112118
foreach ($classes as $class) {
113119
static::assertContains((new \ReflectionClass($class))->getFileName(), $coveredFiles);
@@ -127,29 +133,11 @@ private function isBundleLoaded(string $bundleName): bool
127133
*/
128134
private function runCommand(array $parameters): string
129135
{
130-
$projectDir = $this->getProjectDir();
136+
$tester = new CommandTester(new GetClassesPerAreaCommand($_SERVER['PROJECT_ROOT']));
131137

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);
151139

152-
return \dirname($vendorDir);
140+
return $tester->getDisplay();
153141
}
154142

155143
/**

tests/integration/Core/DevOps/DevOps/StaticAnalyse/Coverage/Command/GetJSFilesPerAreaCommandTest.php tests/devops/Core/DevOps/StaticAnalyse/Coverage/Command/GetJSFilesPerAreaCommandTest.php

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<?php declare(strict_types=1);
22

3-
namespace Shopware\Tests\Integration\Core\DevOps\DevOps\StaticAnalyse\Coverage\Command;
3+
namespace Shopware\Tests\DevOps\Core\DevOps\StaticAnalyse\Coverage\Command;
44

55
use PHPUnit\Framework\Attributes\DataProvider;
66
use PHPUnit\Framework\TestCase;
77
use Shopware\Administration\Administration;
88
use Shopware\Core\DevOps\StaticAnalyze\Coverage\Command\GetJSFilesPerAreaCommand;
9-
use Shopware\Core\Framework\Test\TestCaseHelper\ReflectionHelper;
10-
use Symfony\Component\Console\Input\ArrayInput;
11-
use Symfony\Component\Console\Output\BufferedOutput;
9+
use Symfony\Component\Console\Tester\CommandTester;
1210

1311
/**
1412
* @internal
@@ -67,18 +65,10 @@ public static function pathAreaDataProvider(): array
6765
*/
6866
private function runCommand(array $parameters): string
6967
{
70-
$getClassesCommand = new GetJSFilesPerAreaCommand();
71-
$definition = $getClassesCommand->getDefinition();
72-
$input = new ArrayInput(
73-
$parameters,
74-
$definition
75-
);
76-
$input->getOptions();
77-
$output = new BufferedOutput();
68+
$tester = new CommandTester(new GetJSFilesPerAreaCommand());
7869

79-
$refMethod = ReflectionHelper::getMethod(GetJSFilesPerAreaCommand::class, 'execute');
80-
$refMethod->invoke($getClassesCommand, $input, $output);
70+
$tester->execute($parameters);
8171

82-
return $output->fetch();
72+
return $tester->getDisplay();
8373
}
8474
}

tests/integration/Core/DevOps/DevOps/StaticAnalyse/Coverage/Command/SummarizeCoverageReportsTest.php tests/devops/Core/DevOps/StaticAnalyse/Coverage/Command/SummarizeCoverageReportsTest.php

+10-32
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<?php declare(strict_types=1);
22

3-
namespace Shopware\Tests\Integration\Core\DevOps\DevOps\StaticAnalyse\Coverage\Command;
3+
namespace Shopware\Tests\DevOps\Core\DevOps\StaticAnalyse\Coverage\Command;
44

5-
use Composer\Autoload\ClassLoader;
65
use PHPUnit\Framework\Attributes\After;
76
use PHPUnit\Framework\Attributes\Before;
87
use PHPUnit\Framework\TestCase;
98
use Shopware\Core\DevOps\StaticAnalyze\Coverage\Command\SummarizeCoverageReports;
10-
use Shopware\Core\Framework\Test\TestCaseHelper\ReflectionHelper;
11-
use Symfony\Component\Console\Input\ArrayInput;
12-
use Symfony\Component\Console\Output\BufferedOutput;
9+
use Symfony\Component\Console\Tester\CommandTester;
1310
use Symfony\Component\Filesystem\Filesystem;
1411
use Twig\Environment;
1512
use Twig\Loader\ArrayLoader;
@@ -23,7 +20,7 @@ class SummarizeCoverageReportsTest extends TestCase
2320
public function copyFixtures(): void
2421
{
2522
$filesystem = new Filesystem();
26-
$projectDir = $this->getProjectDir();
23+
$projectDir = $_SERVER['PROJECT_ROOT'];
2724

2825
$filesystem->mirror(__DIR__ . '/_fixtures/coverage', $projectDir . '/coverage');
2926
}
@@ -32,7 +29,7 @@ public function copyFixtures(): void
3229
public function deleteTestFiles(): void
3330
{
3431
$filesystem = new Filesystem();
35-
$projectDir = $this->getProjectDir();
32+
$projectDir = $_SERVER['PROJECT_ROOT'];
3633

3734
$filesystem->remove($projectDir . '/coverage');
3835
$filesystem->remove($projectDir . '/coverageSummary.html');
@@ -41,9 +38,9 @@ public function deleteTestFiles(): void
4138

4239
public function testSummarize(): void
4340
{
44-
$this->runCommand([]);
41+
$this->runCommand();
4542

46-
$projectDir = $this->getProjectDir();
43+
$projectDir = $_SERVER['PROJECT_ROOT'];
4744

4845
static::assertFileExists($projectDir . '/coverageSummary.json');
4946
static::assertFileExists($projectDir . '/coverageSummary.html');
@@ -109,31 +106,12 @@ public function testSummarize(): void
109106
], $coverageReport['js']);
110107
}
111108

112-
/**
113-
* @param mixed[] $parameters
114-
*/
115-
private function runCommand(array $parameters): string
109+
private function runCommand(): string
116110
{
117-
$getClassesCommand = new SummarizeCoverageReports($this->getProjectDir(), new Environment(new ArrayLoader()));
118-
$definition = $getClassesCommand->getDefinition();
119-
$input = new ArrayInput(
120-
$parameters,
121-
$definition
122-
);
123-
$input->getOptions();
124-
$output = new BufferedOutput();
125-
126-
$refMethod = ReflectionHelper::getMethod(SummarizeCoverageReports::class, 'execute');
127-
$refMethod->invoke($getClassesCommand, $input, $output);
128-
129-
return $output->fetch();
130-
}
111+
$tester = new CommandTester(new SummarizeCoverageReports($_SERVER['PROJECT_ROOT'], new Environment(new ArrayLoader())));
131112

132-
private function getProjectDir(): string
133-
{
134-
$vendorDir = key(ClassLoader::getRegisteredLoaders());
135-
static::assertIsString($vendorDir);
113+
$tester->execute([]);
136114

137-
return \dirname($vendorDir);
115+
return $tester->getDisplay();
138116
}
139117
}

0 commit comments

Comments
 (0)