Skip to content

Commit dec507f

Browse files
Add PHP 8 support (#52)
* Add PHP 8 support * Upgrade phpunit tests * Fix PHP 8 compatibility * Remove minimum stability for test lowest dependencies
1 parent d6bde41 commit dec507f

23 files changed

+178
-134
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: PHP Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- 'master'
8+
- '[0-9]+.x'
9+
- '[0-9]+.[0-9]+'
10+
- '[0-9]+.[0-9]+.x'
11+
12+
jobs:
13+
test:
14+
name: '${{ matrix.php-version }} ${{ matrix.dependencies }}, Storage ${{ matrix.storage }}, Coverage ${{ matrix.coverage }}'
15+
runs-on: ubuntu-20.04
16+
env:
17+
COVERAGE: ${{ matrix.coverage }}
18+
STORAGE: ${{ matrix.storage }}
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
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'
62+
coverage: '--coverage-clover=coverage.clover'
63+
storage: doctrine
64+
- php-version: '7.4'
65+
storage: array
66+
67+
- php-version: '8.0'
68+
storage: doctrine
69+
- php-version: '8.0'
70+
storage: array
71+
72+
steps:
73+
- name: Checkout project
74+
uses: actions/checkout@v2
75+
76+
- name: Install and configure PHP
77+
uses: shivammathur/setup-php@v2
78+
with:
79+
php-version: ${{ matrix.php-version }}
80+
extensions: "pdo, pdo_sqlite"
81+
coverage: "pcov"
82+
tools: 'composer:v2'
83+
84+
- name: Install dependencies with Composer
85+
uses: ramsey/composer-install@v1
86+
with:
87+
dependency-versions: ${{ matrix.dependencies }}
88+
composer-options: --prefer-dist --no-suggest
89+
90+
- name: Doctrine
91+
if: matrix.storage == 'doctrine'
92+
run: |
93+
tests/app/console doctrine:database:create
94+
tests/app/console doctrine:schema:create
95+
96+
- name: Execute test
97+
run: vendor/bin/simple-phpunit -c phpunit.xml.dist ${{ matrix.matrix.coverage }}
98+
99+
- name: Coverage
100+
if: matrix.coverage
101+
run: |
102+
wget https://scrutinizer-ci.com/ocular.phar
103+
php ocular.phar code-coverage:upload --access-token="230ec5e01daf5bb3e46ea304fb20348b52d80de73463ec08ee9c96fcd1349e35" --format=php-clover coverage.clover

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ composer.phar
88
/tests/app/cache/
99
/tests/app/logs/
1010
/tests/app/data/
11+
var/

.travis.yml

Lines changed: 0 additions & 88 deletions
This file was deleted.

composer.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^5.6 || ^7.0",
13+
"php": "^5.6 || ^7.0 || ^8.0",
1414
"php-task/php-task": "^1.4",
1515
"symfony/http-kernel": "^2.8 || ^3.4 || ^4.0 || ^5.0",
1616
"symfony/dependency-injection": "^2.8 || ^3.4 || ^4.0 || ^5.0",
@@ -21,13 +21,12 @@
2121
"doctrine/orm": "^2.5"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^4.8 || ^5.0",
25-
"sebastian/comparator": "^1.2.3",
2624
"symfony/debug": "^2.8 || ^3.4 || ^4.0 || ^5.0",
27-
"symfony/framework-bundle": "^2.8 || ^3.4 || ^4.0 || ^5.0",
25+
"symfony/framework-bundle": "^2.8.18 || ^3.4 || ^4.0 || ^5.0",
2826
"symfony/finder": "^2.8 || ^3.4 || ^4.0 || ^5.0",
2927
"symfony/yaml": "^2.8 || ^3.4 || ^4.0 || ^5.0",
30-
"doctrine/doctrine-bundle": "^1.5",
28+
"symfony/phpunit-bridge": "^5.2.3",
29+
"doctrine/doctrine-bundle": "^1.5 || ^2.0",
3130
"doctrine/data-fixtures": "^1.1"
3231
},
3332
"autoload": {
@@ -40,7 +39,6 @@
4039
"Task\\TaskBundle\\Tests\\": "tests"
4140
}
4241
},
43-
"minimum-stability": "dev",
4442
"extra": {
4543
"branch-alias": {
4644
"dev-master": "2.x-dev"

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<ini name="error_reporting" value="-1" />
1010
<server name="KERNEL_DIR" value="tests/app" />
1111
<server name="KERNEL_CLASS" value="TestKernel" />
12+
<env name="SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT" value="1"/>
13+
<env name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml"/>
14+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
1215
</php>
1316

1417
<testsuites>

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
}

0 commit comments

Comments
 (0)