Skip to content

Commit aad451d

Browse files
authored
Add symfony 6 comptability (#54)
* Add symfony 6 comptability * Fix doctrine storage * Fix unit test * Update php-task version
1 parent 3dc0df7 commit aad451d

File tree

9 files changed

+69
-99
lines changed

9 files changed

+69
-99
lines changed

.github/workflows/test-application.yaml

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,23 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
include:
24-
- php-version: '5.6'
25-
dependencies: 'lowest'
26-
storage: doctrine
27-
- php-version: '5.6'
28-
storage: doctrine
29-
- php-version: '5.6'
30-
storage: array
31-
32-
- php-version: '7.0'
33-
dependencies: 'lowest'
34-
storage: doctrine
35-
- php-version: '7.0'
36-
storage: doctrine
37-
- php-version: '7.0'
38-
storage: array
39-
40-
- php-version: '7.1'
41-
dependencies: 'lowest'
42-
storage: doctrine
43-
- php-version: '7.1'
44-
storage: doctrine
45-
- php-version: '7.1'
46-
storage: array
47-
48-
- php-version: '7.2'
49-
dependencies: 'lowest'
50-
storage: doctrine
51-
- php-version: '7.2'
52-
storage: doctrine
53-
- php-version: '7.2'
54-
storage: array
55-
56-
- php-version: '7.3'
57-
storage: doctrine
58-
- php-version: '7.3'
59-
storage: array
60-
61-
- php-version: '7.4'
24+
- php-version: '8.0'
6225
coverage: '--coverage-clover=coverage.clover'
6326
storage: doctrine
64-
- php-version: '7.4'
27+
- php-version: '8.0'
6528
storage: array
6629

67-
- php-version: '8.0'
30+
- php-version: '8.1'
6831
storage: doctrine
69-
- php-version: '8.0'
32+
- php-version: '8.1'
7033
storage: array
71-
7234
steps:
7335
- name: Checkout project
7436
uses: actions/checkout@v2
37+
with:
38+
# Fetch 10 commits or Scrutinizer will throw ("Failed to retrieve commit parents. If you use a shallow git checkout, please checkout at least a depth of one."), see: RepositoryIntrospector at scrutinizer-ci/ocular GitHub repository
39+
# 10 commits is an arbitrary value that is more than 1 commit
40+
fetch-depth: 10
7541

7642
- name: Install and configure PHP
7743
uses: shivammathur/setup-php@v2
@@ -82,7 +48,7 @@ jobs:
8248
tools: 'composer:v2'
8349

8450
- name: Install dependencies with Composer
85-
uses: ramsey/composer-install@v1
51+
uses: ramsey/composer-install@v2
8652
with:
8753
dependency-versions: ${{ matrix.dependencies }}
8854
composer-options: --prefer-dist --no-suggest
@@ -99,5 +65,5 @@ jobs:
9965
- name: Coverage
10066
if: matrix.coverage
10167
run: |
102-
wget https://scrutinizer-ci.com/ocular.phar
103-
php ocular.phar code-coverage:upload --access-token="230ec5e01daf5bb3e46ea304fb20348b52d80de73463ec08ee9c96fcd1349e35" --format=php-clover coverage.clover
68+
composer global require scrutinizer/ocular
69+
~/.composer/vendor/bin/ocular code-coverage:upload --access-token="230ec5e01daf5bb3e46ea304fb20348b52d80de73463ec08ee9c96fcd1349e35" --format=php-clover coverage.clover

composer.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^5.6 || ^7.0 || ^8.0",
14-
"php-task/php-task": "^1.4",
15-
"symfony/http-kernel": "^2.8 || ^3.4 || ^4.0 || ^5.0",
16-
"symfony/dependency-injection": "^2.8 || ^3.4 || ^4.0 || ^5.0",
17-
"symfony/expression-language": "^2.8 || ^3.4 || ^4.0 || ^5.0",
18-
"symfony/config": "^2.8 || ^3.4 || ^4.0 || ^5.0",
19-
"symfony/console": "^2.8 || ^3.4 || ^4.0 || ^5.0",
20-
"symfony/process": "^2.8 || ^3.4 || ^4.0 || ^5.0",
21-
"doctrine/orm": "^2.5"
13+
"php": "^8.0 || ^8.1",
14+
"php-task/php-task": "^2.0",
15+
"symfony/http-kernel": "^5.4 || ^6.0",
16+
"symfony/dependency-injection": "^5.4 || ^6.0",
17+
"symfony/expression-language": "^5.4 || ^6.0",
18+
"symfony/config": "^5.4 || ^6.0",
19+
"symfony/console": "^5.4 || ^6.0",
20+
"symfony/process": "^5.4 || ^6.0",
21+
"doctrine/orm": "^2.5.3"
2222
},
2323
"require-dev": {
24-
"symfony/debug": "^2.8 || ^3.4 || ^4.0 || ^5.0",
25-
"symfony/framework-bundle": "^2.8.18 || ^3.4 || ^4.0 || ^5.0",
26-
"symfony/finder": "^2.8 || ^3.4 || ^4.0 || ^5.0",
27-
"symfony/yaml": "^2.8 || ^3.4 || ^4.0 || ^5.0",
28-
"symfony/phpunit-bridge": "^5.2.3",
24+
"symfony/framework-bundle": "^5.4 || ^6.0",
25+
"symfony/finder": "^5.4 || ^6.0",
26+
"symfony/yaml": "^5.4 || ^6.0",
27+
"symfony/phpunit-bridge": "^5.4 || ^6.0",
2928
"doctrine/doctrine-bundle": "^1.5 || ^2.0",
30-
"doctrine/data-fixtures": "^1.1"
29+
"doctrine/data-fixtures": "^1.3.3"
3130
},
3231
"autoload": {
3332
"psr-4": {

src/Command/ExecuteCommand.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20-
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2120
use Task\Event\Events;
2221
use Task\Event\TaskEvent;
2322
use Task\Event\TaskExecutionEvent;
@@ -82,9 +81,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
8281
$handler = $this->handlerFactory->create($execution->getHandlerClass());
8382

8483
try {
85-
$this->dispatch(Events::TASK_BEFORE, new TaskEvent($execution->getTask()));
84+
$this->eventDispatcher->dispatch(new TaskEvent($execution->getTask()), Events::TASK_BEFORE);
8685
$result = $handler->handle($execution->getWorkload());
87-
$this->dispatch(Events::TASK_AFTER, new TaskExecutionEvent($execution->getTask(), $execution));
86+
$this->eventDispatcher->dispatch(
87+
new TaskExecutionEvent($execution->getTask(), $execution),
88+
Events::TASK_AFTER
89+
);
8890
} catch (\Exception $exception) {
8991
if ($exception instanceof FailedException) {
9092
$errorOutput->writeln(FailedException::class);
@@ -105,17 +107,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
105107
/**
106108
* {@inheritdoc}
107109
*/
108-
public function isHidden()
110+
public function isHidden(): bool
109111
{
110112
return true;
111113
}
112-
113-
private function dispatch($eventName, $event)
114-
{
115-
if (class_exists(LegacyEventDispatcherProxy::class)) {
116-
return $this->eventDispatcher->dispatch($event, $eventName);
117-
} else {
118-
return $this->eventDispatcher->dispatch($eventName, $event);
119-
}
120-
}
121114
}

src/Resources/config/storage/doctrine.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<service id="task.repository.task" class="Task\TaskBundle\Entity\TaskRepository" public="true">
77
<factory service="doctrine.orm.entity_manager" method="getRepository"/>
88

9-
<argument type="string">TaskBundle:Task</argument>
9+
<argument type="string">Task\TaskBundle\Entity\Task</argument>
1010
</service>
1111
<service id="task.storage.task" alias="task.repository.task" public="true"/>
1212

1313
<service id="task.repository.task_execution" class="Task\TaskBundle\Entity\TaskExecutionRepository" public="true">
1414
<factory service="doctrine.orm.entity_manager" method="getRepository"/>
1515

16-
<argument type="string">TaskBundle:TaskExecution</argument>
16+
<argument type="string">Task\TaskBundle\Entity\TaskExecution</argument>
1717
</service>
1818
<service id="task.storage.task_execution" alias="task.repository.task_execution" public="true"/>
1919

tests/Functional/Command/RunCommandTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testExecute()
2727
{
2828
$singleTask = $this->createTask('Test workload 1');
2929
$laterTask = $this->createTask('Test workload 2');
30-
$intervalTask = $this->createTask('Test workload 3', CronExpression::factory('@daily'));
30+
$intervalTask = $this->createTask('Test workload 3', new CronExpression('@daily'));
3131

3232
/** @var TaskExecutionInterface[] $executions */
3333
$executions = [
@@ -70,7 +70,11 @@ public function testExecute()
7070
$this->assertEquals($intervalTask->getWorkload(), $task->getWorkload());
7171
$this->assertLessThanOrEqual($intervalTask->getFirstExecution(), $task->getFirstExecution());
7272
$this->assertLessThanOrEqual($intervalTask->getLastExecution(), $task->getLastExecution());
73-
$this->assertEquals($intervalTask->getInterval(), $task->getInterval());
73+
74+
$this->assertEquals($intervalTask->getInterval()->getExpression(), $task->getInterval()->getExpression());
75+
$this->assertEquals($intervalTask->getInterval()->getNextRunDate(), $task->getInterval()->getNextRunDate());
76+
$this->assertEquals($intervalTask->getInterval()->getParts(), $task->getInterval()->getParts());
77+
$this->assertEquals($intervalTask->getInterval()->getPreviousRunDate(), $task->getInterval()->getPreviousRunDate());
7478

7579
$this->assertEquals(TaskStatus::PLANNED, $result[0]->getStatus());
7680
$this->assertEquals(TestHandler::class, $result[0]->getHandlerClass());
@@ -81,7 +85,7 @@ public function testExecuteWithFail()
8185
{
8286
$singleTask = $this->createTask('Test workload 1', null, FailTestHandler::class);
8387
$laterTask = $this->createTask('Test workload 2', null, FailTestHandler::class);
84-
$intervalTask = $this->createTask('Test workload 3', CronExpression::factory('@daily'), FailTestHandler::class);
88+
$intervalTask = $this->createTask('Test workload 3', new CronExpression('@daily'), FailTestHandler::class);
8589

8690
/** @var TaskExecutionInterface[] $executions */
8791
$executions = [
@@ -124,7 +128,11 @@ public function testExecuteWithFail()
124128
$this->assertEquals($intervalTask->getWorkload(), $task->getWorkload());
125129
$this->assertLessThanOrEqual($intervalTask->getFirstExecution(), $task->getFirstExecution());
126130
$this->assertLessThanOrEqual($intervalTask->getLastExecution(), $task->getLastExecution());
127-
$this->assertEquals($intervalTask->getInterval(), $task->getInterval());
131+
132+
$this->assertEquals($intervalTask->getInterval()->getExpression(), $task->getInterval()->getExpression());
133+
$this->assertEquals($intervalTask->getInterval()->getNextRunDate(), $task->getInterval()->getNextRunDate());
134+
$this->assertEquals($intervalTask->getInterval()->getParts(), $task->getInterval()->getParts());
135+
$this->assertEquals($intervalTask->getInterval()->getPreviousRunDate(), $task->getInterval()->getPreviousRunDate());
128136

129137
$this->assertEquals(TaskStatus::PLANNED, $result[0]->getStatus());
130138
$this->assertEquals(FailTestHandler::class, $result[0]->getHandlerClass());

tests/Unit/Command/ScheduleSystemTasksCommandTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Cron\CronExpression;
66
use PHPUnit\Framework\TestCase;
77
use Prophecy\Argument;
8-
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\StringInput;
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use Task\Execution\TaskExecutionInterface;
1111
use Task\Scheduler\TaskSchedulerInterface;
@@ -85,7 +85,7 @@ public function testExecute()
8585
$taskBuilder->schedule()->shouldBeCalled();
8686

8787
$command->run(
88-
$this->prophesize(InputInterface::class)->reveal(),
88+
new StringInput(''),
8989
$this->prophesize(OutputInterface::class)->reveal()
9090
);
9191
}
@@ -135,7 +135,7 @@ public function testExecuteMultiple()
135135
$taskBuilder2->schedule()->shouldBeCalled();
136136

137137
$command->run(
138-
$this->prophesize(InputInterface::class)->reveal(),
138+
new StringInput(''),
139139
$this->prophesize(OutputInterface::class)->reveal()
140140
);
141141
}
@@ -178,7 +178,7 @@ function ($date) {
178178
$this->taskExecutionRepository->save($execution->reveal())->shouldBeCalled();
179179

180180
$command->run(
181-
$this->prophesize(InputInterface::class)->reveal(),
181+
new StringInput(''),
182182
$this->prophesize(OutputInterface::class)->reveal()
183183
);
184184
}
@@ -218,7 +218,7 @@ public function testExecuteUpdate()
218218
$this->scheduler->scheduleTasks()->shouldBeCalled();
219219

220220
$command->run(
221-
$this->prophesize(InputInterface::class)->reveal(),
221+
new StringInput(''),
222222
$this->prophesize(OutputInterface::class)->reveal()
223223
);
224224
}
@@ -253,7 +253,7 @@ public function testExecuteUpdateNotSupported()
253253
$this->scheduler->scheduleTasks()->shouldNotBeCalled();
254254

255255
$command->run(
256-
$this->prophesize(InputInterface::class)->reveal(),
256+
new StringInput(''),
257257
$this->prophesize(OutputInterface::class)->reveal()
258258
);
259259
}
@@ -287,7 +287,7 @@ function ($date) {
287287
$this->taskExecutionRepository->save($execution->reveal())->shouldBeCalled();
288288

289289
$command->run(
290-
$this->prophesize(InputInterface::class)->reveal(),
290+
new StringInput(''),
291291
$this->prophesize(OutputInterface::class)->reveal()
292292
);
293293
}

tests/Unit/DependencyInjection/HandlerCompilerPassTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ public function testProcess()
3636
$serviceDefinition = $this->prophesize(Definition::class);
3737
$container->findDefinition(HandlerCompilerPass::REGISTRY_ID)->willReturn($serviceDefinition);
3838

39-
$compilerPass = new HandlerCompilerPass();
40-
$compilerPass->process($container->reveal());
41-
4239
$serviceDefinition->replaceArgument(
4340
0,
4441
[\stdClass::class => new Reference('service1'), self::class => new Reference('service2')]
45-
)->shouldBeCalled();
42+
)->shouldBeCalled()
43+
->willReturn($serviceDefinition->reveal());
44+
45+
$compilerPass = new HandlerCompilerPass();
46+
$compilerPass->process($container->reveal());
4647
}
4748

4849
public function testProcessNoTaggedService()
@@ -55,9 +56,11 @@ public function testProcessNoTaggedService()
5556
$serviceDefinition = $this->prophesize(Definition::class);
5657
$container->findDefinition(HandlerCompilerPass::REGISTRY_ID)->willReturn($serviceDefinition);
5758

59+
$serviceDefinition->replaceArgument(0, [])
60+
->shouldBeCalled()
61+
->willReturn($serviceDefinition->reveal());
62+
5863
$compilerPass = new HandlerCompilerPass();
5964
$compilerPass->process($container->reveal());
60-
61-
$serviceDefinition->replaceArgument(0, [])->shouldBeCalled();
6265
}
6366
}

tests/app/TestKernel.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1414
use Symfony\Component\Config\FileLocator;
1515
use Symfony\Component\Config\Loader\LoaderInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1718
use Symfony\Component\HttpKernel\Kernel;
1819
use Task\TaskBundle\TaskBundle;
@@ -29,7 +30,7 @@ class TestKernel extends Kernel
2930
/**
3031
* {@inheritdoc}
3132
*/
32-
public function registerBundles()
33+
public function registerBundles(): array
3334
{
3435
return [
3536
new FrameworkBundle(),
@@ -41,7 +42,7 @@ public function registerBundles()
4142
/**
4243
* {@inheritdoc}
4344
*/
44-
public function registerContainerConfiguration(LoaderInterface $loader)
45+
public function registerContainerConfiguration(LoaderInterface $loader): void
4546
{
4647
$this->storage = getenv(self::STORAGE_VAR_NAME);
4748
if (false === $this->storage) {
@@ -55,7 +56,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
5556
/**
5657
* {@inheritdoc}
5758
*/
58-
protected function buildContainer()
59+
protected function buildContainer(): ContainerBuilder
5960
{
6061
$container = parent::buildContainer();
6162
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config'));
@@ -70,7 +71,7 @@ protected function buildContainer()
7071
/**
7172
* {@inheritdoc}
7273
*/
73-
protected function initializeContainer()
74+
protected function initializeContainer(): void
7475
{
7576
static $first = true;
7677

@@ -92,7 +93,7 @@ protected function initializeContainer()
9293

9394
try {
9495
parent::initializeContainer();
95-
} catch (\Exception $e) {
96+
} catch (Exception $e) {
9697
$this->debug = $debug;
9798

9899
throw $e;
@@ -101,7 +102,7 @@ protected function initializeContainer()
101102
$this->debug = $debug;
102103
}
103104

104-
protected function getKernelParameters()
105+
protected function getKernelParameters(): array
105106
{
106107
return array_merge(
107108
parent::getKernelParameters(),

tests/app/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?php
33
use Symfony\Bundle\FrameworkBundle\Console\Application;
44
use Symfony\Component\Console\Input\ArgvInput;
5-
use Symfony\Component\Debug\Debug;
5+
use Symfony\Component\ErrorHandler\Debug;
66

77
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
88
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information

0 commit comments

Comments
 (0)