Skip to content

Commit

Permalink
[9.6.x] Supports PHPUnit 11.5 (#262)
Browse files Browse the repository at this point in the history
* [9.x] Supports PHPUnit 11.5

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

* wip

* wip

* wip

* wip

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Dec 5, 2024
1 parent 6334911 commit 8694abf
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/collision-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
composer show -D
- name: Execute tests (with deprecations on PHPUnit 10)
run: ./testbench package:test --exclude-group commander
run: php testbench package:test --exclude-group commander
env:
RAY_ENABLED: false

Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
composer show -D
- name: Execute tests
run: ./testbench package:test --coverage --exclude-group commander --exclude-group deprecations
run: php testbench package:test --coverage --exclude-group commander --exclude-group deprecations
env:
RAY_ENABLED: false
TESTBENCH_CONVERT_DEPRECATIONS_TO_EXCEPTIONS: false
23 changes: 12 additions & 11 deletions .github/workflows/parallel-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ jobs:
paratest:
- "^7.3"
phpunit:
- "^10.5"
- "^11.0"
- "~10.5.35"
- "~11.3.6"
- "~11.4.0"
- "~11.5.0"
experimental:
- false
exclude:
- php: 8.4
phpunit: "~10.5.35"
- php: 8.4
phpunit: "~11.3.6"

name: PHP:${{ matrix.php }} / Paratest:${{ matrix.paratest }} / PHPUnit:${{ matrix.phpunit }} ⬆️

Expand Down Expand Up @@ -51,14 +58,8 @@ jobs:
run: |
composer show -D
- name: Execute tests (with deprecations)
run: ./testbench package:test --parallel --exclude-group commander,without-parallel,database,session --no-coverage
- name: Execute tests
run: php testbench package:test --parallel ${{ matrix.phpunit == '~10.5.35' && '--exclude-group commander,without-parallel,database,session --no-coverage' || '--exclude-group commander --exclude-group without-parallel --exclude-group database --exclude-group session --no-coverage' }}
env:
RAY_ENABLED: false
if: matrix.phpunit == '^10.5'

- name: Execute tests (with deprecations)
run: ./testbench package:test --parallel --exclude-group commander --exclude-group without-parallel --exclude-group database --exclude-group session --no-coverage
env:
RAY_ENABLED: false
if: matrix.phpunit != '^10.5'
if: matrix.phpunit != '~10.5.35'
1 change: 1 addition & 0 deletions .github/workflows/strict-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- "~10.5.0"
- "~11.3.0"
- "~11.4.0"
- "~11.5.0"
experimental:
- false

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- "~10.5.0"
- "~11.3.0"
- "~11.4.0"
- "~11.5.0"
dependencies:
- "highest"
- "lowest"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"laravel/framework": "<11.33.2 || >=12.0.0",
"laravel/serializable-closure": "<1.3.0 || >=3.0.0",
"nunomaduro/collision": "<8.0.0 || >=9.0.0",
"phpunit/phpunit": "<10.5.35 || >=11.0.0 <11.3.6 || >=11.5.0"
"phpunit/phpunit": "<10.5.35 || >=11.0.0 <11.3.6 || >=11.6.0"
},
"suggest": {
"ext-pcntl": "Required to use all features of the console signal trapping.",
Expand Down
8 changes: 7 additions & 1 deletion src/Exceptions/DeprecatedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use PHPUnit\Util\Filter;

use function Orchestra\Testbench\phpunit_version_compare;

/**
* @codeCoverageIgnore
*/
Expand All @@ -16,6 +18,10 @@ class DeprecatedException extends PHPUnitErrorException
*/
public function __toString(): string
{
return \sprintf('%s'.PHP_EOL.PHP_EOL.'%s', $this->getMessage(), Filter::getFilteredStacktrace($this));
$stackTrace = phpunit_version_compare('11.5', '>=')
? Filter::stackTraceFromThrowableAsString($this)
: Filter::getFilteredStacktrace($this);

return \sprintf('%s'.PHP_EOL.PHP_EOL.'%s', $this->getMessage(), $stackTrace);
}
}
17 changes: 13 additions & 4 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,11 @@ function laravel_vendor_exists(ApplicationContract $app, ?string $workingPath =
*/
function laravel_version_compare(string $version, ?string $operator = null): int|bool
{
/** @phpstan-ignore identical.alwaysFalse */
$laravel = Application::VERSION === '11.x-dev' ? '11.0.0' : Application::VERSION;
/** @var string $laravel */
$laravel = transform(
Application::VERSION,
fn (string $version) => $version === '11.x-dev' ? '11.0.0' : $version, // @phpstan-ignore identical.alwaysFalse
);

if (\is_null($operator)) {
return version_compare($laravel, $version);
Expand All @@ -393,11 +396,17 @@ function phpunit_version_compare(string $version, ?string $operator = null): int
throw new RuntimeException('Unable to verify PHPUnit version');
}

/** @var string $phpunit */
$phpunit = transform(
Version::id(),
fn (string $version) => $version === '11.5-dev' ? '11.5.0' : $version,
);

if (\is_null($operator)) {
return version_compare(Version::id(), $version);
return version_compare($phpunit, $version);
}

return version_compare(Version::id(), $version, $operator);
return version_compare($phpunit, $version, $operator);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function it_can_compare_laravel_version()
#[Test]
public function it_can_compare_phpunit_version()
{
$this->assertSame(0, phpunit_version_compare(Version::id()));
$this->assertTrue(phpunit_version_compare(Version::id(), '=='));
$phpunit = Version::id() === '11.5-dev' ? '11.5.0' : Version::id();

$this->assertSame(0, phpunit_version_compare($phpunit));
$this->assertTrue(phpunit_version_compare($phpunit, '=='));
}
}

0 comments on commit 8694abf

Please sign in to comment.