-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathPostBuildTest.php
More file actions
126 lines (102 loc) Β· 6.37 KB
/
Copy pathPostBuildTest.php
File metadata and controls
126 lines (102 loc) Β· 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
declare(strict_types=1);
namespace DrevOps\Vortex\Tests\Functional;
use DrevOps\Vortex\Tests\Traits\CircleCiTrait;
use PHPUnit\Framework\Attributes\Group;
/**
* Tests CircleCI post-build artifacts and test results.
*
* These tests verify that the build job properly generates and stores
* artifacts and test results in CircleCI.
*/
class PostBuildTest extends FunctionalTestCase {
use CircleCiTrait;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
if (empty(getenv('CIRCLECI'))) {
$this->markTestSkipped('This test is only run on CircleCI');
}
// Verify required environment variables are set.
$this->assertNotEmpty(getenv('TEST_CIRCLECI_TOKEN'), 'CircleCI token is not set');
$this->assertNotEmpty(getenv('CIRCLE_PROJECT_REPONAME'), 'CircleCI project repo name is not set');
$this->assertNotEmpty(getenv('CIRCLE_PROJECT_USERNAME'), 'CircleCI project username is not set');
$this->assertNotEmpty(getenv('CIRCLE_BUILD_NUM'), 'CircleCI build number is not set');
// Skip the parent setUp as we don't need to prepare SUT for these tests.
}
/**
* {@inheritdoc}
*/
protected function tearDown(): void {
// Skip parent tearDown as we didn't set up SUT.
}
/**
* Test that CircleCI artifacts are saved correctly.
*
* Verifies that:
* - PHPUnit coverage reports are generated for both parallel runners
* - Behat feature files are saved for both parallel runners
* - Feature files are split correctly between runners (e.g., clamav.feature
* on runner 0 but not runner 1, search.feature on runner 1 but not
* runner 0)
*/
#[Group('postbuild')]
public function testCircleCiArtifactsAreSaved(): void {
$currentJobNumber = (int) getenv('CIRCLE_BUILD_NUM');
$previousJobNumbers = $this->circleCiGetPreviousJobNumbers($currentJobNumber);
$this->assertNotEmpty($previousJobNumbers, 'No previous job numbers found');
foreach ($previousJobNumbers as $previousJobNumber) {
$artifactsData = $this->circleCiGetJobArtifacts($previousJobNumber);
// Verify runner 0 artifacts.
$artifactPathsRunner0 = $this->circleCiExtractArtifactPaths($artifactsData, 0);
$artifactPathsRunner0Str = implode("\n", $artifactPathsRunner0);
$this->assertStringContainsString('coverage/phpunit/cobertura.xml', $artifactPathsRunner0Str, 'Runner 0 should have PHPUnit cobertura coverage');
$this->assertStringContainsString('coverage/phpunit/.coverage-html/index.html', $artifactPathsRunner0Str, 'Runner 0 should have PHPUnit HTML coverage');
$this->assertStringContainsString('homepage.feature', $artifactPathsRunner0Str, 'Runner 0 should have homepage.feature');
$this->assertStringContainsString('login.feature', $artifactPathsRunner0Str, 'Runner 0 should have login.feature');
$this->assertStringContainsString('clamav.feature', $artifactPathsRunner0Str, 'Runner 0 should have clamav.feature');
$this->assertStringNotContainsString('search.feature', $artifactPathsRunner0Str, 'Runner 0 should NOT have search.feature');
// Verify runner 1 artifacts.
$artifactPathsRunner1 = $this->circleCiExtractArtifactPaths($artifactsData, 1);
$artifactPathsRunner1Str = implode("\n", $artifactPathsRunner1);
$this->assertStringContainsString('coverage/phpunit/cobertura.xml', $artifactPathsRunner1Str, 'Runner 1 should have PHPUnit cobertura coverage');
$this->assertStringContainsString('coverage/phpunit/.coverage-html/index.html', $artifactPathsRunner1Str, 'Runner 1 should have PHPUnit HTML coverage');
$this->assertStringContainsString('homepage.feature', $artifactPathsRunner1Str, 'Runner 1 should have homepage.feature');
$this->assertStringContainsString('login.feature', $artifactPathsRunner1Str, 'Runner 1 should have login.feature');
$this->assertStringNotContainsString('clamav.feature', $artifactPathsRunner1Str, 'Runner 1 should NOT have clamav.feature');
$this->assertStringContainsString('search.feature', $artifactPathsRunner1Str, 'Runner 1 should have search.feature');
}
}
/**
* Test that CircleCI test results are saved correctly.
*
* Verifies that:
* - PHPUnit test results from various test suites are recorded
* - Behat feature test results are recorded.
*/
#[Group('postbuild')]
public function testCircleCiTestResultsAreSaved(): void {
$currentJobNumber = (int) getenv('CIRCLE_BUILD_NUM');
$previousJobNumbers = $this->circleCiGetPreviousJobNumbers($currentJobNumber);
$this->assertNotEmpty($previousJobNumbers, 'No previous job numbers found');
foreach ($previousJobNumbers as $previousJobNumber) {
$testsData = $this->circleCiGetJobTestMetadata($previousJobNumber);
$testPaths = $this->circleCiExtractTestPaths($testsData);
$testPathsStr = implode("\n", $testPaths);
// Verify PHPUnit test results.
$this->assertStringContainsString('tests/phpunit/CircleCiConfigTest.php', $testPathsStr, 'Should have CircleCiConfigTest results');
$this->assertStringContainsString('tests/phpunit/Drupal/DatabaseSettingsTest.php', $testPathsStr, 'Should have DatabaseSettingsTest results');
$this->assertStringContainsString('tests/phpunit/Drupal/EnvironmentSettingsTest.php', $testPathsStr, 'Should have EnvironmentSettingsTest results');
$this->assertStringContainsString('tests/phpunit/Drupal/SwitchableSettingsTest.php', $testPathsStr, 'Should have SwitchableSettingsTest results');
$this->assertStringContainsString('web/modules/custom/ys_base/tests/src/Functional/ExampleTest.php', $testPathsStr, 'Should have custom module Functional test results');
$this->assertStringContainsString('web/modules/custom/ys_base/tests/src/Kernel/ExampleTest.php', $testPathsStr, 'Should have custom module Kernel test results');
$this->assertStringContainsString('web/modules/custom/ys_base/tests/src/Unit/ExampleTest.php', $testPathsStr, 'Should have custom module Unit test results');
// Verify Behat test results.
$this->assertStringContainsString('homepage.feature', $testPathsStr, 'Should have homepage.feature results');
$this->assertStringContainsString('login.feature', $testPathsStr, 'Should have login.feature results');
$this->assertStringContainsString('clamav.feature', $testPathsStr, 'Should have clamav.feature results');
$this->assertStringContainsString('search.feature', $testPathsStr, 'Should have search.feature results');
}
}
}