From 943b3def1010bf93804888bdb7ee4fefc807c188 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sat, 10 Aug 2024 15:16:47 +0200 Subject: [PATCH] add phpunit 11 support --- composer.json | 6 +-- tests/TestCase/Command/WorkerCommandTest.php | 37 +++++++------------ .../LimitAttemptsExtensionTest.php | 7 ++-- ...emoveUniqueJobIdFromCacheExtensionTest.php | 7 ++-- .../Listener/FailedJobsListenerTest.php | 3 +- tests/TestCase/Mailer/QueueTraitTest.php | 5 +-- tests/TestCase/Queue/ProcessorTest.php | 5 ++- 7 files changed, 30 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index a9fb670..38288a6 100644 --- a/composer.json +++ b/composer.json @@ -22,15 +22,15 @@ }, "require": { "php": ">=8.1", - "cakephp/cakephp": "^5.0.0", + "cakephp/cakephp": "dev-5.next as 5.1.0", "enqueue/simple-client": "^0.10", "psr/log": "^3.0" }, "require-dev": { - "cakephp/bake": "^3.0.0", + "cakephp/bake": "dev-3.next", "cakephp/cakephp-codesniffer": "^5.0", "enqueue/fs": "^0.10", - "phpunit/phpunit": "^10.1.0" + "phpunit/phpunit": "^10.5.5 || ^11.1.3" }, "suggest": { "cakephp/bake": "Required if you want to generate jobs.", diff --git a/tests/TestCase/Command/WorkerCommandTest.php b/tests/TestCase/Command/WorkerCommandTest.php index 38f458a..5bc49b0 100644 --- a/tests/TestCase/Command/WorkerCommandTest.php +++ b/tests/TestCase/Command/WorkerCommandTest.php @@ -23,6 +23,8 @@ use Cake\Queue\Test\test_app\src\Job\LogToDebugWithServiceJob; use Cake\Queue\Test\TestCase\DebugLogTrait; use Cake\TestSuite\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use TestApp\Job\LogToDebugJob; use TestApp\Job\RequeueJob; use TestApp\WelcomeMailerListener; @@ -48,9 +50,8 @@ public function testDescriptionOutput() /** * Test that queue will run for one second - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesStart() { Configure::write('Queue', [ @@ -65,9 +66,8 @@ public function testQueueProcessesStart() /** * Test that queue will run for one second with valid listener - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesWithListener() { Configure::write('Queue', [ @@ -83,9 +83,8 @@ public function testQueueProcessesWithListener() /** * Test that queue will abort when the passed config is not present in the app configuration. - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueWillAbortWithMissingConfig() { Configure::write('Queue', [ @@ -102,9 +101,8 @@ public function testQueueWillAbortWithMissingConfig() /** * Test that queue will abort with invalid listener - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesWithInvalidListener() { Configure::write('Queue', [ @@ -121,9 +119,8 @@ public function testQueueProcessesWithInvalidListener() /** * Test that queue will write to specified logger option - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesWithLogger() { Configure::write('Queue', [ @@ -156,10 +153,9 @@ public static function dataProviderCallableTypes(): array /** * Start up the worker queue, push a job, and see that it processes - * - * @dataProvider dataProviderCallableTypes - * @runInSeparateProcess */ + #[DataProvider('dataProviderCallableTypes')] + #[RunInSeparateProcess] public function testQueueProcessesJob($callable) { $config = [ @@ -185,9 +181,8 @@ public function testQueueProcessesJob($callable) /** * Set the processor name, Start up the worker queue, push a job, and see that it processes - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesJobWithProcessor() { $config = [ @@ -212,9 +207,8 @@ public function testQueueProcessesJobWithProcessor() /** * Test non-default queue name - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesJobWithOtherQueue() { $config = [ @@ -240,9 +234,8 @@ public function testQueueProcessesJobWithOtherQueue() /** * Test max-attempts option - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesJobWithMaxAttempts() { $config = [ @@ -268,9 +261,8 @@ public function testQueueProcessesJobWithMaxAttempts() /** * Test DI service injection works in tasks - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesJobWithDIService() { $this->skipIf(version_compare(Configure::version(), '4.2', '<'), 'DI Container is only available since CakePHP 4.2'); @@ -296,9 +288,8 @@ public function testQueueProcessesJobWithDIService() /** * Test that queue will process when a unique cache is configured. - * - * @runInSeparateProcess */ + #[RunInSeparateProcess] public function testQueueProcessesWithUniqueCacheConfigured() { $config = [ diff --git a/tests/TestCase/Consumption/LimitAttemptsExtensionTest.php b/tests/TestCase/Consumption/LimitAttemptsExtensionTest.php index 7094d47..709dcac 100644 --- a/tests/TestCase/Consumption/LimitAttemptsExtensionTest.php +++ b/tests/TestCase/Consumption/LimitAttemptsExtensionTest.php @@ -13,6 +13,8 @@ use Cake\Queue\Test\TestCase\DebugLogTrait; use Cake\TestSuite\TestCase; use Enqueue\Consumption\ChainExtension; +use PHPUnit\Framework\Attributes\After; +use PHPUnit\Framework\Attributes\BeforeClass; use Psr\Log\NullLogger; use TestApp\Job\MaxAttemptsIsThreeJob; use TestApp\Job\RequeueJob; @@ -28,10 +30,7 @@ public function setUp(): void EventManager::instance()->setEventList(new EventList()); } - /** - * @beforeClass - * @after - */ + #[BeforeClass, After] public static function dropConfigs() { Log::drop('debug'); diff --git a/tests/TestCase/Consumption/RemoveUniqueJobIdFromCacheExtensionTest.php b/tests/TestCase/Consumption/RemoveUniqueJobIdFromCacheExtensionTest.php index 9d09e2a..01102df 100644 --- a/tests/TestCase/Consumption/RemoveUniqueJobIdFromCacheExtensionTest.php +++ b/tests/TestCase/Consumption/RemoveUniqueJobIdFromCacheExtensionTest.php @@ -11,15 +11,14 @@ use Cake\Queue\QueueManager; use Cake\TestSuite\TestCase; use Enqueue\Consumption\ChainExtension; +use PHPUnit\Framework\Attributes\After; +use PHPUnit\Framework\Attributes\BeforeClass; use Psr\Log\NullLogger; use TestApp\Job\UniqueJob; class RemoveUniqueJobIdFromCacheExtensionTest extends TestCase { - /** - * @beforeClass - * @after - */ + #[BeforeClass, After] public static function dropConfigs() { Log::drop('debug'); diff --git a/tests/TestCase/Listener/FailedJobsListenerTest.php b/tests/TestCase/Listener/FailedJobsListenerTest.php index b126260..d08f0cf 100644 --- a/tests/TestCase/Listener/FailedJobsListenerTest.php +++ b/tests/TestCase/Listener/FailedJobsListenerTest.php @@ -28,6 +28,7 @@ use Cake\TestSuite\TestCase; use Enqueue\Null\NullConnectionFactory; use Enqueue\Null\NullMessage; +use PHPUnit\Framework\Attributes\DataProvider; use RuntimeException; use stdClass; use TestApp\Job\LogToDebugJob; @@ -113,9 +114,9 @@ public static function storeFailedJobExceptionDataProvider() } /** - * @dataProvider storeFailedJobExceptionDataProvider * @return void */ + #[DataProvider('storeFailedJobExceptionDataProvider')] public function testStoreFailedJobException($eventData, $exceptionMessage) { $tableLocator = $this diff --git a/tests/TestCase/Mailer/QueueTraitTest.php b/tests/TestCase/Mailer/QueueTraitTest.php index 93d067b..f706aae 100644 --- a/tests/TestCase/Mailer/QueueTraitTest.php +++ b/tests/TestCase/Mailer/QueueTraitTest.php @@ -19,6 +19,7 @@ use Cake\Mailer\Exception\MissingActionException; use Cake\Queue\QueueManager; use Cake\TestSuite\TestCase; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use TestApp\WelcomeMailer; class QueueTraitTest extends TestCase @@ -38,10 +39,8 @@ public function testQueueTraitTestThrowsMissingActionException() /** * Test that QueueTrait calls push - * - * @runInSeparateProcess - * @return @void */ + #[RunInSeparateProcess] public function testQueueTraitCallsPush() { $queue = new WelcomeMailer(); diff --git a/tests/TestCase/Queue/ProcessorTest.php b/tests/TestCase/Queue/ProcessorTest.php index ec8bbab..3baf907 100644 --- a/tests/TestCase/Queue/ProcessorTest.php +++ b/tests/TestCase/Queue/ProcessorTest.php @@ -25,6 +25,7 @@ use Enqueue\Null\NullConnectionFactory; use Enqueue\Null\NullMessage; use Interop\Queue\Processor as InteropProcessor; +use PHPUnit\Framework\Attributes\DataProvider; use TestApp\TestProcessor; class ProcessorTest extends TestCase @@ -53,10 +54,10 @@ public static function dataProviderTestProcess(): array * @param string $jobMethod The method name to run * @param string $expected The expected process result. * @param string $logMessage The log message based on process result. - * @param string $dispacthedEvent The dispatched event based on process result. - * @dataProvider dataProviderTestProcess + * @param string $dispatchedEvent The dispatched event based on process result. * @return void */ + #[DataProvider('dataProviderTestProcess')] public function testProcess($jobMethod, $expected, $logMessage, $dispatchedEvent) { $messageBody = [