Skip to content

Commit

Permalink
Merge pull request #10 from mybuilder/php-8
Browse files Browse the repository at this point in the history
Update to PHP8
  • Loading branch information
maxbaldanza authored Sep 29, 2022
2 parents af2c3d0 + a1bf5dd commit dc34a94
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 111 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Test

on: [push]

jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.1']
symfony-versions: ['4.4.*', '5.4.*']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} with Symfony ${{ matrix.symfony-versions }}
steps:
# —— Setup Github actions 🐙 —————————————————————————————————————————————
- name: Checkout
uses: actions/checkout@v2

# https://github.com/shivammathur/setup-php (community)
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl
coverage: xdebug #optional

# https://github.com/marketplace/actions/setup-php-action#problem-matchers
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

# https://github.com/marketplace/actions/setup-php-action#problem-matchers
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

# —— Composer 🧙‍️ —————————————————————————————————————————————————————————
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ matrix.symfony-versions }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ matrix.symfony-versions }}-

- name: Validate Composer.json
run: composer validate

- name: Fix symfony version for symfony/framework-bundle
run: composer require --no-update symfony/framework-bundle:"${{ matrix.symfony-versions }}";

- name: Fix symfony version for symfony/console
run: composer require --no-update symfony/console:"${{ matrix.symfony-versions }}";

- name: Install Composer dependencies
run: composer update --no-progress --no-suggest --prefer-dist --optimize-autoloader

## —— Test ✅ ———————————————————————————————————————————————————————————
- name: Run Tests
run: php bin/phpunit --coverage-text
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bin/
vendor/
var/
/Tests/Fixtures/app/cache/
.phpunit.result.cache
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

38 changes: 11 additions & 27 deletions Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;

class DumpCommand extends Command implements ContainerAwareInterface
class DumpCommand extends Command
{
use ContainerAwareTrait;
private AnnotationSupervisorExporter $annotationSupervisorExporter;

public function __construct(AnnotationSupervisorExporter $annotationSupervisorExporter)
{
$this->annotationSupervisorExporter = $annotationSupervisorExporter;

parent::__construct();
}

protected function configure()
{
Expand All @@ -24,14 +31,11 @@ protected function configure()
->addOption('server', null, InputOption::VALUE_OPTIONAL, 'Only include programs for the specified server');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$commands = $this->getApplication()->all();

/** @var AnnotationSupervisorExporter $exporter */
$exporter = $this->getContainer()->get('mybuilder.supervisor_bundle.annotation_supervisor_exporter');

$output->write($exporter->export($commands, $this->parseOptions($input)));
$output->write($this->annotationSupervisorExporter->export($commands, $this->parseOptions($input)));

return 0;
}
Expand All @@ -54,24 +58,4 @@ private function parseOptions(InputInterface $input): array

return $options;
}

/** @throws \LogicException */
protected function getContainer(): ContainerInterface
{
if (null === $this->container) {
$application = $this->getApplication();

if (null === $application) {
throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.');
}

$this->container = $application->getKernel()->getContainer();

if (null === $this->container) {
throw new \LogicException('The container cannot be retrieved as the kernel has shut down.');
}
}

return $this->container;
}
}
11 changes: 2 additions & 9 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
// Symfony 4
$treeBuilder = new TreeBuilder('my_builder_supervisor');
$rootNode = $treeBuilder->getRootNode();
} else {
// Symfony 3
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_builder_supervisor');
}
$treeBuilder = new TreeBuilder('my_builder_supervisor');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
7 changes: 2 additions & 5 deletions Exporter/AnnotationSupervisorExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

class AnnotationSupervisorExporter
{
/** @var Reader */
private $reader;

/** @var array */
private $config;
private Reader $reader;
private array $config;

public function __construct(Reader $reader, array $config)
{
Expand Down
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/mybuilder/supervisor-bundle.svg?branch=master)](https://travis-ci.org/mybuilder/supervisor-bundle)

A bundle for Symfony 3/4/5 which allows you to use `@Supervisor` annotations to configure how [Supervisor](http://supervisord.org/) runs your console commands.
A bundle for Symfony 4/5 which allows you to use `@Supervisor` annotations to configure how [Supervisor](http://supervisord.org/) runs your console commands.

## Installation

Expand All @@ -16,18 +16,7 @@ $ php composer.phar require mybuilder/supervisor-bundle

### Enable the bundle

Enable the bundle in the `app/AppKernel.php` for Symfony 3:

```php
public function registerBundles(): array
{
return [
new MyBuilder\Bundle\SupervisorBundle\MyBuilderSupervisorBundle(),
];
}
```

Enable the bundle in the `config/bundles.php` for Symfony 4/5:
Enable the bundle in the `config/bundles.php` for Symfony:

```php
return [
Expand All @@ -37,7 +26,7 @@ return [

### Configure the bundle

You can add the following to your `config.yml` (Symfony 3) / `packages/my_builder_supervisor.yaml` (Symfony 4/5) to define your global export configuration.
You can add the following to `packages/my_builder_supervisor.yaml` for Symfony to define your global export configuration:

```yaml
my_builder_supervisor:
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ services:

# Ensure command is loaded within Symfony 4
MyBuilder\Bundle\SupervisorBundle\Command\DumpCommand:
arguments:
- '@mybuilder.supervisor_bundle.annotation_supervisor_exporter'
tags:
- { name: 'console.command' }
6 changes: 1 addition & 5 deletions Tests/Command/DumpCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MyBuilder\Bundle\SupervisorBundle\Tests\Command;

use MyBuilder\Bundle\SupervisorBundle\Command\DumpCommand;
use MyBuilder\Bundle\SupervisorBundle\Tests\Fixtures\Command\TestCommand;
use MyBuilder\Bundle\SupervisorBundle\Tests\SupervisorTestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
Expand All @@ -11,17 +10,14 @@

class DumpCommandTest extends SupervisorTestCase
{
/** @var Command */
private $command;
private Command $command;

protected function setUp(): void
{
$kernel = self::createKernel();
$kernel->boot();

$application = new Application($kernel);

$application->add(new DumpCommand());
$application->add(new TestCommand());

$this->command = $application->find('supervisor:dump');
Expand Down
3 changes: 1 addition & 2 deletions Tests/Fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace MyBuilder\Bundle\SupervisorBundle\Tests\Fixtures\app;

use Doctrine\Common\Annotations\AnnotationRegistry;
use MyBuilder\Bundle\SupervisorBundle\MyBuilderSupervisorBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
public function registerBundles()
public function registerBundles(): iterable
{
return [
new FrameworkBundle(),
Expand Down
5 changes: 2 additions & 3 deletions Tests/SupervisorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace MyBuilder\Bundle\SupervisorBundle\Tests;

use MyBuilder\Bundle\SupervisorBundle\Tests\Fixtures\app\AppKernel;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class SupervisorTestCase extends WebTestCase
{
protected static function getKernelClass()
{
require_once __DIR__ . '/Fixtures/app/AppKernel.php';

return 'MyBuilder\Bundle\SupervisorBundle\Tests\Fixtures\app\AppKernel';
return AppKernel::class;
}
}
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
}
],
"require": {
"francodacosta/supervisord": "~1.0",
"php": ">=7.4",
"doctrine/annotations": "~1.0",
"symfony/console": "~3.0||~4.0||~5.0",
"symfony/config": "~3.0||~4.0||~5.0",
"symfony/framework-bundle": "~3.0||~4.0||~5.0",
"symfony/yaml": "~3.0||^4.0||~5.0",
"php": ">=7.3"
"francodacosta/supervisord": "~1.0",
"symfony/config": "~4.0||~5.0",
"symfony/console": "~4.0||~5.0",
"symfony/framework-bundle": "~4.0||~5.0",
"symfony/yaml": "^4.0||~5.0"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"phpunit/phpunit": "~9.0"
},
"autoload": {
Expand All @@ -33,6 +32,7 @@
}
},
"config": {
"bin-dir": "bin"
"bin-dir": "bin",
"sort-packages": true
}
}
15 changes: 14 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand All @@ -10,11 +11,23 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
bootstrap="Tests/bootstrap.php">
bootstrap="Tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<testsuites>
<testsuite name="Project Test Suite">
<directory>Tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>.</directory>
</include>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
<directory>./bin</directory>
</exclude>
</coverage>
</phpunit>

0 comments on commit dc34a94

Please sign in to comment.