Skip to content

Commit

Permalink
Add PHP 8.1 and PHP 8.2 test support (#87)
Browse files Browse the repository at this point in the history
* Make doctrine/annotations hard dependency

Doctrine bundle did make annotations optional dependency due to transitioning to attributes

* Update BundleInitializationTest.php

* Update BreadcrumbListenerTest.php

* Update BreadcrumbTrailExtensionTest.php

* Upgrade Nyholm test bundle to 2.x

* Drop Symfony 3.4 support
Add Symfony 6.x support
Add PHP 8.1 and 8.2 test coverage

* Only test PHP <8.1 on `test-lowest`

* Fix running CI, as jakzal latest does not have php-cs-fixer yet

* Fix tests

Co-authored-by: Richard van Laak <[email protected]>
  • Loading branch information
rvanlaak and Richard van Laak authored Jan 5, 2023
1 parent d99042c commit 3ac2464
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 65 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
symfony: ['3.4', '4.4', '5.1', '5.2', '5.3']
php: ['8.1', '8.2']
symfony: ['4.4.*', '5.4.*', '6.1.*', '6.2.*']

steps:
- name: Set up PHP
Expand All @@ -22,16 +22,18 @@ jobs:
php-version: ${{ matrix.php }}
coverage: none
extensions: mbstring, intl
tools: composer:v2
tools: composer:v2, flex

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Checkout code
uses: actions/checkout@v2

- name: Select supported Symfony version
run: composer require symfony/framework-bundle:"^${{ matrix.symfony }}" --no-update
- name: Download dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}
uses: ramsey/composer-install@v1

- name: Run tests
run: make test
Expand All @@ -42,7 +44,7 @@ jobs:
strategy:
max-parallel: 10
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

steps:
- name: Set up PHP
Expand All @@ -51,7 +53,7 @@ jobs:
php-version: ${{ matrix.php }}
coverage: none
extensions: mbstring, intl
tools: composer:v2
tools: composer:v2, flex

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
Expand All @@ -65,7 +67,7 @@ jobs:
codestyle:
name: Code style
runs-on: ubuntu-latest
container: jakzal/phpqa
container: jakzal/phpqa:php8.1
steps:
- uses: actions/checkout@v2
- name: PHP CS Fixer (via jakzal/phpqa)
Expand Down
37 changes: 23 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
DIR := ${CURDIR}

test-php72:
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.2 $(MAKE) test
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.2 make test

test-php73:
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.3 $(MAKE) test
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.3 make test

test-php74:
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.4 $(MAKE) test
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.4 make test

test-php80:
docker run --rm -v $(DIR):/project -w /project webdevops/php:8.0 make test

test-php81:
docker run --rm -v $(DIR):/project -w /project webdevops/php:8.1 make test

test-php82:
docker run --rm -v $(DIR):/project -w /project webdevops/php:8.2 make test

test:
composer update --prefer-dist --no-interaction ${COMPOSER_PARAMS}
composer test

test-lowest:
COMPOSER_PARAMS='--prefer-lowest' $(MAKE) test
COMPOSER_PARAMS='--prefer-lowest' make test

test-php72-lowest:
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.2 $(MAKE) test-lowest
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.2 make test-lowest

test-php73-lowest:
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.3 $(MAKE) test-lowest
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.3 make test-lowest

test-php74-lowest:
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.4 $(MAKE) test-lowest
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.4 make test-lowest

cs:
docker run --rm -v $(DIR):/project -w /project jakzal/phpqa php-cs-fixer fix -vv ${CS_PARAMS}
cs: composer.lock
docker run --rm -v $(DIR):/project -w /project jakzal/phpqa:php8.1 php-cs-fixer fix -vv ${CS_PARAMS}

test-cs:
CS_PARAMS='--dry-run' $(MAKE) cs
test-cs: composer.lock
CS_PARAMS='--dry-run' make cs

static:
static: composer.lock
docker run --rm -v $(DIR):/project -w /project jakzal/phpqa phpstan analyze -c .phpstan.neon

composer:
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.2 composer install
composer.lock:
docker run --rm -v $(DIR):/project -w /project jakzal/phpqa composer install
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"require": {
"php": ">=7.2",
"symfony/framework-bundle": "^3.4|^4.0|^5.0|^6.0",
"symfony/framework-bundle": "^4.0|^5.0|^6.0",
"twig/twig": "^1.41|^2.7|^3.0",
"symfony/deprecation-contracts": "^2.4|^3.0"
},
Expand All @@ -23,13 +23,13 @@
},
"require-dev": {
"symfony/phpunit-bridge": "^5.0|^6.0",
"nyholm/symfony-bundle-test": "^1.5",
"nyholm/symfony-bundle-test": "^v2.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"doctrine/doctrine-bundle": "^v1.0|^v2.0",
"doctrine/annotations": "^v1.7",
"symfony/twig-bundle": "^3.4|^4.0|^5.0|^6.0"
},
"conflict": {
"doctrine/annotations": "< 1.7",
"symfony/framework-bundle": "<3.4.26 || >4 <4.1.12 || >4.2 <4.2.7",
"twig/twig": ">=2.0 <2.15.3"
},
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ini name="intl.default_locale" value="en" />
<ini name="intl.error_level" value="0" />
<ini name="memory_limit" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=6" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=7" />
<env name="SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT " value="1" />
</php>

Expand Down
3 changes: 1 addition & 2 deletions src/BreadcrumbTrail/Trail.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Traversable;

class Trail implements \IteratorAggregate, \Countable
{
Expand Down Expand Up @@ -197,7 +196,7 @@ public function count(): int
/**
* {@inheritDoc}
*/
public function getIterator(): Traversable
public function getIterator(): \Traversable
{
$this->breadcrumbs->rewind();

Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/APYBreadcrumbTrailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private function deprecateService(ContainerBuilder $container, string $id)
if (version_compare(Kernel::VERSION, '5.1.0', '>=')) {
$alias->setDeprecated('APY/BreadcrumbTrailBundle', '1.7', 'The service is deprecated, use "%alias_id%" FQCN as service id instead.');
} elseif (version_compare(Kernel::VERSION, '4.3.0', '>=')) {
/* @phpstan-ignore-next-line */
$alias->setDeprecated();
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
#[\ReturnTypeWillChange]
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('apy_breadcrumb_trail');
Expand Down
25 changes: 19 additions & 6 deletions tests/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@

namespace APY\BreadcrumbTrailBundle;

use Nyholm\BundleTest\BaseBundleTestCase;
use Nyholm\BundleTest\TestKernel;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

class BundleInitializationTest extends BaseBundleTestCase
class BundleInitializationTest extends KernelTestCase
{
protected function getBundleClass()
protected static function getKernelClass(): string
{
return APYBreadcrumbTrailBundle::class;
return TestKernel::class;
}

protected static function createKernel(array $options = []): KernelInterface
{
/**
* @var TestKernel $kernel
*/
$kernel = parent::createKernel($options);
$kernel->addTestBundle(APYBreadcrumbTrailBundle::class);
$kernel->handleOptions($options);

return $kernel;
}

public function testServicesAreRegisteredToContainer()
{
$this->bootKernel();
$container = $this->getContainer();
$container = self::bootKernel()->getContainer();

$this->assertTrue($container->has('apy_breadcrumb_trail'));
$this->assertTrue($container->has('apy_breadcrumb_trail.annotation.listener'));
Expand Down
37 changes: 24 additions & 13 deletions tests/EventListener/BreadcrumbListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,43 @@
use APY\BreadcrumbTrailBundle\Fixtures\InvokableControllerWithAnnotations;
use APY\BreadcrumbTrailBundle\Fixtures\ResetTrailAttribute;
use APY\BreadcrumbTrailBundle\MixedAnnotationWithAttributeBreadcrumbsException;
use Nyholm\BundleTest\AppKernel;
use Nyholm\BundleTest\BaseBundleTestCase;
use Nyholm\BundleTest\TestKernel;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;

class BreadcrumbListenerTest extends BaseBundleTestCase
class BreadcrumbListenerTest extends KernelTestCase
{
/** @var BreadcrumbListener */
private $listener;

/** @var Trail */
private $breadcrumbTrail;

/** @var AppKernel */
private $kernel;
protected static function getKernelClass(): string
{
return TestKernel::class;
}

protected static function createKernel(array $options = []): KernelInterface
{
/** @var TestKernel $kernel */
$kernel = parent::createKernel($options);
$kernel->addTestBundle(APYBreadcrumbTrailBundle::class);
$kernel->handleOptions($options);

return $kernel;
}

protected function setUpTest(): void
{
// TODO rename this to setUp method once bumping PHP to supporting return type declarations
$this->kernel = $this->createKernel();
$this->kernel->boot();
$this->listener = $this->getContainer()->get('apy_breadcrumb_trail.annotation.listener');
$this->breadcrumbTrail = $this->getContainer()->get('apy_breadcrumb_trail');
$kernel = self::bootKernel();
$this->listener = $kernel->getContainer()->get('apy_breadcrumb_trail.annotation.listener');
$this->breadcrumbTrail = $kernel->getContainer()->get('apy_breadcrumb_trail');
}

public function testAnnotations()
Expand Down Expand Up @@ -101,7 +112,7 @@ public function testResetTrailAttribute()
self::assertCount(1, $this->breadcrumbTrail);
}

protected function getBundleClass()
protected function getBundleClass(): string
{
return APYBreadcrumbTrailBundle::class;
}
Expand All @@ -113,9 +124,9 @@ private function createControllerEvent($controller)
{
$callable = \is_callable($controller) ? $controller : [$controller, 'indexAction'];
if (Kernel::MAJOR_VERSION <= 4) {
return new FilterControllerEvent($this->kernel, $callable, new Request(), HttpKernelInterface::MASTER_REQUEST);
return new FilterControllerEvent(self::$kernel, $callable, new Request(), HttpKernelInterface::MASTER_REQUEST);
}

return new ControllerEvent($this->kernel, $callable, new Request(), HttpKernelInterface::MASTER_REQUEST);
return new ControllerEvent(self::$kernel, $callable, new Request(), HttpKernelInterface::MASTER_REQUEST);
}
}
38 changes: 23 additions & 15 deletions tests/Twig/BreadcrumbTrailExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,44 @@
namespace APY\BreadcrumbTrailBundle\Twig;

use APY\BreadcrumbTrailBundle\APYBreadcrumbTrailBundle;
use Nyholm\BundleTest\BaseBundleTestCase;
use Nyholm\BundleTest\TestKernel;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Twig\Environment;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* @coversDefaultClass \APY\BreadcrumbTrailBundle\Twig\BreadcrumbTrailExtension
*/
class BreadcrumbTrailExtensionTest extends BaseBundleTestCase
class BreadcrumbTrailExtensionTest extends KernelTestCase
{
protected function getBundleClass()
protected static function getKernelClass(): string
{
return APYBreadcrumbTrailBundle::class;
return TestKernel::class;
}

protected function setUp(): void
protected static function createKernel(array $options = []): KernelInterface
{
$kernel = $this->createKernel();
$kernel->addBundle(TwigBundle::class);
$kernel->boot();
/** @var TestKernel $kernel */
$kernel = parent::createKernel($options);
$kernel->addTestBundle(APYBreadcrumbTrailBundle::class);
$kernel->addTestBundle(TwigBundle::class);
$kernel->handleOptions($options);

return $kernel;
}

/**
* @requires PHP >= 8.0
*/
public function testTwigFunctionGetsRegistered()
{
$container = $this->getContainer();
$container = self::getContainer();

/** @var BreadcrumbTrailExtension $extension */
$extension = $container->get(BreadcrumbTrailExtension::class);

/** @var Environment $twig */
$twig = $container->get('twig');
$function = current($extension->getFunctions());

self::assertNotNull(
$twig->getFunction('apy_breadcrumb_trail_render')
);
self::assertEquals('apy_breadcrumb_trail_render', $function->getName());
}
}

0 comments on commit 3ac2464

Please sign in to comment.