From 2ec0fc13ee8f1cdb0c29bc84ecaa8e654dd234c9 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 24 Jul 2024 15:51:54 +0200 Subject: [PATCH 1/3] Upgrade CI for PHP 8.4 testing --- .github/workflows/test-application.yaml | 28 +++++++++++++++---------- composer.json | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 48bf334..cf433db 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -57,6 +57,14 @@ jobs: env: SYMFONY_DEPRECATIONS_HELPER: weak + - php-version: '8.4' + dependency-versions: 'highest' + php-extensions: 'mysql, imagick' + tools: 'composer:v2' + composer-options: '--ignore-platform-reqs' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + services: mysql: image: 'mysql:5.7' @@ -69,7 +77,7 @@ jobs: --health-timeout=5s --health-retries=5 steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -79,23 +87,21 @@ jobs: tools: '${{ matrix.tools }}' coverage: none - - name: Remove not required tooling for tests - run: composer remove php-cs-fixer/shim "*phpstan*" --dev + - name: Remove Lint Tools + # These tools are not required to run tests, so we are removing them to improve dependency resolving and + # testing lowest versions. + run: composer remove "*php-cs-fixer*" "*phpstan*" "*rector*" --dev --no-update - name: Install composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: ${{matrix.dependency-versions}} + composer-options: ${{matrix.composer-options}} - name: Bootstrap test environment run: composer bootstrap-test-environment env: '${{ matrix.env }}' - - name: Lint code - if: '${{ matrix.lint }}' - run: composer lint - env: '${{ matrix.env }}' - - name: Execute test cases run: time composer test env: '${{ matrix.env }}' @@ -108,7 +114,7 @@ jobs: steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -119,7 +125,7 @@ jobs: coverage: none - name: Install composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: highest diff --git a/composer.json b/composer.json index 863c95b..fa57062 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.0", "php-cs-fixer/shim": "^3.0", "symfony/browser-kit": "^4.3 || ^5.0 || ^6.0 || ^7.0", "symfony/dotenv": "^4.3 || ^5.0 || ^6.0 || ^7.0", From 0058ea22dba90f77766cf0e854592434cfb594c0 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 24 Jul 2024 15:58:10 +0200 Subject: [PATCH 2/3] Update use ProphecyTrait usage --- .../Controller/RedirectControllerTest.php | 3 ++ .../RedirectRouteImportControllerTest.php | 35 ++++++++----------- .../GoneDocumentSubscriberTest.php | 3 ++ .../GoneEntitySubscriberTest.php | 3 ++ .../Import/Converter/ConverterFacadeTest.php | 3 ++ Tests/Unit/Import/Converter/ConverterTest.php | 3 ++ Tests/Unit/Import/FileImportTest.php | 3 ++ Tests/Unit/Import/Reader/ReaderFacadeTest.php | 3 ++ Tests/Unit/Import/Writer/WriterTest.php | 3 ++ .../Unit/Manager/RedirectRouteManagerTest.php | 3 ++ .../Routing/RedirectRouteProviderTest.php | 3 ++ Tests/prophecy-trailt-bc-layer.php | 19 ++++++++++ Tests/test-bootstrap.php | 4 +++ composer.json | 3 +- 14 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 Tests/prophecy-trailt-bc-layer.php diff --git a/Tests/Unit/Controller/RedirectControllerTest.php b/Tests/Unit/Controller/RedirectControllerTest.php index 31f4302..6dbafc9 100644 --- a/Tests/Unit/Controller/RedirectControllerTest.php +++ b/Tests/Unit/Controller/RedirectControllerTest.php @@ -12,6 +12,7 @@ namespace Sulu\Bundle\RedirectBundle\Tests\Unit\Controller; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\RedirectBundle\Controller\WebsiteRedirectController; use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -19,6 +20,8 @@ class RedirectControllerTest extends TestCase { + use ProphecyTrait; + /** * @var WebsiteRedirectController */ diff --git a/Tests/Unit/Controller/RedirectRouteImportControllerTest.php b/Tests/Unit/Controller/RedirectRouteImportControllerTest.php index ea32b18..f29438c 100644 --- a/Tests/Unit/Controller/RedirectRouteImportControllerTest.php +++ b/Tests/Unit/Controller/RedirectRouteImportControllerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\RedirectBundle\Controller\RedirectRouteImportController; use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterNotFoundException; use Sulu\Bundle\RedirectBundle\Import\FileImportInterface; @@ -27,6 +28,8 @@ class RedirectRouteImportControllerTest extends TestCase { + use ProphecyTrait; + /** * @var string */ @@ -39,15 +42,12 @@ class RedirectRouteImportControllerTest extends TestCase public function testImportAction() { - $request = $this->prophesize(Request::class); - - $fileBag = $this->prophesize(FileBag::class); - $request->reveal()->files = $fileBag->reveal(); + $request = Request::create('/'); $uploadedFile = $this->createUploadedFile(__DIR__ . '/import.csv'); - - $fileBag->has('redirectRoutes')->willReturn(true); - $fileBag->get('redirectRoutes')->willReturn($uploadedFile); + $request->files->add([ + 'redirectRoutes' => $uploadedFile, + ]); $items = [ new Item(1, '', $this->prophesize(RedirectRouteInterface::class)->reveal()), @@ -59,7 +59,7 @@ public function testImportAction() $import->import(Argument::any())->willReturn($items); $controller = new RedirectRouteImportController($import->reveal(), $this->importPath); - $response = $controller->postAction($request->reveal()); + $response = $controller->postAction($request); $this->assertInstanceOf(JsonResponse::class, $response); $this->assertEquals(200, $response->getStatusCode()); @@ -96,15 +96,12 @@ public function testImportActionReaderNotFound() public function testImportActionConverterNotFound() { - $request = $this->prophesize(Request::class); - - $fileBag = $this->prophesize(FileBag::class); - $request->reveal()->files = $fileBag->reveal(); + $request = Request::create('/'); $uploadedFile = $this->createUploadedFile(__DIR__ . '/import.csv'); - - $fileBag->has('redirectRoutes')->willReturn(true); - $fileBag->get('redirectRoutes')->willReturn($uploadedFile); + $request->files->add([ + 'redirectRoutes' => $uploadedFile, + ]); $import = $this->prophesize(FileImportInterface::class); $import->import(Argument::any())->willThrow(ConverterNotFoundException::class); @@ -118,12 +115,8 @@ public function testImportActionConverterNotFound() public function testImportActionNoFile() { - $request = $this->prophesize(Request::class); - - $fileBag = $this->prophesize(FileBag::class); - $request->reveal()->files = $fileBag->reveal(); - - $fileBag->has('redirectRoutes')->willReturn(false); + $request = Request::create('/'); + $request->files->add([]); $import = $this->prophesize(FileImportInterface::class); $import->import(Argument::any())->shouldNotBeCalled(); diff --git a/Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php b/Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php index d6f8f32..8daf03b 100644 --- a/Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php +++ b/Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php @@ -14,6 +14,7 @@ use Doctrine\ORM\EntityManager; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector; use Sulu\Bundle\PageBundle\Document\BasePageDocument; @@ -30,6 +31,8 @@ class GoneDocumentSubscriberTest extends TestCase { + use ProphecyTrait; + /** * @var GoneDocumentSubscriber */ diff --git a/Tests/Unit/GoneSubscriber/GoneEntitySubscriberTest.php b/Tests/Unit/GoneSubscriber/GoneEntitySubscriberTest.php index 1d8a767..e950d06 100644 --- a/Tests/Unit/GoneSubscriber/GoneEntitySubscriberTest.php +++ b/Tests/Unit/GoneSubscriber/GoneEntitySubscriberTest.php @@ -14,6 +14,7 @@ use Doctrine\ORM\Event\LifecycleEventArgs; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\RedirectBundle\Entity\RedirectRoute; use Sulu\Bundle\RedirectBundle\GoneSubscriber\GoneEntitySubscriber; @@ -22,6 +23,8 @@ class GoneEntitySubscriberTest extends TestCase { + use ProphecyTrait; + /** * @var GoneEntitySubscriber */ diff --git a/Tests/Unit/Import/Converter/ConverterFacadeTest.php b/Tests/Unit/Import/Converter/ConverterFacadeTest.php index a1e4acd..030d6cd 100644 --- a/Tests/Unit/Import/Converter/ConverterFacadeTest.php +++ b/Tests/Unit/Import/Converter/ConverterFacadeTest.php @@ -12,6 +12,7 @@ namespace Sulu\Bundle\RedirectBundle\Tests\Unit\Import\Converter; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterFacade; use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterInterface; @@ -19,6 +20,8 @@ class ConverterFacadeTest extends TestCase { + use ProphecyTrait; + public function testSupports() { $data = ['title' => 'Test-Title']; diff --git a/Tests/Unit/Import/Converter/ConverterTest.php b/Tests/Unit/Import/Converter/ConverterTest.php index 99a6fb8..5068e78 100644 --- a/Tests/Unit/Import/Converter/ConverterTest.php +++ b/Tests/Unit/Import/Converter/ConverterTest.php @@ -13,12 +13,15 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\RedirectBundle\Import\Converter\Converter; use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface; use Sulu\Bundle\RedirectBundle\Model\RedirectRouteRepositoryInterface; class ConverterTest extends TestCase { + use ProphecyTrait; + public function testSupports() { $repository = $this->prophesize(RedirectRouteRepositoryInterface::class); diff --git a/Tests/Unit/Import/FileImportTest.php b/Tests/Unit/Import/FileImportTest.php index 00c16b5..a4ebd33 100644 --- a/Tests/Unit/Import/FileImportTest.php +++ b/Tests/Unit/Import/FileImportTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\RedirectBundle\Import\Converter\Converter; use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterInterface; @@ -28,6 +29,8 @@ class FileImportTest extends TestCase { + use ProphecyTrait; + /** * @var ObjectProphecy */ diff --git a/Tests/Unit/Import/Reader/ReaderFacadeTest.php b/Tests/Unit/Import/Reader/ReaderFacadeTest.php index 4119848..d2a286b 100644 --- a/Tests/Unit/Import/Reader/ReaderFacadeTest.php +++ b/Tests/Unit/Import/Reader/ReaderFacadeTest.php @@ -12,6 +12,7 @@ namespace Sulu\Bundle\RedirectBundle\Tests\Unit\Import\Reader; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\RedirectBundle\Import\Converter\Converter; use Sulu\Bundle\RedirectBundle\Import\Reader\ReaderFacade; @@ -19,6 +20,8 @@ class ReaderFacadeTest extends TestCase { + use ProphecyTrait; + /** * @var string */ diff --git a/Tests/Unit/Import/Writer/WriterTest.php b/Tests/Unit/Import/Writer/WriterTest.php index a96bdef..acd9b31 100644 --- a/Tests/Unit/Import/Writer/WriterTest.php +++ b/Tests/Unit/Import/Writer/WriterTest.php @@ -13,6 +13,7 @@ use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\RedirectBundle\Exception\RedirectRouteNotUniqueException; use Sulu\Bundle\RedirectBundle\Import\Writer\DuplicatedSourceException; @@ -24,6 +25,8 @@ class WriterTest extends TestCase { + use ProphecyTrait; + /** * @var ObjectProphecy */ diff --git a/Tests/Unit/Manager/RedirectRouteManagerTest.php b/Tests/Unit/Manager/RedirectRouteManagerTest.php index a16ed17..4b6106c 100644 --- a/Tests/Unit/Manager/RedirectRouteManagerTest.php +++ b/Tests/Unit/Manager/RedirectRouteManagerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\RedirectBundle\Exception\RedirectRouteNotUniqueException; use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManager; @@ -22,6 +23,8 @@ class RedirectRouteManagerTest extends TestCase { + use ProphecyTrait; + /** * @var ObjectProphecy */ diff --git a/Tests/Unit/Routing/RedirectRouteProviderTest.php b/Tests/Unit/Routing/RedirectRouteProviderTest.php index d686b3a..76e031d 100644 --- a/Tests/Unit/Routing/RedirectRouteProviderTest.php +++ b/Tests/Unit/Routing/RedirectRouteProviderTest.php @@ -12,6 +12,7 @@ namespace Sulu\Bundle\RedirectBundle\Tests\Unit\Routing; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface; use Sulu\Bundle\RedirectBundle\Model\RedirectRouteRepositoryInterface; use Sulu\Bundle\RedirectBundle\Routing\RedirectRouteProvider; @@ -20,6 +21,8 @@ class RedirectRouteProviderTest extends TestCase { + use ProphecyTrait; + /** * @var RedirectRouteRepositoryInterface */ diff --git a/Tests/prophecy-trailt-bc-layer.php b/Tests/prophecy-trailt-bc-layer.php new file mode 100644 index 0000000..55757af --- /dev/null +++ b/Tests/prophecy-trailt-bc-layer.php @@ -0,0 +1,19 @@ + Date: Wed, 24 Jul 2024 16:20:38 +0200 Subject: [PATCH 3/3] BC Layer --- .github/workflows/test-application.yaml | 4 ++-- Tests/Application/config/bootstrap.php | 4 ++++ Tests/Unit/Controller/RedirectRouteImportControllerTest.php | 4 ++-- ...ophecy-trailt-bc-layer.php => prophecy-trait-bc-layer.php} | 0 Tests/test-bootstrap.php | 4 ---- phpstan.neon | 1 + 6 files changed, 9 insertions(+), 8 deletions(-) rename Tests/{prophecy-trailt-bc-layer.php => prophecy-trait-bc-layer.php} (100%) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index cf433db..4025d41 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -18,7 +18,7 @@ jobs: - php-version: '7.2' dependency-versions: 'lowest' php-extensions: 'mysql, gd' - tools: 'composer:v1' + tools: 'composer:v2' env: SYMFONY_DEPRECATIONS_HELPER: disabled @@ -119,7 +119,7 @@ jobs: - name: Install and configure PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.3' extensions: 'mysql, imagick' tools: 'composer:v2' coverage: none diff --git a/Tests/Application/config/bootstrap.php b/Tests/Application/config/bootstrap.php index 3bc0a8f..b380d97 100644 --- a/Tests/Application/config/bootstrap.php +++ b/Tests/Application/config/bootstrap.php @@ -21,6 +21,10 @@ require $file; +if (!\trait_exists(Prophecy\PhpUnit\ProphecyTrait::class)) { // backwards compatibility layer for < PHP 7.3 + require __DIR__ . '/../../prophecy-trait-bc-layer.php'; +} + // Load cached env vars if the .env.local.php file exists // Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) if (is_array($env = @include dirname(__DIR__) . '/.env.local.php')) { diff --git a/Tests/Unit/Controller/RedirectRouteImportControllerTest.php b/Tests/Unit/Controller/RedirectRouteImportControllerTest.php index f29438c..157a553 100644 --- a/Tests/Unit/Controller/RedirectRouteImportControllerTest.php +++ b/Tests/Unit/Controller/RedirectRouteImportControllerTest.php @@ -107,7 +107,7 @@ public function testImportActionConverterNotFound() $import->import(Argument::any())->willThrow(ConverterNotFoundException::class); $controller = new RedirectRouteImportController($import->reveal(), $this->importPath); - $response = $controller->postAction($request->reveal(), $this->importPath); + $response = $controller->postAction($request, $this->importPath); $this->assertInstanceOf(JsonResponse::class, $response); $this->assertEquals(400, $response->getStatusCode()); @@ -122,7 +122,7 @@ public function testImportActionNoFile() $import->import(Argument::any())->shouldNotBeCalled(); $controller = new RedirectRouteImportController($import->reveal(), $this->importPath); - $response = $controller->postAction($request->reveal(), $this->importPath); + $response = $controller->postAction($request, $this->importPath); $this->assertInstanceOf(JsonResponse::class, $response); $this->assertEquals(400, $response->getStatusCode()); diff --git a/Tests/prophecy-trailt-bc-layer.php b/Tests/prophecy-trait-bc-layer.php similarity index 100% rename from Tests/prophecy-trailt-bc-layer.php rename to Tests/prophecy-trait-bc-layer.php diff --git a/Tests/test-bootstrap.php b/Tests/test-bootstrap.php index 9bd366c..42d9d77 100644 --- a/Tests/test-bootstrap.php +++ b/Tests/test-bootstrap.php @@ -12,7 +12,3 @@ */ require __DIR__ . '/Application/config/bootstrap.php'; - -if (!\trait_exists(Prophecy\PhpUnit\ProphecyTrait::class)) { // backwards compatibility layer for < PHP 7.3 - require __DIR__ . '/prophecy-trait-bc-layer.php'; -} diff --git a/phpstan.neon b/phpstan.neon index eb7045b..9c81319 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,6 +14,7 @@ parameters: excludePaths: - %currentWorkingDirectory%/vendor/* - %currentWorkingDirectory%/Tests/Application/var/* + - %currentWorkingDirectory%/Tests/prophecy-trait-bc-layer.php symfony: container_xml_path: %currentWorkingDirectory%/Tests/Application/var/cache/admin/dev/Sulu_Bundle_RedirectBundle_Tests_Application_KernelDevDebugContainer.xml console_application_loader: Tests/phpstan/console-application.php