From 6d17635d839fe87a0ef92c52f73e78d31f12508f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Nov 2024 23:06:20 +0800 Subject: [PATCH] [7.x] Supports PHP 8.4 (#182) * [7.x] Supports PHP 8.4 Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * Apply fixes from StyleCI * wip * wip * wip * wip --------- Signed-off-by: Mior Muhammad Zaki Co-authored-by: StyleCI Bot --- .github/workflows/tests.yml | 10 +++-- composer.json | 1 + pint.json | 6 +++ src/Concerns/MakesHttpRequests.php | 10 ++--- src/Constraints/HasLink.php | 2 +- src/TestCase.php | 6 +-- .../Unit/InteractsWithAuthenticationTest.php | 1 + tests/Unit/InteractsWithContainerTest.php | 3 +- tests/Unit/InteractsWithDatabaseTest.php | 4 +- .../InteractsWithExceptionHandlingTest.php | 39 ++++++++----------- tests/Unit/InteractsWithPagesTest.php | 2 + tests/Unit/InteractsWithSessionTest.php | 23 ++++------- 12 files changed, 52 insertions(+), 55 deletions(-) create mode 100644 pint.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3400115..651ecb1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,10 +17,12 @@ jobs: strategy: fail-fast: true matrix: - php: [8.2, 8.3] + php: [8.2, 8.3, 8.4] phpunit: [10, 11] laravel: [10, 11] exclude: + - php: 8.4 + laravel: 10 - phpunit: 11 laravel: 10 @@ -41,10 +43,10 @@ jobs: - name: Install dependencies run: | - composer update --with=laravel/framework=^${{ matrix.laravel }} --with=phpunit/phpunit:^${{ matrix.phpunit }} --prefer-dist --no-interaction --no-progress + composer update --prefer-dist --no-interaction --no-progress --with="laravel/framework=^${{ matrix.laravel }}" --with="phpunit/phpunit:^${{ matrix.phpunit }}" - name: Execute tests - run: vendor/bin/phpunit + run: vendor/bin/phpunit --display-deprecations --fail-on-deprecation paratests: runs-on: ubuntu-22.04 @@ -52,7 +54,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.2, 8.3] + php: [8.2, 8.3, 8.4] name: PHP ${{ matrix.php }} Paratest diff --git a/composer.json b/composer.json index 12fe36d..b717da6 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "symfony/http-kernel": "^6.2|^7.0" }, "require-dev": { + "laravel/pint": "^1.17", "orchestra/testbench-core": "^8.21|^9.0" }, "autoload": { diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..61be846 --- /dev/null +++ b/pint.json @@ -0,0 +1,6 @@ +{ + "preset": "laravel", + "rules": { + "no_superfluous_phpdoc_tags": false + } +} diff --git a/src/Concerns/MakesHttpRequests.php b/src/Concerns/MakesHttpRequests.php index 61bc64d..3602f35 100644 --- a/src/Concerns/MakesHttpRequests.php +++ b/src/Concerns/MakesHttpRequests.php @@ -380,7 +380,7 @@ public function handle(Request $request) * @param array|null $data * @return $this */ - protected function shouldReturnJson(array $data = null) + protected function shouldReturnJson(?array $data = null) { return $this->receiveJson($data); } @@ -391,7 +391,7 @@ protected function shouldReturnJson(array $data = null) * @param array|null $data * @return $this|null */ - protected function receiveJson(array $data = null) + protected function receiveJson(?array $data = null) { return $this->seeJson($data); } @@ -416,7 +416,7 @@ public function seeJsonEquals(array $data) * @param bool $negate * @return $this */ - public function seeJson(array $data = null, $negate = false) + public function seeJson(?array $data = null, $negate = false) { if (is_null($data)) { $decodedResponse = json_decode($this->response->getContent(), true); @@ -442,7 +442,7 @@ public function seeJson(array $data = null, $negate = false) * @param array|null $data * @return $this */ - public function dontSeeJson(array $data = null) + public function dontSeeJson(?array $data = null) { return $this->seeJson($data, true); } @@ -454,7 +454,7 @@ public function dontSeeJson(array $data = null) * @param array|null $responseData * @return $this */ - public function seeJsonStructure(array $structure = null, $responseData = null) + public function seeJsonStructure(?array $structure = null, $responseData = null) { $this->response->assertJsonStructure($structure, $responseData); diff --git a/src/Constraints/HasLink.php b/src/Constraints/HasLink.php index 783e509..5657091 100644 --- a/src/Constraints/HasLink.php +++ b/src/Constraints/HasLink.php @@ -19,7 +19,7 @@ class HasLink extends PageConstraint * * @var string|null */ - protected readonly string|null $url; + protected readonly ?string $url; /** * Create a new constraint instance. diff --git a/src/TestCase.php b/src/TestCase.php index 9831fdd..3dea234 100755 --- a/src/TestCase.php +++ b/src/TestCase.php @@ -10,14 +10,14 @@ abstract class TestCase extends BaseTestCase { - use Concerns\InteractsWithContainer, - Concerns\MakesHttpRequests, - Concerns\ImpersonatesUsers, + use Concerns\ImpersonatesUsers, Concerns\InteractsWithAuthentication, Concerns\InteractsWithConsole, + Concerns\InteractsWithContainer, Concerns\InteractsWithDatabase, Concerns\InteractsWithExceptionHandling, Concerns\InteractsWithSession, + Concerns\MakesHttpRequests, InteractsWithTestCaseLifecycle; /** diff --git a/tests/Unit/InteractsWithAuthenticationTest.php b/tests/Unit/InteractsWithAuthenticationTest.php index 64531a3..0e58322 100644 --- a/tests/Unit/InteractsWithAuthenticationTest.php +++ b/tests/Unit/InteractsWithAuthenticationTest.php @@ -18,6 +18,7 @@ protected function createUserProviderToCredentials() return new class { public $retrieveByCredentials; + public $validateCredentials; public function make() diff --git a/tests/Unit/InteractsWithContainerTest.php b/tests/Unit/InteractsWithContainerTest.php index c3ff33e..cff8653 100644 --- a/tests/Unit/InteractsWithContainerTest.php +++ b/tests/Unit/InteractsWithContainerTest.php @@ -22,8 +22,7 @@ public function instance() } }; $abstract = 'Foo'; - $instance = new class { - }; + $instance = new class {}; $this->assertEquals( $instance, $this->instance($abstract, $instance) diff --git a/tests/Unit/InteractsWithDatabaseTest.php b/tests/Unit/InteractsWithDatabaseTest.php index 93777cb..85698de 100644 --- a/tests/Unit/InteractsWithDatabaseTest.php +++ b/tests/Unit/InteractsWithDatabaseTest.php @@ -10,8 +10,8 @@ class InteractsWithDatabaseTest extends TestCase { - use InteractsWithDatabase, - InteractsWithConsole; + use InteractsWithConsole, + InteractsWithDatabase; protected $app; diff --git a/tests/Unit/InteractsWithExceptionHandlingTest.php b/tests/Unit/InteractsWithExceptionHandlingTest.php index 1ead73d..794718e 100644 --- a/tests/Unit/InteractsWithExceptionHandlingTest.php +++ b/tests/Unit/InteractsWithExceptionHandlingTest.php @@ -21,7 +21,7 @@ class InteractsWithExceptionHandlingTest extends TestCase #[Test] public function withExceptionHandling_restore_exception_handling() { - $this->app = new Application(); + $this->app = new Application; $this->previousExceptionHandler = 'MyExceptionHandler'; $this->withExceptionHandling(); $this->assertEquals( @@ -33,8 +33,8 @@ public function withExceptionHandling_restore_exception_handling() #[Test] public function withoutExceptionHandling_disable_exception_handling_for_the_test() { - $this->app = new Application(); - $this->app->instance(ExceptionHandler::class, new ExceptionHandlerStub()); + $this->app = new Application; + $this->app->instance(ExceptionHandler::class, new ExceptionHandlerStub); $this->assertNull($this->previousExceptionHandler); $this->withoutExceptionHandling(); $this->assertInstanceOf( @@ -48,9 +48,8 @@ public function withExceptionHandling_throw_exception_NotFoundHttpException() { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('Abort 404'); - $this->app = new Application(); - $this->app->instance(ExceptionHandler::class, new class { - }); + $this->app = new Application; + $this->app->instance(ExceptionHandler::class, new class {}); $this->withoutExceptionHandling(); abort(404, 'Abort 404'); @@ -59,9 +58,8 @@ public function withExceptionHandling_throw_exception_NotFoundHttpException() #[Test] public function report_of_instance_ExceptionHandler_on_Application_does_nothing() { - $this->app = new Application(); - $this->app->instance(ExceptionHandler::class, new class { - }); + $this->app = new Application; + $this->app->instance(ExceptionHandler::class, new class {}); $this->withoutExceptionHandling(); $this->assertNull(app(ExceptionHandler::class)->report(new Exception)); @@ -73,9 +71,8 @@ public function render_of_instance_ExceptionHandler_on_Application_throw_excepti $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('GET http://localhost'); - $this->app = new Application(); - $this->app->instance(ExceptionHandler::class, new class { - }); + $this->app = new Application; + $this->app->instance(ExceptionHandler::class, new class {}); $request = new class { @@ -105,12 +102,10 @@ public function render_of_instance_ExceptionHandler_on_Application_throw_excepti $this->expectException(Exception::class); $this->expectExceptionMessage('My Exception'); - $this->app = new Application(); - $this->app->instance(ExceptionHandler::class, new class { - }); + $this->app = new Application; + $this->app->instance(ExceptionHandler::class, new class {}); - $request = new class { - }; + $request = new class {}; $this->withoutExceptionHandling(); @@ -120,9 +115,8 @@ public function render_of_instance_ExceptionHandler_on_Application_throw_excepti #[Test] public function renderForConsole_throw_exception_to_console_and_does_nothing() { - $this->app = new Application(); - $this->app->instance(ExceptionHandler::class, new class { - }); + $this->app = new Application; + $this->app->instance(ExceptionHandler::class, new class {}); $output = new OutputStub; $this->withoutExceptionHandling(); @@ -135,9 +129,8 @@ public function renderForConsole_throw_exception_to_console_and_does_nothing() #[Test] public function withoutExceptionHandling_doesnt_not_report_exceptions() { - $this->app = new Application(); - $this->app->instance(ExceptionHandler::class, new class { - }); + $this->app = new Application; + $this->app->instance(ExceptionHandler::class, new class {}); $this->withoutExceptionHandling(); $this->assertFalse( app(ExceptionHandler::class)->shouldReport(new NotFoundHttpException) diff --git a/tests/Unit/InteractsWithPagesTest.php b/tests/Unit/InteractsWithPagesTest.php index a11ae10..e6e7940 100644 --- a/tests/Unit/InteractsWithPagesTest.php +++ b/tests/Unit/InteractsWithPagesTest.php @@ -15,7 +15,9 @@ class InteractsWithPagesTest extends TestCase use InteractsWithPages; protected $app; + protected $response; + protected $currentUri; #[Test] diff --git a/tests/Unit/InteractsWithSessionTest.php b/tests/Unit/InteractsWithSessionTest.php index 7766074..0cd0957 100644 --- a/tests/Unit/InteractsWithSessionTest.php +++ b/tests/Unit/InteractsWithSessionTest.php @@ -35,8 +35,7 @@ public function wasCalledPutMethod($times) return $times == $this->put; } }; - $this->app['session.store'] = new class { - }; + $this->app['session.store'] = new class {}; $this->session([ 'foo' => 'bar', @@ -68,8 +67,7 @@ public function wasCalledPutMethod($times) return $times == $this->put; } }; - $this->app['session.store'] = new class { - }; + $this->app['session.store'] = new class {}; $this->withSession([ 'foo' => 'bar', @@ -133,8 +131,7 @@ public function isCalledFlushMethod() #[Test] public function check_if_exists_data_on_session_and_check_exist_key() { - $this->app['session'] = new class { - }; + $this->app['session'] = new class {}; $this->app['session.store'] = new class { public function get($key) @@ -157,8 +154,7 @@ public function has($key) #[Test] public function check_multi_data_on_session_and_check_multi_keys() { - $this->app['session'] = new class { - }; + $this->app['session'] = new class {}; $this->app['session.store'] = new class { protected $data = [ @@ -193,8 +189,7 @@ public function has($key) #[Test] public function check_not_exists_key_and_multi_key_on_session() { - $this->app['session'] = new class { - }; + $this->app['session'] = new class {}; $this->app['session.store'] = new class { public function has($key) @@ -209,8 +204,7 @@ public function has($key) #[Test] public function check_if_exists_errors_on_session() { - $this->app['session'] = new class { - }; + $this->app['session'] = new class {}; $this->app['session.store'] = new class { public function get($key) @@ -229,7 +223,7 @@ public function has($key) #[Test] public function check_if_exists_errors_with_value_on_session() { - $this->app = new Application(); + $this->app = new Application; $this->app['session.store'] = new class { public function get($key) @@ -254,8 +248,7 @@ public function has($key) #[Test] public function check_if_exists_old_input_on_session() { - $this->app['session'] = new class { - }; + $this->app['session'] = new class {}; $this->app['session.store'] = new class { public function has($key)