From 5d854832a61cb0a1d2ca30ffc4d1e4f279a434af Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 11 Feb 2021 20:30:56 +0100 Subject: [PATCH 1/4] Add PHP 8 support --- .github/workflows/test-application.yaml | 102 ++++++++++++++++++++++++ .gitignore | 1 + .travis.yml | 88 -------------------- composer.json | 7 +- phpunit.xml.dist | 3 + tests/app/TestKernel.php | 10 +++ tests/app/config/config.doctrine.yml | 4 +- 7 files changed, 121 insertions(+), 94 deletions(-) create mode 100644 .github/workflows/test-application.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml new file mode 100644 index 0000000..53d97d1 --- /dev/null +++ b/.github/workflows/test-application.yaml @@ -0,0 +1,102 @@ +name: PHP Test + +on: + pull_request: + push: + branches: + - 'master' + - '[0-9]+.x' + - '[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.x' + +jobs: + test: + name: '${{ matrix.php-version }} ${{ matrix.dependencies }}, Storage ${{ matrix.storage }}, Coverage ${{ matrix.coverage }}' + runs-on: ubuntu-20.04 + env: + COVERAGE: ${{ matrix.coverage }} + STORAGE: ${{ matrix.storage }} + + strategy: + fail-fast: false + matrix: + include: + - php-version: '5.6' + dependencies: 'lowest' + storage: doctrine + - php-version: '5.6' + storage: doctrine + - php-version: '5.6' + storage: array + + - php-version: '7.0' + dependencies: 'lowest' + storage: doctrine + - php-version: '7.0' + storage: doctrine + - php-version: '7.0' + storage: array + + - php-version: '7.1' + dependencies: 'lowest' + storage: doctrine + - php-version: '7.1' + storage: doctrine + - php-version: '7.1' + storage: array + + - php-version: '7.2' + dependencies: 'lowest' + storage: doctrine + - php-version: '7.2' + storage: doctrine + - php-version: '7.2' + storage: array + + - php-version: '7.3' + storage: doctrine + - php-version: '7.3' + storage: array + + - php-version: '7.4' + storage: doctrine + - php-version: '7.4' + storage: array + + - php-version: '8.0' + storage: doctrine + - php-version: '8.0' + storage: array + + steps: + - name: Checkout project + uses: actions/checkout@v2 + + - name: Install and configure PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: "pdo, pdo_sqlite" + coverage: "pcov" + tools: 'composer:v2' + + - name: Install dependencies with Composer + uses: ramsey/composer-install@v1 + with: + dependency-versions: ${{ matrix.dependencies }} + composer-options: --prefer-dist --no-suggest + + - name: Doctrine + if: "${{ matrix.coverage }} == 'doctrine'" + run: | + tests/app/console doctrine:database:create + tests/app/console doctrine:schema:create + + - name: Execute test + run: vendor/bin/simple-phpunit -c phpunit.xml.dist --coverage-clover=coverage.clover + + - name: Coverage + if: ${{ matrix.coverage }} + run: | + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --access-token="230ec5e01daf5bb3e46ea304fb20348b52d80de73463ec08ee9c96fcd1349e35" --format=php-clover coverage.clover diff --git a/.gitignore b/.gitignore index 07fe36f..1dff214 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ composer.phar /tests/app/cache/ /tests/app/logs/ /tests/app/data/ +var/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 02d6c81..0000000 --- a/.travis.yml +++ /dev/null @@ -1,88 +0,0 @@ -language: php - -matrix: - fast_finish: true - include: - - php: 5.6 - env: - - STORAGE=doctrine - - COMPOSER_FLAGS="--prefer-lowest --prefer-dist --no-interaction" - - php: 5.6 - env: - - STORAGE=doctrine - - php: 5.6 - env: - - STORAGE=array - - php: 7.0 - env: - - STORAGE=doctrine - - COMPOSER_FLAGS="--prefer-lowest --prefer-dist --no-interaction" - - php: 7.0 - env: - - STORAGE=doctrine - - php: 7.0 - env: - - STORAGE=array - - php: 7.0 - env: - - STORAGE=doctrine - - COMPOSER_FLAGS="--prefer-lowest --prefer-dist --no-interaction" - - php: 7.0 - env: - - STORAGE=doctrine - - php: 7.1 - env: - - STORAGE=array - - php: 7.1 - env: - - STORAGE=doctrine - - COMPOSER_FLAGS="--prefer-lowest --prefer-dist --no-interaction" - - php: 7.1 - env: - - STORAGE=doctrine - - CODE_COVERAGE="--coverage-clover=coverage.clover" - - php: 7.2 - env: - - STORAGE=array - - php: 7.2 - env: - - STORAGE=doctrine - - COMPOSER_FLAGS="--prefer-lowest --prefer-dist --no-interaction" - - php: 7.2 - env: - - STORAGE=doctrine - - php: 7.3 - env: - - STORAGE=array - - php: 7.3 - env: - - STORAGE=doctrine - - php: 7.4 - env: - - STORAGE=array - - php: 7.4 - env: - - STORAGE=doctrine - -before_install: - - if [[ -z $CODE_COVERAGE ]]; then phpenv config-rm xdebug.ini ; fi - - phpenv config-add tests/travis.php.ini - -install: - - composer update $COMPOSER_FLAGS - - composer info - -before_script: - - if [[ $STORAGE == 'doctrine' ]]; then tests/app/console doctrine:database:create ; fi - - if [[ $STORAGE == 'doctrine' ]]; then tests/app/console doctrine:schema:create ; fi - -script: - - vendor/bin/phpunit -c phpunit.xml.dist $CODE_COVERAGE - -after_script: - - if [[ -n $CODE_COVERAGE ]]; then wget https://scrutinizer-ci.com/ocular.phar ; fi - - if [[ -n $CODE_COVERAGE ]]; then php ocular.phar code-coverage:upload --access-token="230ec5e01daf5bb3e46ea304fb20348b52d80de73463ec08ee9c96fcd1349e35" --format=php-clover coverage.clover ; fi - -cache: - directories: - - "$HOME/.composer/cache" diff --git a/composer.json b/composer.json index 09af429..a1ea5dc 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^5.6 || ^7.0", + "php": "^5.6 || ^7.0 || ^8.0", "php-task/php-task": "^1.4", "symfony/http-kernel": "^2.8 || ^3.4 || ^4.0 || ^5.0", "symfony/dependency-injection": "^2.8 || ^3.4 || ^4.0 || ^5.0", @@ -21,13 +21,12 @@ "doctrine/orm": "^2.5" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.0", - "sebastian/comparator": "^1.2.3", "symfony/debug": "^2.8 || ^3.4 || ^4.0 || ^5.0", "symfony/framework-bundle": "^2.8 || ^3.4 || ^4.0 || ^5.0", "symfony/finder": "^2.8 || ^3.4 || ^4.0 || ^5.0", "symfony/yaml": "^2.8 || ^3.4 || ^4.0 || ^5.0", - "doctrine/doctrine-bundle": "^1.5", + "symfony/phpunit-bridge": "^5.2.3", + "doctrine/doctrine-bundle": "^1.5 || ^2.0", "doctrine/data-fixtures": "^1.1" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index af67984..7d1a47d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,6 +9,9 @@ + + + diff --git a/tests/app/TestKernel.php b/tests/app/TestKernel.php index d82d553..cc7ad4e 100644 --- a/tests/app/TestKernel.php +++ b/tests/app/TestKernel.php @@ -100,4 +100,14 @@ protected function initializeContainer() $this->debug = $debug; } + + protected function getKernelParameters() + { + return array_merge( + parent::getKernelParameters(), + [ + 'kernel.test_root_dir' => __DIR__, + ] + ); + } } diff --git a/tests/app/config/config.doctrine.yml b/tests/app/config/config.doctrine.yml index f708253..6c79f2b 100644 --- a/tests/app/config/config.doctrine.yml +++ b/tests/app/config/config.doctrine.yml @@ -9,7 +9,7 @@ task: executor: type: separate separate: - console_path: '%kernel.root_dir%/console' + console_path: '%kernel.test_root_dir%/console' doctrine: orm: @@ -23,4 +23,4 @@ doctrine: user: root password: ~ charset: UTF8 - path: '%kernel.root_dir%/data/database.sqlite' + path: '%kernel.test_root_dir%/data/database.sqlite' From ec8d64a99e0c55ecd340e7e044370ef22b4cc3aa Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Fri, 12 Feb 2021 10:28:52 +0100 Subject: [PATCH 2/4] Upgrade phpunit tests --- tests/Unit/Builder/TaskBuilderFactoryTest.php | 3 ++- tests/Unit/Builder/TaskBuilderTest.php | 3 ++- tests/Unit/Command/ScheduleSystemTasksCommandTest.php | 3 ++- tests/Unit/DependencyInjection/HandlerCompilerPassTest.php | 3 ++- tests/Unit/EventListener/RunListenerTest.php | 3 ++- tests/Unit/EventListener/TaskExecutionListenerTest.php | 3 ++- tests/Unit/Executor/SeparateProcessExecutorTest.php | 3 ++- tests/Unit/Handler/TaskHandlerFactoryTest.php | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/Unit/Builder/TaskBuilderFactoryTest.php b/tests/Unit/Builder/TaskBuilderFactoryTest.php index edb6f9d..7e96346 100644 --- a/tests/Unit/Builder/TaskBuilderFactoryTest.php +++ b/tests/Unit/Builder/TaskBuilderFactoryTest.php @@ -2,12 +2,13 @@ namespace Unit\Builder; +use PHPUnit\Framework\TestCase; use Task\Scheduler\TaskSchedulerInterface; use Task\TaskBundle\Builder\TaskBuilder; use Task\TaskBundle\Builder\TaskBuilderFactory; use Task\TaskInterface; -class TaskBuilderFactoryTest extends \PHPUnit_Framework_TestCase +class TaskBuilderFactoryTest extends TestCase { public function testCreate() { diff --git a/tests/Unit/Builder/TaskBuilderTest.php b/tests/Unit/Builder/TaskBuilderTest.php index 24a7b23..95a3a5f 100644 --- a/tests/Unit/Builder/TaskBuilderTest.php +++ b/tests/Unit/Builder/TaskBuilderTest.php @@ -2,13 +2,14 @@ namespace Task\TaskBundle\Unit\Builder; +use PHPUnit\Framework\TestCase; use Task\Scheduler\TaskSchedulerInterface; use Task\TaskBundle\Builder\NotSupportedMethodException; use Task\TaskBundle\Builder\TaskBuilder; use Task\TaskBundle\Entity\Task; use Task\TaskInterface; -class TaskBuilderTest extends \PHPUnit_Framework_TestCase +class TaskBuilderTest extends TestCase { public function testSetSystemKey() { diff --git a/tests/Unit/Command/ScheduleSystemTasksCommandTest.php b/tests/Unit/Command/ScheduleSystemTasksCommandTest.php index 23e2e93..e5d78f3 100644 --- a/tests/Unit/Command/ScheduleSystemTasksCommandTest.php +++ b/tests/Unit/Command/ScheduleSystemTasksCommandTest.php @@ -3,6 +3,7 @@ namespace Task\TaskBundle\Unit\Command; use Cron\CronExpression; +use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -16,7 +17,7 @@ use Task\TaskBundle\Tests\Functional\TestHandler; use Task\TaskStatus; -class ScheduleSystemTasksCommandTest extends \PHPUnit_Framework_TestCase +class ScheduleSystemTasksCommandTest extends TestCase { /** * @var TaskSchedulerInterface diff --git a/tests/Unit/DependencyInjection/HandlerCompilerPassTest.php b/tests/Unit/DependencyInjection/HandlerCompilerPassTest.php index 62bac6b..a4c9aaa 100644 --- a/tests/Unit/DependencyInjection/HandlerCompilerPassTest.php +++ b/tests/Unit/DependencyInjection/HandlerCompilerPassTest.php @@ -11,6 +11,7 @@ namespace Task\TaskBundle\Unit\DependencyInjection; +use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -19,7 +20,7 @@ /** * Tests for class HandlerCompilerPass. */ -class HandlerCompilerPassTest extends \PHPUnit_Framework_TestCase +class HandlerCompilerPassTest extends TestCase { public function testProcess() { diff --git a/tests/Unit/EventListener/RunListenerTest.php b/tests/Unit/EventListener/RunListenerTest.php index 656e95f..a23302a 100644 --- a/tests/Unit/EventListener/RunListenerTest.php +++ b/tests/Unit/EventListener/RunListenerTest.php @@ -11,6 +11,7 @@ namespace Task\TaskBundle\Tests\Unit\EventListener; +use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\Event; use Task\Runner\TaskRunnerInterface; use Task\TaskBundle\EventListener\RunListener; @@ -18,7 +19,7 @@ /** * Tests for class RunListener. */ -class RunListenerTest extends \PHPUnit_Framework_TestCase +class RunListenerTest extends TestCase { public function testRun() { diff --git a/tests/Unit/EventListener/TaskExecutionListenerTest.php b/tests/Unit/EventListener/TaskExecutionListenerTest.php index 7cbf1e4..3f371e8 100644 --- a/tests/Unit/EventListener/TaskExecutionListenerTest.php +++ b/tests/Unit/EventListener/TaskExecutionListenerTest.php @@ -12,13 +12,14 @@ namespace Task\TaskBundle\Tests\Unit\EventListener; use Doctrine\ORM\EntityManagerInterface; +use PHPUnit\Framework\TestCase; use Task\Event\TaskExecutionEvent; use Task\TaskBundle\EventListener\DoctrineTaskExecutionListener; /** * Tests for class TaskExecutionListener. */ -class TaskExecutionListenerTest extends \PHPUnit_Framework_TestCase +class TaskExecutionListenerTest extends TestCase { public function testClearEntityManagerAfterTask() { diff --git a/tests/Unit/Executor/SeparateProcessExecutorTest.php b/tests/Unit/Executor/SeparateProcessExecutorTest.php index e7311c2..ec9b0a0 100644 --- a/tests/Unit/Executor/SeparateProcessExecutorTest.php +++ b/tests/Unit/Executor/SeparateProcessExecutorTest.php @@ -11,6 +11,7 @@ namespace Task\TaskBundle\Tests\Unit\Executor; +use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; use Task\Execution\TaskExecutionInterface; use Task\Executor\FailedException; @@ -22,7 +23,7 @@ use Task\TaskBundle\Executor\SeparateProcessException; use Task\TaskBundle\Executor\SeparateProcessExecutor; -class SeparateProcessExecutorTest extends \PHPUnit_Framework_TestCase +class SeparateProcessExecutorTest extends TestCase { /** * @var TaskHandlerFactoryInterface diff --git a/tests/Unit/Handler/TaskHandlerFactoryTest.php b/tests/Unit/Handler/TaskHandlerFactoryTest.php index c6b2089..67449e9 100644 --- a/tests/Unit/Handler/TaskHandlerFactoryTest.php +++ b/tests/Unit/Handler/TaskHandlerFactoryTest.php @@ -11,6 +11,7 @@ namespace Task\TaskBundle\Tests\Unit\Handler; +use PHPUnit\Framework\TestCase; use Task\Handler\TaskHandlerNotExistsException; use Task\TaskBundle\Handler\TaskHandlerFactory; use Task\TaskBundle\Tests\Functional\TestHandler; @@ -18,7 +19,7 @@ /** * Tests for class TaskHandlerFactory. */ -class TaskHandlerFactoryTest extends \PHPUnit_Framework_TestCase +class TaskHandlerFactoryTest extends TestCase { public function testCreate() { From 8db574197472f79d415aef5d484c0469e2a81e3a Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Fri, 12 Feb 2021 10:44:27 +0100 Subject: [PATCH 3/4] Fix PHP 8 compatibility --- src/Command/RunHandlerCommand.php | 2 ++ src/EventListener/RunListener.php | 7 +++-- .../Command/DebugTasksCommandTest.php | 28 +++++++++---------- tests/Functional/Command/RunCommandTest.php | 2 +- .../Command/RunHandlerCommandTest.php | 4 +-- .../ScheduleSystemTasksCommandTest.php | 2 +- .../Command/ScheduleTaskCommandTest.php | 2 +- .../Handler/TaskHandlerFactoryTest.php | 6 ++-- tests/Unit/Builder/TaskBuilderTest.php | 2 +- tests/Unit/EventListener/RunListenerTest.php | 10 +++++-- tests/Unit/Handler/TaskHandlerFactoryTest.php | 4 +-- 11 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/Command/RunHandlerCommand.php b/src/Command/RunHandlerCommand.php index e851027..b9a36ab 100644 --- a/src/Command/RunHandlerCommand.php +++ b/src/Command/RunHandlerCommand.php @@ -72,5 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln(sprintf('Result: %s', json_encode($result))); } + + return 0; } } diff --git a/src/EventListener/RunListener.php b/src/EventListener/RunListener.php index cc0e2cb..826c939 100644 --- a/src/EventListener/RunListener.php +++ b/src/EventListener/RunListener.php @@ -11,7 +11,8 @@ namespace Task\TaskBundle\EventListener; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\EventDispatcher\Event as LegacyEvent; +use Symfony\Contracts\EventDispatcher\Event; use Task\Runner\TaskRunnerInterface; /** @@ -35,9 +36,9 @@ public function __construct(TaskRunnerInterface $taskRunner) /** * Run scheduled tasks. * - * @param Event $event + * @param Event|LegacyEvent $event */ - public function run(Event $event) + public function run($event) { $this->taskRunner->runTasks(); } diff --git a/tests/Functional/Command/DebugTasksCommandTest.php b/tests/Functional/Command/DebugTasksCommandTest.php index 6d1f188..cd87182 100644 --- a/tests/Functional/Command/DebugTasksCommandTest.php +++ b/tests/Functional/Command/DebugTasksCommandTest.php @@ -46,11 +46,11 @@ public function testExecute() ); $output = $this->commandTester->getDisplay(); - $this->assertContains($executions[0]->getUuid(), $output); - $this->assertContains($executions[1]->getUuid(), $output); - $this->assertContains('100000ms', $output); - $this->assertContains('100ms', $output); - $this->assertContains('completed', $output); + $this->assertStringContainsString($executions[0]->getUuid(), $output); + $this->assertStringContainsString($executions[1]->getUuid(), $output); + $this->assertStringContainsString('100000ms', $output); + $this->assertStringContainsString('100ms', $output); + $this->assertStringContainsString('completed', $output); } public function testExecutePaginated() @@ -76,9 +76,9 @@ public function testExecutePaginated() ); $output = $this->commandTester->getDisplay(); - $this->assertContains($executions[0]->getUuid(), $output); - $this->assertContains($executions[1]->getUuid(), $output); - $this->assertNotContains($executions[2]->getUuid(), $output); + $this->assertStringContainsString($executions[0]->getUuid(), $output); + $this->assertStringContainsString($executions[1]->getUuid(), $output); + $this->assertStringNotContainsString($executions[2]->getUuid(), $output); $this->commandTester->execute( [ @@ -89,9 +89,9 @@ public function testExecutePaginated() ); $output = $this->commandTester->getDisplay(); - $this->assertNotContains($executions[0]->getUuid(), $output); - $this->assertNotContains($executions[1]->getUuid(), $output); - $this->assertContains($executions[2]->getUuid(), $output); + $this->assertStringNotContainsString($executions[0]->getUuid(), $output); + $this->assertStringNotContainsString($executions[1]->getUuid(), $output); + $this->assertStringContainsString($executions[2]->getUuid(), $output); $this->commandTester->execute( [ @@ -102,9 +102,9 @@ public function testExecutePaginated() ); $output = $this->commandTester->getDisplay(); - $this->assertNotContains($executions[0]->getUuid(), $output); - $this->assertNotContains($executions[1]->getUuid(), $output); - $this->assertNotContains($executions[2]->getUuid(), $output); + $this->assertStringNotContainsString($executions[0]->getUuid(), $output); + $this->assertStringNotContainsString($executions[1]->getUuid(), $output); + $this->assertStringNotContainsString($executions[2]->getUuid(), $output); } /** diff --git a/tests/Functional/Command/RunCommandTest.php b/tests/Functional/Command/RunCommandTest.php index 97be75c..1a3d48c 100644 --- a/tests/Functional/Command/RunCommandTest.php +++ b/tests/Functional/Command/RunCommandTest.php @@ -43,7 +43,7 @@ public function testExecute() ); $execution = $this->taskExecutionRepository->findByUuid($executions[0]->getUuid()); - $this->assertEquals(TaskStatus::COMPLETED, $execution->getStatus(), $execution->getException()); + $this->assertEquals(TaskStatus::COMPLETED, $execution->getStatus(), $execution->getException() ?: ''); $this->assertEquals(strrev('Test workload 1'), $execution->getResult()); $this->assertGreaterThan(0, $execution->getDuration()); $this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime()); diff --git a/tests/Functional/Command/RunHandlerCommandTest.php b/tests/Functional/Command/RunHandlerCommandTest.php index d3a5dee..700754d 100644 --- a/tests/Functional/Command/RunHandlerCommandTest.php +++ b/tests/Functional/Command/RunHandlerCommandTest.php @@ -33,7 +33,7 @@ public function testExecute() ); $output = $this->commandTester->getDisplay(); - $this->assertContains('No workload.', $output); + $this->assertStringContainsString('No workload.', $output); } public function testExecuteWithWorkload() @@ -50,7 +50,7 @@ public function testExecuteWithWorkload() ); $output = $this->commandTester->getDisplay(); - $this->assertContains(strrev('Test workload 1'), $output); + $this->assertStringContainsString(strrev('Test workload 1'), $output); } public function testExecuteWithWorkloadNoVerbosity() diff --git a/tests/Functional/Command/ScheduleSystemTasksCommandTest.php b/tests/Functional/Command/ScheduleSystemTasksCommandTest.php index 2ff7fff..ff80556 100644 --- a/tests/Functional/Command/ScheduleSystemTasksCommandTest.php +++ b/tests/Functional/Command/ScheduleSystemTasksCommandTest.php @@ -26,7 +26,7 @@ public function testExecute() ); $output = $this->commandTester->getDisplay(); - $this->assertContains('System-tasks successfully scheduled', $output); + $this->assertStringContainsString('System-tasks successfully scheduled', $output); $taskRepository = self::$kernel->getContainer()->get('task.repository.task'); $this->assertNotNull($taskRepository->findBySystemKey('testing')); diff --git a/tests/Functional/Command/ScheduleTaskCommandTest.php b/tests/Functional/Command/ScheduleTaskCommandTest.php index 3ec448e..2dd3360 100644 --- a/tests/Functional/Command/ScheduleTaskCommandTest.php +++ b/tests/Functional/Command/ScheduleTaskCommandTest.php @@ -94,7 +94,7 @@ public function testExecuteWithWorkloadAndIntervalAndEndDate() $this->assertEquals(TestHandler::class, $tasks[0]->getHandlerClass()); $this->assertEquals('Test workload 1', $tasks[0]->getWorkload()); $this->assertEquals('0 * * * *', $tasks[0]->getInterval()); - $this->assertEquals($date, $tasks[0]->getLastExecution(), '', 2); + $this->assertEquals($date->format('Y-m-d H:i:s'), $tasks[0]->getLastExecution()->format('Y-m-d H:i:s')); } public function testExecuteWithExecutionDate() diff --git a/tests/Functional/Handler/TaskHandlerFactoryTest.php b/tests/Functional/Handler/TaskHandlerFactoryTest.php index df20342..22a6e96 100644 --- a/tests/Functional/Handler/TaskHandlerFactoryTest.php +++ b/tests/Functional/Handler/TaskHandlerFactoryTest.php @@ -12,6 +12,7 @@ namespace Task\TaskBundle\Tests\Functional\Handler; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Task\Handler\TaskHandlerNotExistsException; use Task\TaskBundle\Handler\TaskHandlerFactory; use Task\TaskBundle\Tests\Functional\TestHandler; @@ -38,11 +39,10 @@ public function testCreate() $this->assertInstanceOf(TestHandler::class, $this->taskHandlerFactory->create(TestHandler::class)); } - /** - * @expectedException \Task\Handler\TaskHandlerNotExistsException - */ public function testCreateNotExists() { + $this->expectException(TaskHandlerNotExistsException::class); + $this->taskHandlerFactory->create(\stdClass::class); } } diff --git a/tests/Unit/Builder/TaskBuilderTest.php b/tests/Unit/Builder/TaskBuilderTest.php index 95a3a5f..64e421b 100644 --- a/tests/Unit/Builder/TaskBuilderTest.php +++ b/tests/Unit/Builder/TaskBuilderTest.php @@ -24,7 +24,7 @@ public function testSetSystemKey() public function testSetSystemKeyNotSupported() { - $this->setExpectedException(NotSupportedMethodException::class); + $this->expectException(NotSupportedMethodException::class); $task = $this->prophesize(TaskInterface::class); $scheduler = $this->prophesize(TaskSchedulerInterface::class); diff --git a/tests/Unit/EventListener/RunListenerTest.php b/tests/Unit/EventListener/RunListenerTest.php index a23302a..68b23d1 100644 --- a/tests/Unit/EventListener/RunListenerTest.php +++ b/tests/Unit/EventListener/RunListenerTest.php @@ -12,7 +12,8 @@ namespace Task\TaskBundle\Tests\Unit\EventListener; use PHPUnit\Framework\TestCase; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\EventDispatcher\Event as LegacyEvent; +use Symfony\Contracts\EventDispatcher\Event; use Task\Runner\TaskRunnerInterface; use Task\TaskBundle\EventListener\RunListener; @@ -23,7 +24,12 @@ class RunListenerTest extends TestCase { public function testRun() { - $event = $this->prophesize(Event::class); + if (\class_exists(LegacyEvent::class)) { + $event = $this->prophesize(LegacyEvent::class); + } else { + $event = $this->prophesize(Event::class); + } + $taskRunner = $this->prophesize(TaskRunnerInterface::class); $listener = new RunListener($taskRunner->reveal()); diff --git a/tests/Unit/Handler/TaskHandlerFactoryTest.php b/tests/Unit/Handler/TaskHandlerFactoryTest.php index 67449e9..4b44d2a 100644 --- a/tests/Unit/Handler/TaskHandlerFactoryTest.php +++ b/tests/Unit/Handler/TaskHandlerFactoryTest.php @@ -31,7 +31,7 @@ public function testCreate() public function testCreateNotExists() { - $this->setExpectedException(TaskHandlerNotExistsException::class); + $this->expectException(TaskHandlerNotExistsException::class); $taskHandlerFactory = new TaskHandlerFactory([TestHandler::class => new TestHandler()]); @@ -40,7 +40,7 @@ public function testCreateNotExists() public function testCreateNoHandler() { - $this->setExpectedException(TaskHandlerNotExistsException::class); + $this->expectException(TaskHandlerNotExistsException::class); $taskHandlerFactory = new TaskHandlerFactory([]); From e43c6165361be7694801ea0ccaaf49e8fe61be18 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Fri, 12 Feb 2021 11:05:44 +0100 Subject: [PATCH 4/4] Remove minimum stability for test lowest dependencies --- .github/workflows/test-application.yaml | 7 ++++--- composer.json | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 53d97d1..7fd7613 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -59,6 +59,7 @@ jobs: storage: array - php-version: '7.4' + coverage: '--coverage-clover=coverage.clover' storage: doctrine - php-version: '7.4' storage: array @@ -87,16 +88,16 @@ jobs: composer-options: --prefer-dist --no-suggest - name: Doctrine - if: "${{ matrix.coverage }} == 'doctrine'" + if: matrix.storage == 'doctrine' run: | tests/app/console doctrine:database:create tests/app/console doctrine:schema:create - name: Execute test - run: vendor/bin/simple-phpunit -c phpunit.xml.dist --coverage-clover=coverage.clover + run: vendor/bin/simple-phpunit -c phpunit.xml.dist ${{ matrix.matrix.coverage }} - name: Coverage - if: ${{ matrix.coverage }} + if: matrix.coverage run: | wget https://scrutinizer-ci.com/ocular.phar php ocular.phar code-coverage:upload --access-token="230ec5e01daf5bb3e46ea304fb20348b52d80de73463ec08ee9c96fcd1349e35" --format=php-clover coverage.clover diff --git a/composer.json b/composer.json index a1ea5dc..ddcb322 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "require-dev": { "symfony/debug": "^2.8 || ^3.4 || ^4.0 || ^5.0", - "symfony/framework-bundle": "^2.8 || ^3.4 || ^4.0 || ^5.0", + "symfony/framework-bundle": "^2.8.18 || ^3.4 || ^4.0 || ^5.0", "symfony/finder": "^2.8 || ^3.4 || ^4.0 || ^5.0", "symfony/yaml": "^2.8 || ^3.4 || ^4.0 || ^5.0", "symfony/phpunit-bridge": "^5.2.3", @@ -39,7 +39,6 @@ "Task\\TaskBundle\\Tests\\": "tests" } }, - "minimum-stability": "dev", "extra": { "branch-alias": { "dev-master": "2.x-dev"