From 6964ba5714cc1849e3243b6882a289fc845595f9 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 24 Jul 2024 16:51:55 +0200 Subject: [PATCH] Upgrade CI for PHP 8.4 testing (#93) * Upgrade CI for PHP 8.4 testing * Update use ProphecyTrait usage * BC Layer --- .github/workflows/test-application.yaml | 32 ++++++++------- Tests/Application/config/bootstrap.php | 4 ++ .../Controller/RedirectControllerTest.php | 3 ++ .../RedirectRouteImportControllerTest.php | 39 ++++++++----------- .../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-trait-bc-layer.php | 19 +++++++++ composer.json | 5 ++- phpstan.neon | 1 + 16 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 Tests/prophecy-trait-bc-layer.php diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 48bf334..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 @@ -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,18 +114,18 @@ jobs: steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - 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 - name: Install composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: highest 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/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..157a553 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,21 +96,18 @@ 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); $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()); @@ -118,18 +115,14 @@ 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(); $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/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-trait-bc-layer.php b/Tests/prophecy-trait-bc-layer.php new file mode 100644 index 0000000..55757af --- /dev/null +++ b/Tests/prophecy-trait-bc-layer.php @@ -0,0 +1,19 @@ +