From b9d4448b225199baa4b30fcf8e1d02708eb2b2aa Mon Sep 17 00:00:00 2001 From: Minh Vuong Date: Sun, 16 Jul 2023 13:07:19 +0700 Subject: [PATCH] feat: bump Laravel & PHPUnit to latest versions --- .gitignore | 4 ++-- CHANGELOG.md | 5 +++++ composer.json | 4 ++-- phpunit.xml.dist | 13 +++++++------ tests/EventTestClass.php | 8 +++++--- tests/JobTest.php | 29 +++++++++++++++++++---------- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index b9e1080..386cfa6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .buildpath .project .settings -.phpunit.result.cache +.phpunit.cache .idea build composer.lock @@ -11,4 +11,4 @@ nbproject vendor phpunit.phar phpunit.xml -Thumbs.db \ No newline at end of file +Thumbs.db diff --git a/CHANGELOG.md b/CHANGELOG.md index 61d3005..99ce1b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.0.0 + +- Add support Laravel 10 and drop support Laravel 9. +- Bump version and migrate syntax of PHPUnit. + ## 3.0.0 - Drop support for older Laravel versions lower than 9. diff --git a/composer.json b/composer.json index 6a28d8b..a46881d 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ ], "require": { "php": "^8.1", - "illuminate/support": "^9.0", + "illuminate/support": "^10.0", "spatie/async": "^1.5" }, "require-dev": { - "orchestra/testbench": "^7.0", + "orchestra/testbench": "^8.0", "symplify/easy-coding-standard": "^11.2" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 818b75d..9388cdc 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,14 @@ - - - - src/ - - + + tests + + + src/ + + diff --git a/tests/EventTestClass.php b/tests/EventTestClass.php index 203aa49..65a4ed7 100644 --- a/tests/EventTestClass.php +++ b/tests/EventTestClass.php @@ -10,15 +10,17 @@ use Exception; -class EventTestClass extends TestCase +class EventTestClass { + public string|Exception $capture; + public function success($result) { - $this->assertStringContainsString('ok!', $result); + $this->capture = $result; } public function catch(Exception $exception) { - $this->assertStringContainsString('ok!', $exception->getMessage()); + $this->capture = $exception; } } diff --git a/tests/JobTest.php b/tests/JobTest.php index 6046aa4..cb7b9b4 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -9,46 +9,55 @@ namespace VXM\Async\Tests; use Async; +use PHPUnit\Framework\Attributes\DataProvider; use VXM\Async\Pool; class JobTest extends TestCase { - /** - * @dataProvider successJobProvider - */ + protected function setUp(): void + { + parent::setUp(); + + $this->app->forgetInstance(EventTestClass::class); + $this->app->singleton(EventTestClass::class); + } + + #[DataProvider('successJobProvider')] public function testHandleSuccess($handler, array $events): void { Async::run($handler, $events); $this->assertStringContainsString('ok!', current(Async::wait())); + $this->assertStringContainsString('ok!', $this->app->get(EventTestClass::class)->capture); } public function testBatchHandleSuccess(): void { - Async::batchRun(...$this->successJobProvider()); + Async::batchRun(...self::successJobProvider()); foreach (Async::wait() as $result) { $this->assertStringContainsString('ok!', $result); + $this->assertStringContainsString('ok!', $this->app->get(EventTestClass::class)->capture); } } - /** - * @dataProvider errorJobProvider - */ + #[DataProvider('errorJobProvider')] public function testHandleError($handler, array $events): void { Async::run($handler, $events); $results = array_filter(Async::wait()); $this->assertEmpty($results); + $this->assertInstanceOf(\Exception::class, $this->app->get(EventTestClass::class)->capture); } public function testBatchHandleError(): void { - Async::batchRun(...$this->errorJobProvider()); + Async::batchRun(...self::errorJobProvider()); $results = array_filter(Async::wait()); $this->assertEmpty($results); + $this->assertInstanceOf(\Exception::class, $this->app->get(EventTestClass::class)->capture); } public function testMaxOutputLength(): void @@ -64,7 +73,7 @@ public function testMaxOutputLength(): void } } - public function successJobProvider(): array + public static function successJobProvider(): array { return [ [ @@ -90,7 +99,7 @@ function () { ]; } - public function errorJobProvider(): array + public static function errorJobProvider(): array { return [ [