Skip to content

Commit

Permalink
[10.x] Adds PHPUnit 10 support (#45416)
Browse files Browse the repository at this point in the history
* Adds PHPUnit 10 support

* Apply fixes from StyleCI

* Update composer.json

Co-authored-by: Mior Muhammad Zaki <[email protected]>

* Ignores type error

* Run PHPUnit v10

* wip

* Performs `transformNotSuccessfulException` when running the test

* Apply fixes from StyleCI

* Fixes PHPUnit 10 tests

* Apply fixes from StyleCI

* Removes non needed exclude path on types

* Fixes tests on linux

* Adjusts tests on Windows

* Fixes type issues on PHPUnit 10

* Removes at `@`

* Fixes missing variable

* Removes wrong test instead

* Fixes tests on Windows

* Adjusts tests

* Sets PHPUnit on its own step

* Adjusts workflow

* Removes verbose from PHPUnit 10

* Update tests.yml

* Update composer.json

* Update tests.yml

* Removes non needed files

* Setups PHPUnit as extra step

* Removes `--verbose` from workflows

* Fixes missing `Registry` class

* Bumps phpunit

* Fixes and adds tests for `assertArraySubset`

* Apply fixes from StyleCI

* Update InvalidArgumentException.php

* Update TestCase.php

---------

Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: Dries Vints <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
5 people authored Feb 3, 2023
1 parent 72c7929 commit ad736a4
Show file tree
Hide file tree
Showing 32 changed files with 492 additions and 443 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Database --verbose
run: vendor/bin/phpunit tests/Integration/Database
env:
DB_CONNECTION: mysql
DB_USERNAME: root
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Database --verbose
run: vendor/bin/phpunit tests/Integration/Database
env:
DB_CONNECTION: mysql
DB_USERNAME: root
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Database --verbose
run: vendor/bin/phpunit tests/Integration/Database
env:
DB_CONNECTION: mysql
DB_USERNAME: root
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Database --verbose
run: vendor/bin/phpunit tests/Integration/Database
env:
DB_CONNECTION: pgsql
DB_PASSWORD: password
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Database --verbose
run: vendor/bin/phpunit tests/Integration/Database
env:
DB_CONNECTION: sqlsrv
DB_DATABASE: master
Expand Down
50 changes: 43 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ jobs:
fail-fast: true
matrix:
php: [8.1, 8.2]
phpunit: ['9.5.8', '10.0']
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -75,22 +76,41 @@ jobs:
command: composer require guzzlehttp/guzzle:^7.5 guzzlehttp/psr7:^2.4 predis/predis:^2.0.2 --no-interaction --no-update
if: matrix.php >= 8.2

- name: Set PHPUnit
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit --verbose
- name: Execute tests against PHPUnit ^9
run: vendor/bin/phpunit --verbose --configuration phpunit9.xml.dist
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_USERNAME: root
DYNAMODB_CACHE_TABLE: laravel_dynamodb_test
DYNAMODB_ENDPOINT: "http://localhost:8888"
AWS_ACCESS_KEY_ID: random_key
AWS_SECRET_ACCESS_KEY: random_secret
if: matrix.phpunit != '10.0'

- name: Execute tests against PHPUnit ^10
run: vendor/bin/phpunit
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_USERNAME: root
DYNAMODB_CACHE_TABLE: laravel_dynamodb_test
DYNAMODB_ENDPOINT: "http://localhost:8888"
AWS_ACCESS_KEY_ID: random_key
AWS_SECRET_ACCESS_KEY: random_secret
if: matrix.phpunit == '10.0'

- name: Store artifacts
uses: actions/upload-artifact@v3
Expand All @@ -107,9 +127,10 @@ jobs:
fail-fast: true
matrix:
php: [8.1, 8.2]
phpunit: ['9.5.8', '10.0']
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }} - Windows
name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - Windows

steps:
- name: Set git to use LF
Expand All @@ -133,7 +154,7 @@ jobs:
with:
timeout_minutes: 5
max_attempts: 5
command: composer require symfony/css-selector:~6.0 --no-interaction --no-update
command: composer require symfony/css-selector:~6.0 ramsey/collection:^1.2 brick/math:^0.9.3 --no-interaction --no-update

- name: Set Minimum PHP 8.2 Versions
uses: nick-fields/retry@v2
Expand All @@ -143,18 +164,33 @@ jobs:
command: composer require guzzlehttp/guzzle:~7.5 guzzlehttp/psr7:~2.4 predis/predis:~2.0.2 --no-interaction --no-update
if: matrix.php >= 8.2

- name: Set PHPUnit
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit --verbose
- name: Execute tests against PHPUnit ^9
run: vendor/bin/phpunit --verbose --configuration phpunit9.xml.dist
env:
AWS_ACCESS_KEY_ID: random_key
AWS_SECRET_ACCESS_KEY: random_secret
if: matrix.phpunit != '10.0'

- name: Execute tests against PHPUnit ^10
run: vendor/bin/phpunit
env:
AWS_ACCESS_KEY_ID: random_key
AWS_SECRET_ACCESS_KEY: random_secret
if: matrix.phpunit == '10.0'

- name: Store artifacts
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.phpunit.cache
/vendor
composer.phar
composer.lock
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@
"league/flysystem-read-only": "^3.3",
"league/flysystem-sftp-v3": "^3.0",
"mockery/mockery": "^1.5.1",
"orchestra/testbench-core": "^8.0",
"orchestra/testbench-core": "dev-phpunit10",
"pda/pheanstalk": "^4.0",
"phpstan/phpdoc-parser": "^1.15",
"phpstan/phpstan": "^1.4.7",
"phpunit/phpunit": "^9.5.8",
"phpunit/phpunit": "^9.5.8 || ^10.0.1",
"predis/predis": "^2.0.2",
"symfony/cache": "^6.2",
"symfony/http-client": "^6.2.4"
Expand Down
1 change: 0 additions & 1 deletion phpstan.src.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ parameters:
- "#Unsafe usage of new static#"
excludePaths:
- "src/Illuminate/Testing/ParallelRunner.php"
- "src/Illuminate/Testing/Constraints/ArraySubset.php"
10 changes: 2 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
printerClass="Illuminate\Tests\IgnoreSkippedPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<testsuites>
<testsuite name="Laravel Test Suite">
<directory suffix="Test.php">./tests</directory>
Expand Down
31 changes: 31 additions & 0 deletions phpunit9.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
printerClass="Illuminate\Tests\IgnoreSkippedPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Laravel Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<ini name="date.timezone" value="UTC" />
<ini name="intl.default_locale" value="C.UTF-8" />
<ini name="memory_limit" value="2048M" />
<env name="DB_CONNECTION" value="testing" />
<!--
<env name="REDIS_HOST" value="127.0.0.1" />
<env name="REDIS_PORT" value="6379" />
-->
</php>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function setUpRedis()
$host = Env::get('REDIS_HOST', '127.0.0.1');
$port = Env::get('REDIS_PORT', 6379);

foreach ($this->redisDriverProvider() as $driver) {
foreach (static::redisDriverProvider() as $driver) {
$this->redis[$driver[0]] = new RedisManager($app, $driver[0], [
'cluster' => false,
'options' => [
Expand Down Expand Up @@ -80,7 +80,7 @@ public function tearDownRedis()
$this->redis['phpredis']->connection()->flushdb();
}

foreach ($this->redisDriverProvider() as $driver) {
foreach (static::redisDriverProvider() as $driver) {
if (isset($this->redis[$driver[0]])) {
$this->redis[$driver[0]]->connection()->disconnect();
}
Expand All @@ -92,7 +92,7 @@ public function tearDownRedis()
*
* @return array
*/
public function redisDriverProvider()
public static function redisDriverProvider()
{
return [
['predis'],
Expand Down
45 changes: 26 additions & 19 deletions src/Illuminate/Foundation/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ protected function setUpTraits()
return $uses;
}

/**
* {@inheritdoc}
*/
protected function runTest(): mixed
{
$result = null;

try {
$result = parent::runTest();
} catch (Throwable $e) {
if (! is_null(static::$latestResponse)) {
static::$latestResponse->transformNotSuccessfulException($e);
}

throw $e;
}

return $result;
}

/**
* Clean up the testing environment before the next test.
*
Expand Down Expand Up @@ -241,10 +261,12 @@ public static function tearDownAfterClass(): void
{
static::$latestResponse = null;

(function () {
$this->classDocBlocks = [];
$this->methodDocBlocks = [];
})->call(Registry::getInstance());
if (class_exists(Registry::class)) {
(function () {
$this->classDocBlocks = [];
$this->methodDocBlocks = [];
})->call(Registry::getInstance());
}
}

/**
Expand Down Expand Up @@ -290,19 +312,4 @@ protected function callBeforeApplicationDestroyedCallbacks()
}
}
}

/**
* This method is called when a test method did not execute successfully.
*
* @param \Throwable $exception
* @return void
*/
protected function onNotSuccessfulTest(Throwable $exception): void
{
parent::onNotSuccessfulTest(
is_null(static::$latestResponse)
? $exception
: static::$latestResponse->transformNotSuccessfulException($exception)
);
}
}
43 changes: 1 addition & 42 deletions src/Illuminate/Testing/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

use ArrayAccess;
use Illuminate\Testing\Constraints\ArraySubset;
use Illuminate\Testing\Exceptions\InvalidArgumentException;
use PHPUnit\Framework\Assert as PHPUnit;
use PHPUnit\Framework\Constraint\DirectoryExists;
use PHPUnit\Framework\Constraint\FileExists;
use PHPUnit\Framework\Constraint\LogicalNot;
use PHPUnit\Framework\Constraint\RegularExpression;
use PHPUnit\Framework\InvalidArgumentException;

/**
* @internal This class is not meant to be used or overwritten outside the framework itself.
Expand Down Expand Up @@ -39,41 +35,4 @@ public static function assertArraySubset($subset, $array, bool $checkForIdentity

PHPUnit::assertThat($array, $constraint, $msg);
}

/**
* Asserts that a file does not exist.
*
* @param string $filename
* @param string $message
* @return void
*/
public static function assertFileDoesNotExist(string $filename, string $message = ''): void
{
static::assertThat($filename, new LogicalNot(new FileExists), $message);
}

/**
* Asserts that a directory does not exist.
*
* @param string $directory
* @param string $message
* @return void
*/
public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void
{
static::assertThat($directory, new LogicalNot(new DirectoryExists), $message);
}

/**
* Asserts that a string matches a given regular expression.
*
* @param string $pattern
* @param string $string
* @param string $message
* @return void
*/
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
{
static::assertThat($string, new RegularExpression($pattern), $message);
}
}
Loading

0 comments on commit ad736a4

Please sign in to comment.