Skip to content

Commit 8db5741

Browse files
Fix PHP 8 compatibility
1 parent ec8d64a commit 8db5741

File tree

11 files changed

+39
-30
lines changed

11 files changed

+39
-30
lines changed

src/Command/RunHandlerCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7272
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
7373
$output->writeln(sprintf('Result: %s', json_encode($result)));
7474
}
75+
76+
return 0;
7577
}
7678
}

src/EventListener/RunListener.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Task\TaskBundle\EventListener;
1313

14-
use Symfony\Component\EventDispatcher\Event;
14+
use Symfony\Component\EventDispatcher\Event as LegacyEvent;
15+
use Symfony\Contracts\EventDispatcher\Event;
1516
use Task\Runner\TaskRunnerInterface;
1617

1718
/**
@@ -35,9 +36,9 @@ public function __construct(TaskRunnerInterface $taskRunner)
3536
/**
3637
* Run scheduled tasks.
3738
*
38-
* @param Event $event
39+
* @param Event|LegacyEvent $event
3940
*/
40-
public function run(Event $event)
41+
public function run($event)
4142
{
4243
$this->taskRunner->runTasks();
4344
}

tests/Functional/Command/DebugTasksCommandTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public function testExecute()
4646
);
4747

4848
$output = $this->commandTester->getDisplay();
49-
$this->assertContains($executions[0]->getUuid(), $output);
50-
$this->assertContains($executions[1]->getUuid(), $output);
51-
$this->assertContains('100000ms', $output);
52-
$this->assertContains('100ms', $output);
53-
$this->assertContains('completed', $output);
49+
$this->assertStringContainsString($executions[0]->getUuid(), $output);
50+
$this->assertStringContainsString($executions[1]->getUuid(), $output);
51+
$this->assertStringContainsString('100000ms', $output);
52+
$this->assertStringContainsString('100ms', $output);
53+
$this->assertStringContainsString('completed', $output);
5454
}
5555

5656
public function testExecutePaginated()
@@ -76,9 +76,9 @@ public function testExecutePaginated()
7676
);
7777

7878
$output = $this->commandTester->getDisplay();
79-
$this->assertContains($executions[0]->getUuid(), $output);
80-
$this->assertContains($executions[1]->getUuid(), $output);
81-
$this->assertNotContains($executions[2]->getUuid(), $output);
79+
$this->assertStringContainsString($executions[0]->getUuid(), $output);
80+
$this->assertStringContainsString($executions[1]->getUuid(), $output);
81+
$this->assertStringNotContainsString($executions[2]->getUuid(), $output);
8282

8383
$this->commandTester->execute(
8484
[
@@ -89,9 +89,9 @@ public function testExecutePaginated()
8989
);
9090

9191
$output = $this->commandTester->getDisplay();
92-
$this->assertNotContains($executions[0]->getUuid(), $output);
93-
$this->assertNotContains($executions[1]->getUuid(), $output);
94-
$this->assertContains($executions[2]->getUuid(), $output);
92+
$this->assertStringNotContainsString($executions[0]->getUuid(), $output);
93+
$this->assertStringNotContainsString($executions[1]->getUuid(), $output);
94+
$this->assertStringContainsString($executions[2]->getUuid(), $output);
9595

9696
$this->commandTester->execute(
9797
[
@@ -102,9 +102,9 @@ public function testExecutePaginated()
102102
);
103103

104104
$output = $this->commandTester->getDisplay();
105-
$this->assertNotContains($executions[0]->getUuid(), $output);
106-
$this->assertNotContains($executions[1]->getUuid(), $output);
107-
$this->assertNotContains($executions[2]->getUuid(), $output);
105+
$this->assertStringNotContainsString($executions[0]->getUuid(), $output);
106+
$this->assertStringNotContainsString($executions[1]->getUuid(), $output);
107+
$this->assertStringNotContainsString($executions[2]->getUuid(), $output);
108108
}
109109

110110
/**

tests/Functional/Command/RunCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testExecute()
4343
);
4444

4545
$execution = $this->taskExecutionRepository->findByUuid($executions[0]->getUuid());
46-
$this->assertEquals(TaskStatus::COMPLETED, $execution->getStatus(), $execution->getException());
46+
$this->assertEquals(TaskStatus::COMPLETED, $execution->getStatus(), $execution->getException() ?: '');
4747
$this->assertEquals(strrev('Test workload 1'), $execution->getResult());
4848
$this->assertGreaterThan(0, $execution->getDuration());
4949
$this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime());

tests/Functional/Command/RunHandlerCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testExecute()
3333
);
3434

3535
$output = $this->commandTester->getDisplay();
36-
$this->assertContains('No workload.', $output);
36+
$this->assertStringContainsString('No workload.', $output);
3737
}
3838

3939
public function testExecuteWithWorkload()
@@ -50,7 +50,7 @@ public function testExecuteWithWorkload()
5050
);
5151

5252
$output = $this->commandTester->getDisplay();
53-
$this->assertContains(strrev('Test workload 1'), $output);
53+
$this->assertStringContainsString(strrev('Test workload 1'), $output);
5454
}
5555

5656
public function testExecuteWithWorkloadNoVerbosity()

tests/Functional/Command/ScheduleSystemTasksCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testExecute()
2626
);
2727

2828
$output = $this->commandTester->getDisplay();
29-
$this->assertContains('System-tasks successfully scheduled', $output);
29+
$this->assertStringContainsString('System-tasks successfully scheduled', $output);
3030

3131
$taskRepository = self::$kernel->getContainer()->get('task.repository.task');
3232
$this->assertNotNull($taskRepository->findBySystemKey('testing'));

tests/Functional/Command/ScheduleTaskCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testExecuteWithWorkloadAndIntervalAndEndDate()
9494
$this->assertEquals(TestHandler::class, $tasks[0]->getHandlerClass());
9595
$this->assertEquals('Test workload 1', $tasks[0]->getWorkload());
9696
$this->assertEquals('0 * * * *', $tasks[0]->getInterval());
97-
$this->assertEquals($date, $tasks[0]->getLastExecution(), '', 2);
97+
$this->assertEquals($date->format('Y-m-d H:i:s'), $tasks[0]->getLastExecution()->format('Y-m-d H:i:s'));
9898
}
9999

100100
public function testExecuteWithExecutionDate()

tests/Functional/Handler/TaskHandlerFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Task\TaskBundle\Tests\Functional\Handler;
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
15+
use Task\Handler\TaskHandlerNotExistsException;
1516
use Task\TaskBundle\Handler\TaskHandlerFactory;
1617
use Task\TaskBundle\Tests\Functional\TestHandler;
1718

@@ -38,11 +39,10 @@ public function testCreate()
3839
$this->assertInstanceOf(TestHandler::class, $this->taskHandlerFactory->create(TestHandler::class));
3940
}
4041

41-
/**
42-
* @expectedException \Task\Handler\TaskHandlerNotExistsException
43-
*/
4442
public function testCreateNotExists()
4543
{
44+
$this->expectException(TaskHandlerNotExistsException::class);
45+
4646
$this->taskHandlerFactory->create(\stdClass::class);
4747
}
4848
}

tests/Unit/Builder/TaskBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testSetSystemKey()
2424

2525
public function testSetSystemKeyNotSupported()
2626
{
27-
$this->setExpectedException(NotSupportedMethodException::class);
27+
$this->expectException(NotSupportedMethodException::class);
2828

2929
$task = $this->prophesize(TaskInterface::class);
3030
$scheduler = $this->prophesize(TaskSchedulerInterface::class);

tests/Unit/EventListener/RunListenerTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
namespace Task\TaskBundle\Tests\Unit\EventListener;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\EventDispatcher\Event;
15+
use Symfony\Component\EventDispatcher\Event as LegacyEvent;
16+
use Symfony\Contracts\EventDispatcher\Event;
1617
use Task\Runner\TaskRunnerInterface;
1718
use Task\TaskBundle\EventListener\RunListener;
1819

@@ -23,7 +24,12 @@ class RunListenerTest extends TestCase
2324
{
2425
public function testRun()
2526
{
26-
$event = $this->prophesize(Event::class);
27+
if (\class_exists(LegacyEvent::class)) {
28+
$event = $this->prophesize(LegacyEvent::class);
29+
} else {
30+
$event = $this->prophesize(Event::class);
31+
}
32+
2733
$taskRunner = $this->prophesize(TaskRunnerInterface::class);
2834

2935
$listener = new RunListener($taskRunner->reveal());

tests/Unit/Handler/TaskHandlerFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testCreate()
3131

3232
public function testCreateNotExists()
3333
{
34-
$this->setExpectedException(TaskHandlerNotExistsException::class);
34+
$this->expectException(TaskHandlerNotExistsException::class);
3535

3636
$taskHandlerFactory = new TaskHandlerFactory([TestHandler::class => new TestHandler()]);
3737

@@ -40,7 +40,7 @@ public function testCreateNotExists()
4040

4141
public function testCreateNoHandler()
4242
{
43-
$this->setExpectedException(TaskHandlerNotExistsException::class);
43+
$this->expectException(TaskHandlerNotExistsException::class);
4444

4545
$taskHandlerFactory = new TaskHandlerFactory([]);
4646

0 commit comments

Comments
 (0)