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

Fix some PHPStan errors #319

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/Bridge/Doctrine/Transport/Configuration/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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);
}

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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Middleware/TaskLockBagMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/SchedulePolicy/DeadlinePolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]));
}
Expand Down
63 changes: 46 additions & 17 deletions tests/Worker/FiberWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
63 changes: 46 additions & 17 deletions tests/Worker/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down