Skip to content

Commit

Permalink
Add support for Symfony 7 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored Apr 5, 2024
1 parent ef3ee6c commit 267c495
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 27 deletions.
57 changes: 48 additions & 9 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,39 @@ jobs:
- php-version: '7.2'
dependency-versions: 'lowest'
tools: 'composer:v1'
php-cs-fixer: false
envs:
SYMFONY_PHPUNIT_REQUIRE: phpspec/prophecy:^1.14

- php-version: '7.4'
dependency-versions: 'highest'
tools: 'composer:v2'
php-cs-fixer: false
envs:
SYMFONY_PHPUNIT_REQUIRE: phpspec/prophecy:^1.14

- php-version: '8.0'
dependency-versions: 'highest'
tools: 'composer:v2'
php-cs-fixer: false
envs:
SYMFONY_PHPUNIT_REQUIRE: phpspec/prophecy:^1.14 phpspec/prophecy-phpunit:^2.0

- php-version: '8.1'
dependency-versions: 'highest'
tools: 'composer:v2'
php-cs-fixer: true
envs:
SYMFONY_PHPUNIT_REQUIRE: phpspec/prophecy:^1.14 phpspec/prophecy-phpunit:^2.0

- php-version: '8.2'
dependency-versions: 'highest'
tools: 'composer:v2'
php-cs-fixer: false
envs:
SYMFONY_PHPUNIT_REQUIRE: phpspec/prophecy:^1.14 phpspec/prophecy-phpunit:^2.0

- php-version: '8.3'
dependency-versions: 'highest'
minimum-stability: 'dev'
tools: 'composer:v2'
envs:
SYMFONY_PHPUNIT_REQUIRE: phpspec/prophecy:^1.14 phpspec/prophecy-phpunit:^2.0

steps:
- name: Checkout project
Expand All @@ -51,20 +63,47 @@ jobs:
php-version: ${{ matrix.php-version }}
tools: ${{ matrix.tools }}

- name: Set composer stability
if: ${{ matrix.composer-stability }}
run: composer config minimum-stability ${{ matrix.composer-stability }}

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: ${{matrix.dependency-versions}}

- name: Install PHPUnit
run: vendor/bin/simple-phpunit install
env:
SYMFONY_PHPUNIT_REQUIRE: ${{ matrix.envs.SYMFONY_PHPUNIT_REQUIRE }}

- name: Execute test cases
run: vendor/bin/simple-phpunit

lint:
name: 'PHP Lint'
runs-on: ubuntu-latest

steps:
- name: Checkout project
uses: actions/checkout@v2

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: 'composer:v2'

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: 'highest'

- name: Run php-cs-fixer
if: ${{ matrix.php-cs-fixer }}
run: |
composer global require friendsofphp/php-cs-fixer --prefer-dist --no-interaction
GLOBAL_BIN_DIR=$(composer global config bin-dir --absolute --quiet)
$GLOBAL_BIN_DIR/php-cs-fixer fix --dry-run --diff
- name: Lint code
run: composer validate --strict

- name: Execute test cases
run: vendor/bin/simple-phpunit
5 changes: 4 additions & 1 deletion Build/BuildRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Massive\Bundle\BuildBundle\Build;

/**
* @final
*/
class BuildRegistry
{
protected $builders = [];
Expand Down Expand Up @@ -137,7 +140,7 @@ protected function getUnsequencedBuilders($sequences, $dependencies = null)
$dependencies = \array_keys($sequences);
}

foreach ($dependencies as $dependency) {
foreach ($dependencies as $dependency) {
if (-1 === $sequences[$dependency]) {
$unsequencedBuilders[] = $dependency;
}
Expand Down
3 changes: 3 additions & 0 deletions Build/BuilderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
class BuilderContext
{
protected $input;
Expand Down
2 changes: 2 additions & 0 deletions Builder/VirtualBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* dependencies on other builders.
*
* @author Daniel Leech <[email protected]>
*
* @final
*/
class VirtualBuilder implements BuilderInterface
{
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changelog for MassiveBuildBundle
================================

* [0.5.6 (2023-04-05)](https://github.com/massiveart/MassiveBuildBundle/releases/tag/0.5.6)
* Introduce own `ContainerAwareInterface` to keep compatibility with Symfony 7.

```diff
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Massive\Bundle\BuildBundle\ContainerAwareInterface;
```

* [0.5.5 (2023-03-15)](https://github.com/massiveart/MassiveBuildBundle/releases/tag/0.5.5)

* [0.5.4 (2022-04-21)](https://github.com/massiveart/MassiveBuildBundle/releases/tag/0.5.4)

* 0.5.3 (2020-11-11)
* ENHANCEMENT #20 Fix autoloader for composer 2

Expand Down
14 changes: 10 additions & 4 deletions Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Massive\Bundle\BuildBundle\Build\BuilderInterface;
use Massive\Bundle\BuildBundle\Build\BuildRegistry;
use Massive\Bundle\BuildBundle\Console\MassiveOutputFormatter;
use Massive\Bundle\BuildBundle\ContainerAwareInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Helper\Table;
Expand All @@ -23,9 +24,12 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface as SymfonyContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* @final
*/
class BuildCommand extends Command
{
/**
Expand Down Expand Up @@ -61,7 +65,7 @@ public function __construct(BuildRegistry $buildRegistry, ContainerInterface $co
$this->question = new QuestionHelper();
}

public function configure()
public function configure(): void
{
$this->setName('massive:build');
$this->setDescription('Execute build or build targets');
Expand All @@ -86,7 +90,7 @@ public function configure()
$this->addOption('keep-exit-code', '-k', InputOption::VALUE_NONE, 'Keep the exit code of a job if it fails');
}

public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$this->input = $input;
$this->output = $output;
Expand Down Expand Up @@ -178,7 +182,9 @@ protected function runBuilders($builders)
foreach ($builders as $builder) {
$this->output->getFormatter()->setIndentLevel(0);

if ($builder instanceof ContainerAwareInterface) {
if ($builder instanceof SymfonyContainerAwareInterface
|| $builder instanceof ContainerAwareInterface
) {
$builder->setContainer($this->container);
}

Expand Down
17 changes: 17 additions & 0 deletions ContainerAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Massive\Bundle\BuildBundle;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface as SymfonyContainerAwareInterface;

if (\class_exists(SymfonyContainerAwareInterface::class)) {
\class_alias(ContainerAwareInterface::class, SymfonyContainerAwareInterface::class);
} else {
interface ContainerAwareInterface {
/**
* @return void
*/
public function setContainer(?ContainerInterface $container = null);
}
}
6 changes: 5 additions & 1 deletion DependencyInjection/Compiler/BuilderPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

/**
* @author Daniel Leech <[email protected]>
*
* @final
*
* @internal
*/
class BuilderPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition(
'massive_build.build.registry'
Expand Down
6 changes: 5 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*
* @final
*
* @internal
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('massive_art_build');
$rootNode = $treeBuilder->getRootNode();
Expand Down
6 changes: 5 additions & 1 deletion DependencyInjection/MassiveBuildExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*
* @final
*
* @internal
*/
class MassiveBuildExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand Down
6 changes: 4 additions & 2 deletions MassiveBuildBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* @final
*/
class MassiveBuildBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new BuilderPass());
}
}
3 changes: 3 additions & 0 deletions Tests/Build/BuildRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
use Massive\Bundle\BuildBundle\Build\BuilderInterface;
use Massive\Bundle\BuildBundle\Build\BuildRegistry;
use Massive\Bundle\BuildBundle\Tests\BaseTestCase;
use Massive\Bundle\BuildBundle\Tests\ProphecyTrait;

class BuildRegistryTest extends BaseTestCase
{
use ProphecyTrait;

/**
* @var BuildRegistry
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Build/BuilderContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@

use Massive\Bundle\BuildBundle\Build\BuilderContext;
use Massive\Bundle\BuildBundle\Tests\BaseTestCase;
use Massive\Bundle\BuildBundle\Tests\ProphecyTrait;

class BuilderContextTest extends BaseTestCase
{
use ProphecyTrait;

protected $input;
protected $output;

Expand Down
5 changes: 4 additions & 1 deletion Tests/Command/BuildCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

use Massive\Bundle\BuildBundle\Build\BuilderInterface;
use Massive\Bundle\BuildBundle\Command\BuildCommand;
use Massive\Bundle\BuildBundle\ContainerAwareInterface;
use Massive\Bundle\BuildBundle\Tests\BaseTestCase;
use Massive\Bundle\BuildBundle\Tests\ProphecyTrait;
use Prophecy\Argument;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

class BuildCommandTest extends BaseTestCase
{
use ProphecyTrait;

public function setUp()
{
parent::setUp();
Expand Down
14 changes: 14 additions & 0 deletions Tests/ProphecyTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Massive\Bundle\BuildBundle\Tests;

use Prophecy\PhpUnit\ProphecyTrait as ProphecyProphecyTrait;

if (\trait_exists(ProphecyProphecyTrait::class)) {
\class_alias(ProphecyProphecyTrait::class, ProphecyTrait::class);
} else {
trait ProphecyTrait
{
// provided by phpunit 8
}
}
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
"license": "MIT",
"require": {
"php": ">=7.2.0",
"symfony/console": "^4.3 || ^5.0 || ^6.0",
"symfony/config": "^4.3 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0",
"symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0"
"symfony/console": "^4.3 || ^5.0 || ^6.0 || ^7.0",
"symfony/config": "^4.3 || ^5.0 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0 || ^7.0",
"symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.0.4 || ^6.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"phpspec/prophecy": "^1.14"
"symfony/phpunit-bridge": "^5.4.33|^6.3.10|^7.0.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0"
},
"autoload": {
"psr-4": {"Massive\\Bundle\\BuildBundle\\": "."},
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
<env name="SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT" value="1"/>
<env name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml"/>
<env name="SYMFONY_PHPUNIT_REQUIRE" value="phpspec/prophecy:^1.14"/>
</php>
</phpunit>

0 comments on commit 267c495

Please sign in to comment.