Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade CI for PHP 8.4 testing #93

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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 }}'
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Controller/RedirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
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;
use Symfony\Component\HttpFoundation\Request;

class RedirectControllerTest extends TestCase
{
use ProphecyTrait;

/**
* @var WebsiteRedirectController
*/
Expand Down
39 changes: 16 additions & 23 deletions Tests/Unit/Controller/RedirectRouteImportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,8 @@

class RedirectRouteImportControllerTest extends TestCase
{
use ProphecyTrait;

/**
* @var string
*/
Expand All @@ -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()),
Expand All @@ -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());
Expand Down Expand Up @@ -96,40 +96,33 @@ 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());
}

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());
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,8 @@

class GoneDocumentSubscriberTest extends TestCase
{
use ProphecyTrait;

/**
* @var GoneDocumentSubscriber
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/GoneSubscriber/GoneEntitySubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,8 @@

class GoneEntitySubscriberTest extends TestCase
{
use ProphecyTrait;

/**
* @var GoneEntitySubscriber
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/Converter/ConverterFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
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;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface;

class ConverterFacadeTest extends TestCase
{
use ProphecyTrait;

public function testSupports()
{
$data = ['title' => 'Test-Title'];
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/Converter/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/FileImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,8 @@

class FileImportTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy<ReaderInterface>
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/Reader/ReaderFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
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;
use Sulu\Bundle\RedirectBundle\Import\Reader\ReaderInterface;

class ReaderFacadeTest extends TestCase
{
use ProphecyTrait;

/**
* @var string
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/Writer/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,8 @@

class WriterTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy<RedirectRouteManagerInterface>
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Manager/RedirectRouteManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,8 @@

class RedirectRouteManagerTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy<RedirectRouteRepositoryInterface>
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Routing/RedirectRouteProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,8 @@

class RedirectRouteProviderTest extends TestCase
{
use ProphecyTrait;

/**
* @var RedirectRouteRepositoryInterface
*/
Expand Down
19 changes: 19 additions & 0 deletions Tests/prophecy-trait-bc-layer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Prophecy\PhpUnit;

/**
* @internal
*/
trait ProphecyTrait
{
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
"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",
"symfony/monolog-bundle": "^3.1",
"jackalope/jackalope-doctrine-dbal": "^1.3.4 || ^2.0",
"handcraftedinthealps/zendsearch": "^2.0",
"symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0 || ^7.0",
"phpspec/prophecy": "^1.10"
"phpspec/prophecy": "^1.10",
"phpspec/prophecy-phpunit": "^1.0 || ^2.0"
},
"keywords": [
"redirects"
Expand Down
Loading
Loading