Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6f98bae
chore: add phpunit schema version script
delatrie Apr 11, 2025
28245e4
deps: bump vimeo/psalm to ^6.10
delatrie Apr 11, 2025
0843d66
deps: bump psalm/plugin-phpunit to ^0.19.5
delatrie Apr 11, 2025
842db39
deps: increase min PHPUnit version to 10.0.5
delatrie Apr 11, 2025
2f5e248
deps: fix dev dep version ranges
delatrie Apr 11, 2025
9bf4457
chore: fix phpunit config schemas
delatrie Apr 11, 2025
e3ff029
chore: fix config selection in build CI
delatrie Apr 11, 2025
53a34c7
chore: avoid phpunit/paratest incompat in CI
delatrie Apr 11, 2025
8a6f24d
test: add GarbageCollectorStatus ctor fallback for phpunit 10.1-10.2
delatrie Apr 11, 2025
3b6619e
test: fix phpunit data provider typings
delatrie Apr 16, 2025
0cf1693
chore: add phpunit version to CI matrix
delatrie Apr 16, 2025
f235501
chore: ignore missing GarbageCollectorStatus psalm error
delatrie Apr 16, 2025
2f08372
chore: show PHPUnit XML schema version in build workflow
delatrie Apr 16, 2025
dfa62f9
chore: fix set-phpunit-version step on Win
delatrie Apr 16, 2025
14453a3
chore: swap include and exclude in CI matrix
delatrie Apr 16, 2025
4595e1b
chore: fix update CI step on Windows
delatrie Apr 16, 2025
76dcd72
chore: add resolved phpunit version to CI summary
delatrie Apr 16, 2025
5495fe6
chore: workaround phpunit 11 --prefer-lowest
delatrie Apr 16, 2025
6139eb3
deps: bump v12 min supported version to 12.0.1
delatrie Apr 16, 2025
d5b06dd
test: use CoversTrait in PHPUnit 11.2+
delatrie Apr 17, 2025
47cbe91
test: fix psalm for phpunit 11.4
delatrie Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 48 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
tests:
name: PHP ${{ matrix.php-version }} on ${{ matrix.os }} (${{ matrix.composer-options }})
name: PHP ${{ matrix.php-version }} PHPUnit ${{matrix.phpunit-version}} on ${{ matrix.os }} (${{ matrix.prefer-lowest }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -25,9 +25,34 @@ jobs:
- ubuntu-latest
- windows-latest
- macOS-latest
composer-options:
phpunit-version:
- "10"
- "11"
- "12"
prefer-lowest:
- ""
- "--prefer-lowest"
exclude:
# PHPUnit ^11 requires PHP 8.2
- phpunit-version: "11"
php-version: "8.1"

# PHPUnit ^12 requires PHP 8.3
- phpunit-version: "12"
php-version: "8.1"
- phpunit-version: "12"
php-version: "8.2"
include:
# PHPUnit ^10.5.32 is incompatible with paratest 7.3.
# Paratest 7.4.6, which fixes the incompatibility, requires PHP 8.2
- php-version: "8.1"
phpunit-version: "10"
update-constraints: "'--with=phpunit/phpunit:<10.5.32'"

# PHPUnit ~11.0 || ~11.1 can't double readonly classes, which fails some tests
# We constraint PHPUnit 11 to ^11.2 until we find a better solution
- phpunit-version: "11"
update-constraints: "'--with=phpunit/phpunit:^11.2'"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -44,23 +69,32 @@ jobs:
run: composer validate

- name: Install dependencies
run: composer update
--prefer-dist
--no-progress
${{ matrix.composer-options }}
run: >
composer update --prefer-dist --no-progress
${{ matrix.prefer-lowest }}
'--with=phpunit/phpunit:^${{ matrix.phpunit-version }}'
${{ matrix.update-constraints }}
shell: bash

- name: Set PHPUnit version
id: set-phpunit-version
run: |
echo "Tested against PHPUnit **v$(composer print-phpunit-version)**" >> "$GITHUB_STEP_SUMMARY"
echo "PHPUNIT_SCHEMA_VERSION=$(composer print-phpunit-schema-version)" >> "$GITHUB_OUTPUT"
shell: bash

- name: Run tests
if: ${{ matrix.os != 'windows-latest' && !contains(matrix.composer-options, '--prefer-lowest') }}
if: ${{ matrix.os != 'windows-latest' && steps.set-phpunit-version.outputs.PHPUNIT_SCHEMA_VERSION != '10.0' }}
run: composer test

- name: Run tests (lowest)
if: ${{ matrix.os != 'windows-latest' && contains(matrix.composer-options, '--prefer-lowest') }}
run: composer test-lowest
- name: Run tests (phpunit10.0)
if: ${{ matrix.os != 'windows-latest' && steps.set-phpunit-version.outputs.PHPUNIT_SCHEMA_VERSION == '10.0' }}
run: composer test-phpunit10.0

- name: Run tests (windows)
if: ${{ matrix.os == 'windows-latest' && !contains(matrix.composer-options, '--prefer-lowest') }}
if: ${{ matrix.os == 'windows-latest' && steps.set-phpunit-version.outputs.PHPUNIT_SCHEMA_VERSION != '10.0' }}
run: composer test-windows

- name: Run tests (windows-lowest)
if: ${{ matrix.os == 'windows-latest' && contains(matrix.composer-options, '--prefer-lowest') }}
run: composer test-windows-lowest
- name: Run tests (windows-phpunit10.0)
if: ${{ matrix.os == 'windows-latest' && steps.set-phpunit-version.outputs.PHPUNIT_SCHEMA_VERSION == '10.0' }}
run: composer test-windows-phpunit10.0
36 changes: 21 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"allure-framework/allure-php-commons": "^2.0",
"phpunit/phpunit": "^10 || ^11 || ^12"
"phpunit/phpunit": "^10.0.5 || ^11 || ^12.0.1"
},
"require-dev": {
"phpunit/phpunit": "~10.4.0 || ^11 || ^12",
"brianium/paratest": "^7.3",
"psalm/plugin-phpunit": "^0.19.3",
"brianium/paratest": "^7",
"psalm/plugin-phpunit": "^0.19.5",
"squizlabs/php_codesniffer": "^3.7.2",
"vimeo/psalm": "^6.9"
"vimeo/psalm": "^6.10"
},
"conflict": {
"amphp/byte-stream": "<1.5.1",
Expand All @@ -63,20 +62,21 @@
},
"psr-4": {
"Qameta\\Allure\\PHPUnit\\Test\\Unit\\": "test/unit/",
"Qameta\\Allure\\PHPUnit\\Test\\Report\\": "test/report/"
"Qameta\\Allure\\PHPUnit\\Test\\Report\\": "test/report/",
"Qameta\\Allure\\PHPUnit\\Scripts\\": "scripts/"
}
},
"scripts": {
"test-cs": "vendor/bin/phpcs -sp",
"test-unit": "vendor/bin/phpunit --coverage-text",
"test-unit-lowest": "vendor/bin/phpunit --configuration=phpunit.10.0.xml --coverage-text",
"test-unit-phpunit10.0": "vendor/bin/phpunit --configuration=phpunit.10.0.xml --coverage-text",
"clear-allure-results": "rm -rf ./build/allure-results",
"test-report": [
"@clear-allure-results",
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive",
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative; exit 0"
],
"test-report-lowest": [
"test-report-phpunit10.0": [
"@clear-allure-results",
"vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=positive",
"vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=negative; exit 0"
Expand All @@ -86,7 +86,7 @@
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive",
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative & exit 0"
],
"test-report-windows-lowest": [
"test-report-windows-phpunit10.0": [
"@clear-allure-results",
"vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=positive",
"vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=negative & exit 0"
Expand All @@ -98,10 +98,10 @@
"@test-report",
"@test-psalm"
],
"test-lowest": [
"test-phpunit10.0": [
"@test-cs",
"@test-unit-lowest",
"@test-report-lowest",
"@test-unit-phpunit10.0",
"@test-report-phpunit10.0",
"@test-psalm"
],
"test-windows": [
Expand All @@ -110,11 +110,17 @@
"@test-report-windows",
"@test-psalm"
],
"test-windows-lowest": [
"test-windows-phpunit10.0": [
"@test-cs",
"@test-unit-lowest",
"@test-report-windows-lowest",
"@test-unit-phpunit10.0",
"@test-report-windows-phpunit10.0",
"@test-psalm"
],
"print-phpunit-version": [
"Qameta\\Allure\\PHPUnit\\Scripts\\CiScripts::printPhpUnitVersion"
],
"print-phpunit-schema-version": [
"Qameta\\Allure\\PHPUnit\\Scripts\\CiScripts::printConfigSchemaVersion"
]
}
}
6 changes: 3 additions & 3 deletions phpunit.10.0.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
colors="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
Expand All @@ -15,9 +15,9 @@
<directory>test/unit/</directory>
</testsuite>
</testsuites>
<source>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</coverage>
</phpunit>
2 changes: 1 addition & 1 deletion phpunit.report.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.1/phpunit.xsd"
colors="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.1/phpunit.xsd"
colors="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
Expand Down
27 changes: 27 additions & 0 deletions scripts/CiScripts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);

namespace Qameta\Allure\PHPUnit\Scripts;

final class CiScripts
{
/**
* Prints the version of PHPUnit.
*/
public static function printPhpUnitVersion(): void
{
if (class_exists(\PHPUnit\Runner\Version::class)) {
echo(\PHPUnit\Runner\Version::id());
}
}

/**
* Prints the version of the PHPUnit XML schema.
* We use this in the CI pipeline to deside which configuration file to use.
*/
public static function printConfigSchemaVersion(): void
{
if (class_exists(\PHPUnit\Runner\Version::class)) {
echo(preg_replace('/^(\d+\.\d+)\..*$/', '$1', \PHPUnit\Runner\Version::id()));
}
}
}
6 changes: 6 additions & 0 deletions test/report/Generate/DataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public function testNamedDataSet(int $x, int $y): void
Allure::runStep(fn () => self::assertSame($x, $y));
}

/**
* @return iterable<string, array<int, int>>
*/
public static function providerNamed(): iterable
{
return [
Expand All @@ -34,6 +37,9 @@ public function testListedDataSet(int $x, int $y): void
Allure::runStep(fn () => self::assertSame($x, $y));
}

/**
* @return iterable<int, array<int, int>>
*/
public static function providerListed(): iterable
{
return [
Expand Down
68 changes: 48 additions & 20 deletions test/unit/Event/EventTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,7 @@ trait EventTestTrait
{
protected function createTelemetryInfo(): Info
{
/**
* @psalm-suppress MixedAssignment
* @psalm-suppress TooManyArguments
*/
$garbageCollectorStatus = class_exists(GarbageCollectorStatus::class)
? new GarbageCollectorStatus(
0,
0,
0,
0,
0.0,
0.0,
0.0,
0.0,
false,
false,
false,
0,
)
: null; // early PHPUnit 10
$garbageCollectorStatus = self::createGarbageCollectorStatus();

/**
* @psalm-suppress TooManyArguments
Expand Down Expand Up @@ -264,4 +245,51 @@ protected function createTestWarningTriggeredEvent(
false,
);
}

/**
* GarbageCollectorStatus doesn't exist in PHPUnit 10.0
* @psalm-suppress UndefinedClass
*/
private static function createGarbageCollectorStatus(): ?GarbageCollectorStatus
{
// GarbageCollectorStatus doesn't exist in PHPUnit 10.0
if (class_exists(GarbageCollectorStatus::class)) {
$ctorInfo = (new \ReflectionClass(GarbageCollectorStatus::class))->getConstructor();
if (isset($ctorInfo)) {
/**
* @psalm-suppress InvalidArgument
* @psalm-suppress TooFewArguments
* @psalm-suppress TooManyArguments
*/
return $ctorInfo->getNumberOfParameters() === 8
# PHPUnit [10.1, 10.3)
? new GarbageCollectorStatus(
0,
0,
0,
0,
false,
false,
false,
0,
)
# Extra arguments are required since 10.3.0
: new GarbageCollectorStatus(
0,
0,
0,
0,
0.0,
0.0,
0.0,
0.0,
false,
false,
false,
0,
);
}
}
return null;
}
}
27 changes: 24 additions & 3 deletions test/unit/ExceptionDetailsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

namespace Qameta\Allure\PHPUnit\Test\Unit;

// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses

use Exception;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\CoversTrait;
use Qameta\Allure\PHPUnit\ExceptionDetailsTrait;
use Qameta\Allure\PHPUnit\AllureAdapter;
use Qameta\Allure\PHPUnit\AllureAdapterInterface;
use Throwable;

// #[CoversTrait(ExceptionDetailsTrait::class)] <--- needed by phpunit 12
// #[CoversClass(ExceptionDetailsTrait::class)] <--- needed by phpunit 10 + 11
final class ExceptionDetailsTraitTest extends TestCase
abstract class ExceptionDetailsTraitTestBase extends TestCase
{
public function testOnNotSuccessfulTest_GivenException_ThrowsSameException(): void
{
Expand Down Expand Up @@ -49,3 +51,22 @@ public function testOnNotSuccessfulTest_GivenException_SetsSameExceptionAsLast()
}
}
}

/**
* CoversTrait was added in PHPUnit 11.2.0.
* If was then deprecated in 11.4.0 but the deprecation was reverted in 11.5.4.
* @psalm-suppress DeprecatedClass
*/
if (class_exists(CoversTrait::class)) {
#[CoversTrait(ExceptionDetailsTrait::class)]
final class ExceptionDetailsTraitTest extends ExceptionDetailsTraitTestBase
{
}

} else {
#[CoversClass(ExceptionDetailsTrait::class)]
final class ExceptionDetailsTraitTest extends ExceptionDetailsTraitTestBase
{
}

}