Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Adds PHPUnit 10 support #45416

Merged
merged 34 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0d086f2
Adds PHPUnit 10 support
nunomaduro Dec 23, 2022
54516ca
Apply fixes from StyleCI
StyleCIBot Dec 23, 2022
feee4a0
Update composer.json
nunomaduro Dec 23, 2022
04e785f
Ignores type error
nunomaduro Dec 23, 2022
21880eb
Run PHPUnit v10
driesvints Dec 27, 2022
ddefa08
wip
driesvints Dec 27, 2022
567a227
Performs `transformNotSuccessfulException` when running the test
nunomaduro Dec 27, 2022
350d3e1
Apply fixes from StyleCI
StyleCIBot Dec 27, 2022
6eb8eee
Fixes PHPUnit 10 tests
nunomaduro Dec 27, 2022
b047fd0
Apply fixes from StyleCI
StyleCIBot Dec 27, 2022
58756a2
Removes non needed exclude path on types
nunomaduro Dec 27, 2022
31ac158
Fixes tests on linux
nunomaduro Dec 27, 2022
3d42c57
Adjusts tests on Windows
nunomaduro Dec 27, 2022
b195c85
Fixes type issues on PHPUnit 10
nunomaduro Dec 27, 2022
1bc1e9f
Removes at `@`
nunomaduro Dec 28, 2022
1b71cde
Fixes missing variable
nunomaduro Dec 28, 2022
d541049
Removes wrong test instead
nunomaduro Jan 30, 2023
f061222
Fixes tests on Windows
nunomaduro Jan 30, 2023
c3818fd
Adjusts tests
nunomaduro Jan 30, 2023
680ddd9
Sets PHPUnit on its own step
nunomaduro Jan 30, 2023
32708ac
Adjusts workflow
nunomaduro Jan 30, 2023
d503c24
Removes verbose from PHPUnit 10
nunomaduro Jan 30, 2023
174d1bc
Update tests.yml
driesvints Jan 30, 2023
e411b14
Update composer.json
driesvints Jan 30, 2023
a4c51c8
Update tests.yml
driesvints Jan 30, 2023
a932241
Removes non needed files
nunomaduro Jan 30, 2023
9a6d16d
Setups PHPUnit as extra step
nunomaduro Jan 30, 2023
e369ca7
Removes `--verbose` from workflows
nunomaduro Feb 3, 2023
10d799c
Fixes missing `Registry` class
nunomaduro Feb 3, 2023
233eaa0
Bumps phpunit
nunomaduro Feb 3, 2023
56626b3
Fixes and adds tests for `assertArraySubset`
nunomaduro Feb 3, 2023
ed669a6
Apply fixes from StyleCI
StyleCIBot Feb 3, 2023
5f5ab9c
Update InvalidArgumentException.php
taylorotwell Feb 3, 2023
f451f0c
Update TestCase.php
taylorotwell Feb 3, 2023
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
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