Skip to content

Commit ca9d1df

Browse files
committed
[#1560] Moved post build test to PHPUnit.
1 parent a0c8405 commit ca9d1df

7 files changed

Lines changed: 337 additions & 120 deletions

File tree

.circleci/config.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,19 +537,23 @@ jobs:
537537
ahoy --version
538538
539539
- run:
540-
name: Run CircleCI tests (long)
541-
command: VORTEX_DEV_VOLUMES_SKIP_MOUNT=1 VORTEX_DEV_TEST_COVERAGE_DIR=/tmp/artifacts/coverage .vortex/tests/test.postbuild.sh
540+
name: Install test dependencies
541+
command: |
542+
cd .vortex/tests
543+
composer install --no-interaction --prefer-dist
544+
545+
- run:
546+
name: Run CircleCI post-build tests
547+
command: |
548+
cd .vortex/tests
549+
./vendor/bin/phpunit --group=postbuild
542550
543551
- store_test_results:
544552
path: *test_results
545553

546554
- store_artifacts:
547555
path: *artifacts
548556

549-
- run:
550-
name: Upload code coverage reports to Codecov
551-
command: codecov -Z -s /tmp/artifacts/coverage
552-
553557
#-----------------------------------------------------------------------------
554558
# Launching and testing databases stored within Docker data image.
555559
#-----------------------------------------------------------------------------

.vortex/tests/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ For parallel execution, tests can be run across multiple CI nodes using the
7171
convenience script wrappers:
7272

7373
- [`test.common.sh]`(test.common.sh) - Common tests for all environments
74-
- [`test.deployment.sh`](test.deployment.sh) - Deployment tests
75-
- [`test.postbuild.sh`](test.postbuild.sh) - Post-build tests
76-
- [`test.workflow.sh`](test.workflow.sh) - Workflow tests
7774
- [`lint.scripts.sh`](lint.scripts.sh) - Linting for shell scripts
7875
- [`lint.dockerfiles.sh`](lint.dockerfiles.sh) - Linting for Dockerfiles
7976

@@ -112,4 +109,3 @@ phpunit/
112109
├── SubtestAhoyTrait.php # Steps and assertions for testing Ahoy-based workflows
113110
└── SubtestDockerComposeTrait.php # Steps and assertions for Docker Compose-based workflows
114111
```
115-

.vortex/tests/bats/e2e/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

.vortex/tests/bats/e2e/circleci.bats

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

0 commit comments

Comments
 (0)