From 86c3e9e50f392772b474884546718a632ac3d888 Mon Sep 17 00:00:00 2001 From: jmsche Date: Mon, 19 Jun 2023 09:39:45 +0200 Subject: [PATCH 1/3] Fix some PHPStan errors --- src/Bridge/Doctrine/Transport/Configuration/Connection.php | 3 ++- tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php | 2 +- .../EventListener/StopWorkerOnFailureLimitSubscriberTest.php | 4 ++-- tests/Middleware/TaskLockBagMiddlewareTest.php | 2 +- tests/SchedulePolicy/DeadlinePolicyTest.php | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Bridge/Doctrine/Transport/Configuration/Connection.php b/src/Bridge/Doctrine/Transport/Configuration/Connection.php index 5c73461b..8953675c 100644 --- a/src/Bridge/Doctrine/Transport/Configuration/Connection.php +++ b/src/Bridge/Doctrine/Transport/Configuration/Connection.php @@ -5,6 +5,7 @@ namespace SchedulerBundle\Bridge\Doctrine\Transport\Configuration; use Closure; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection as DbalConnection; use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; @@ -45,7 +46,7 @@ public function init(array $options, array $extraOptions = []): void $qb = $this->createQueryBuilder(self::TABLE_NAME, 'stc'); $existingKeysQuery = $qb->select('stc.configuration_key_name') ->where($qb->expr()->in('stc.configuration_key_name', ':keys')) - ->setParameter('keys', array_keys($options), DbalConnection::PARAM_STR_ARRAY) + ->setParameter('keys', array_keys($options), ArrayParameterType::STRING) ; $existingConfigurationKeys = $this->executeQuery( diff --git a/tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php b/tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php index ade83f73..6a03c374 100644 --- a/tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php +++ b/tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php @@ -49,7 +49,7 @@ public function testTransportCanBeBuilt(): void self::assertSame($dsn->getPort(), $transport->getConfiguration()->get('port')); self::assertSame($dsn->getScheme(), $transport->getConfiguration()->get('scheme')); self::assertSame($dsn->getOption('timeout', 30), $transport->getConfiguration()->get('timeout')); - self::assertSame($dsn->getOption('auth'), $this->transport->getConfiguration()->get('auth')); + self::assertSame($dsn->getOption('auth'), $transport->getConfiguration()->get('auth')); self::assertArrayHasKey('execution_mode', $transport->getConfiguration()->toArray()); self::assertSame('first_in_first_out', $transport->getConfiguration()->get('execution_mode')); self::assertArrayHasKey('list', $transport->getConfiguration()->toArray()); diff --git a/tests/EventListener/StopWorkerOnFailureLimitSubscriberTest.php b/tests/EventListener/StopWorkerOnFailureLimitSubscriberTest.php index fa23eef8..64921622 100644 --- a/tests/EventListener/StopWorkerOnFailureLimitSubscriberTest.php +++ b/tests/EventListener/StopWorkerOnFailureLimitSubscriberTest.php @@ -26,7 +26,7 @@ public function testSubscriberListenValidEvents(): void public function testSubscriberCannotUseNegativeLimit(): void { self::expectException(InvalidArgumentException::class); - self::expectErrorMessage('The failure limit must be greater than 0, given -1'); + self::expectExceptionMessage('The failure limit must be greater than 0, given -1'); self::expectExceptionCode(0); new StopWorkerOnFailureLimitSubscriber(-1); } @@ -34,7 +34,7 @@ public function testSubscriberCannotUseNegativeLimit(): void public function testSubscriberCannotUseZeroLimit(): void { self::expectException(InvalidArgumentException::class); - self::expectErrorMessage('The failure limit must be greater than 0, given 0'); + self::expectExceptionMessage('The failure limit must be greater than 0, given 0'); self::expectExceptionCode(0); new StopWorkerOnFailureLimitSubscriber(0); } diff --git a/tests/Middleware/TaskLockBagMiddlewareTest.php b/tests/Middleware/TaskLockBagMiddlewareTest.php index 07fc2e10..0620460b 100644 --- a/tests/Middleware/TaskLockBagMiddlewareTest.php +++ b/tests/Middleware/TaskLockBagMiddlewareTest.php @@ -47,7 +47,7 @@ public function testMiddlewareCannotReleaseTaskAfterExecutionWithoutAccessLockBa $middleware = new TaskLockBagMiddleware($lockFactory, $logger); self::expectException(RuntimeException::class); - self::expectErrorMessage(sprintf('The task "foo" must be linked to an access lock bag, consider using %s::execute() or %s::schedule()', WorkerInterface::class, SchedulerInterface::class)); + self::expectExceptionMessage(sprintf('The task "foo" must be linked to an access lock bag, consider using %s::execute() or %s::schedule()', WorkerInterface::class, SchedulerInterface::class)); self::expectExceptionCode(0); $middleware->postExecute(new NullTask('foo'), $worker); } diff --git a/tests/SchedulePolicy/DeadlinePolicyTest.php b/tests/SchedulePolicy/DeadlinePolicyTest.php index 55df1211..75afb56e 100644 --- a/tests/SchedulePolicy/DeadlinePolicyTest.php +++ b/tests/SchedulePolicy/DeadlinePolicyTest.php @@ -39,7 +39,7 @@ public function testTasksCannotBeSortedWithoutArrivalTime(): void $deadlinePolicy = new DeadlinePolicy(); self::expectException(RuntimeException::class); - self::expectDeprecationMessage('The arrival time must be defined, consider executing the task "foo" first'); + self::expectExceptionMessage('The arrival time must be defined, consider executing the task "foo" first'); self::expectExceptionCode(0); $deadlinePolicy->sort(new TaskList([ $secondTask, @@ -62,7 +62,7 @@ public function testTasksCannotBeSortedWithoutExecutionRelativeDeadline(): void $deadlinePolicy = new DeadlinePolicy(); self::expectException(RuntimeException::class); - self::expectDeprecationMessage('The execution relative deadline must be defined, consider using SchedulerBundle\Task\TaskInterface::setExecutionRelativeDeadline()'); + self::expectExceptionMessage('The execution relative deadline must be defined, consider using SchedulerBundle\Task\TaskInterface::setExecutionRelativeDeadline()'); self::expectExceptionCode(0); $deadlinePolicy->sort(new TaskList([$secondTask, $task])); } From e1824d7bbab16e9497fc107f1eaa62f0168a3a3c Mon Sep 17 00:00:00 2001 From: jmsche Date: Mon, 19 Jun 2023 09:45:35 +0200 Subject: [PATCH 2/3] Require dbal version corresponding to new constant --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4249623a..eee25a46 100644 --- a/composer.json +++ b/composer.json @@ -129,7 +129,7 @@ "ext-pcntl": "*", "ext-pdo": "*", "ext-redis": "*", - "doctrine/dbal": "^3.3.6", + "doctrine/dbal": "^3.6.0", "doctrine/orm": "^2.8", "friendsofphp/php-cs-fixer": "^3.13", "infection/infection": "^0.26.16", From ed3b107b93c21e4ca755aeed76cf4ad79caca44d Mon Sep 17 00:00:00 2001 From: jmsche Date: Mon, 19 Jun 2023 23:23:07 +0200 Subject: [PATCH 3/3] Start fixing PHPUnit deprecated calls --- tests/Worker/FiberWorkerTest.php | 63 +++++++++++++++++++++++--------- tests/Worker/WorkerTest.php | 63 +++++++++++++++++++++++--------- 2 files changed, 92 insertions(+), 34 deletions(-) diff --git a/tests/Worker/FiberWorkerTest.php b/tests/Worker/FiberWorkerTest.php index 2a362e6b..df30e88e 100644 --- a/tests/Worker/FiberWorkerTest.php +++ b/tests/Worker/FiberWorkerTest.php @@ -536,8 +536,28 @@ public function testTaskCanBeExecutedWithErroredAfterExecutionCallback(): void $logger->expects(self::never())->method('info'); $tracker = $this->createMock(TaskExecutionTrackerInterface::class); - $tracker->expects(self::exactly(2))->method('startTracking')->withConsecutive([$task], [$validTask]); - $tracker->expects(self::exactly(2))->method('endTracking')->withConsecutive([$task], [$validTask]); + + $startTrackingMatcher = self::exactly(2); + $tracker + ->expects($startTrackingMatcher) + ->method('startTracking') + ->willReturnCallback(function (NullTask $param) use ($startTrackingMatcher, $task, $validTask): void { + match ($startTrackingMatcher->getInvocationCount()) { + 1 => self::assertSame($param, $task), + 2 => self::assertSame($param, $validTask), + }; + }); + + $endTrackingMatcher = self::exactly(2); + $tracker + ->expects($endTrackingMatcher) + ->method('endTracking') + ->willReturnCallback(function ($param) use ($endTrackingMatcher, $task, $validTask) { + match ($endTrackingMatcher->getInvocationCount()) { + 1 => self::assertSame($param, $task), + 2 => self::assertSame($param, $validTask), + }; + }); $transport = new InMemoryTransport(new InMemoryConfiguration(), new SchedulePolicyOrchestrator([ new FirstInFirstOutPolicy(), @@ -1305,21 +1325,30 @@ public function testPausedTaskIsNotExecutedIfListContainsASingleTask(): void $tracker = $this->createMock(TaskExecutionTrackerInterface::class); $logger = $this->createMock(LoggerInterface::class); - $logger->expects(self::exactly(2))->method('info')->withConsecutive([ - self::equalTo('The following task "bar" is paused|disabled, consider enable it if it should be executed!'), - [ - 'name' => 'bar', - 'expression' => '* * * * *', - 'state' => TaskInterface::PAUSED, - ], - ], [ - self::equalTo('The following task "foo" is paused|disabled, consider enable it if it should be executed!'), - [ - 'name' => 'foo', - 'expression' => '* * * * *', - 'state' => TaskInterface::PAUSED, - ], - ]); + $matcher = self::exactly(2); + $logger + ->expects($matcher) + ->method('info') + ->willReturnCallback(function () use ($matcher): void { + match ($matcher->getInvocationCount()) { + 1 => [ + self::equalTo('The following task "bar" is paused|disabled, consider enable it if it should be executed!'), + [ + 'name' => 'bar', + 'expression' => '* * * * *', + 'state' => TaskInterface::PAUSED, + ] + ], + 2 => [ + self::equalTo('The following task "foo" is paused|disabled, consider enable it if it should be executed!'), + [ + 'name' => 'foo', + 'expression' => '* * * * *', + 'state' => TaskInterface::PAUSED, + ], + ], + }; + }); $transport = new InMemoryTransport(new InMemoryConfiguration(), new SchedulePolicyOrchestrator([ new FirstInFirstOutPolicy(), diff --git a/tests/Worker/WorkerTest.php b/tests/Worker/WorkerTest.php index 67f9b891..25685d67 100644 --- a/tests/Worker/WorkerTest.php +++ b/tests/Worker/WorkerTest.php @@ -508,8 +508,28 @@ public function testTaskCanBeExecutedWithErroredAfterExecutionCallback(): void $logger->expects(self::never())->method('info'); $tracker = $this->createMock(TaskExecutionTrackerInterface::class); - $tracker->expects(self::exactly(2))->method('startTracking')->withConsecutive([$task], [$validTask]); - $tracker->expects(self::exactly(2))->method('endTracking')->withConsecutive([$task], [$validTask]); + + $startTrackingMatcher = self::exactly(2); + $tracker + ->expects($startTrackingMatcher) + ->method('startTracking') + ->willReturnCallback(function (NullTask $param) use ($startTrackingMatcher, $task, $validTask): void { + match ($startTrackingMatcher->getInvocationCount()) { + 1 => self::assertSame($param, $task), + 2 => self::assertSame($param, $validTask), + }; + }); + + $endTrackingMatcher = self::exactly(2); + $tracker + ->expects($endTrackingMatcher) + ->method('endTracking') + ->willReturnCallback(function ($param) use ($endTrackingMatcher, $task, $validTask) { + match ($endTrackingMatcher->getInvocationCount()) { + 1 => self::assertSame($param, $task), + 2 => self::assertSame($param, $validTask), + }; + }); $transport = new InMemoryTransport(new InMemoryConfiguration(), new SchedulePolicyOrchestrator([ new FirstInFirstOutPolicy(), @@ -1231,21 +1251,30 @@ public function testPausedTaskIsNotExecutedIfListContainsASingleTask(): void $tracker = $this->createMock(TaskExecutionTrackerInterface::class); $logger = $this->createMock(LoggerInterface::class); - $logger->expects(self::exactly(2))->method('info')->withConsecutive([ - self::equalTo('The following task "bar" is paused|disabled, consider enable it if it should be executed!'), - [ - 'name' => 'bar', - 'expression' => '* * * * *', - 'state' => TaskInterface::PAUSED, - ], - ], [ - self::equalTo('The following task "foo" is paused|disabled, consider enable it if it should be executed!'), - [ - 'name' => 'foo', - 'expression' => '* * * * *', - 'state' => TaskInterface::PAUSED, - ], - ]); + $matcher = self::exactly(2); + $logger + ->expects($matcher) + ->method('info') + ->willReturnCallback(function () use ($matcher): void { + match ($matcher->getInvocationCount()) { + 1 => [ + self::equalTo('The following task "bar" is paused|disabled, consider enable it if it should be executed!'), + [ + 'name' => 'bar', + 'expression' => '* * * * *', + 'state' => TaskInterface::PAUSED, + ] + ], + 2 => [ + self::equalTo('The following task "foo" is paused|disabled, consider enable it if it should be executed!'), + [ + 'name' => 'foo', + 'expression' => '* * * * *', + 'state' => TaskInterface::PAUSED, + ], + ], + }; + }); $transport = new InMemoryTransport(new InMemoryConfiguration(), new SchedulePolicyOrchestrator([ new FirstInFirstOutPolicy(),