Skip to content

Commit

Permalink
Add PHP 8 compatibility (#187)
Browse files Browse the repository at this point in the history
* Add PHP 8 compatibility

* Add github actions test matrix

* Fix phpstan and test matrix

* Remove circle ci integration

* Fix coverage

* Increase required versions of sulu and symfony

* Remove ignore platform reqs

* Fix deptrac dependency

* Apply suggestions from code review

Co-authored-by: nnatter <[email protected]>

* Move lint before tests

* Remove php-coveralls from composer json

* Remove coveralls config and set it in workflow

Co-authored-by: nnatter <[email protected]>
  • Loading branch information
alexander-schranz and niklasnatter authored Feb 23, 2021
1 parent 91b8b90 commit 817d852
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 163 deletions.
139 changes: 0 additions & 139 deletions .circleci/config.yml

This file was deleted.

100 changes: 100 additions & 0 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Test application

on:
pull_request:
push:
branches:
- '[0-9]+.x'
- '[0-9]+.[0-9]+'

jobs:
test:
name: 'PHP ${{ matrix.php-version }} (${{ matrix.dependency-versions }}, Lint ${{ matrix.lint }}, Coverage ${{ matrix.coverage }})'
runs-on: ubuntu-latest

env:
DATABASE_URL: mysql://root:[email protected]:3306/su_headless_test?serverVersion=5.7
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATE: utf8mb4_unicode_ci

strategy:
fail-fast: false
matrix:
include:
- php-version: '7.2'
lint: false
coverage: false
dependency-versions: 'lowest'
tools: 'composer:v1'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '7.4'
lint: true
coverage: true
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.0'
lint: false
coverage: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5

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

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ctype, iconv, mysql
coverage: pcov
tools: ${{ matrix.tools }}

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

- name: Bootstrap test environment
run: composer bootstrap-test-environment

- name: Lint Code
if: ${{ matrix.lint }}
run: composer lint

- name: Execute test cases
if: matrix.coverage == false
run: composer test

- name: Execute test cases with coverage
if: ${{ matrix.coverage }}
run: composer test-with-coverage

- name: Upload code coverage to coveralls
if: ${{ matrix.coverage }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=Tests/reports/clover.xml --json_path=Tests/reports/coveralls.json -vvv
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check code coverage
if: ${{ matrix.coverage }}
run: composer check-coverage
4 changes: 2 additions & 2 deletions Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine;

use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
Expand Down Expand Up @@ -196,7 +196,7 @@ private function addField(ClassMetadataInfo $metadata, string $name, string $typ

private function getRelationTableName(ClassMetadataInfo $metadata, string $relationName): string
{
$inflector = new Inflector();
$inflector = InflectorFactory::create()->build();
$tableNameParts = explode('_', $metadata->getTableName());
$singularName = $inflector->singularize($tableNameParts[\count($tableNameParts) - 1]) . '_';
$tableNameParts[\count($tableNameParts) - 1] = $singularName;
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/SuluContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function load(array $configs, ContainerBuilder $container): void
if ($container->hasParameter('kernel.bundles')) {
// TODO FIXME add test here
// @codeCoverageIgnoreStart
/** @var string[] $bundles */
$bundles = $container->getParameter('kernel.bundles');

if (\array_key_exists('SuluAutomationBundle', $bundles)) {
Expand Down
10 changes: 10 additions & 0 deletions Tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public function registerContainerConfiguration(LoaderInterface $loader)
parent::registerContainerConfiguration($loader);
$loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yml');
}

protected function getKernelParameters()
{
$parameters = parent::getKernelParameters();

$gedmoReflection = new \ReflectionClass(\Gedmo\Exception::class);
$parameters['gedmo_directory'] = \dirname($gedmoReflection->getFileName());

return $parameters;
}
}
2 changes: 1 addition & 1 deletion Tests/Application/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ doctrine:
gedmo_tree:
type: xml
prefix: Gedmo\Tree\Entity
dir: "%kernel.project_dir%/../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
dir: "%gedmo_directory%/Tree/Entity"
alias: GedmoTree
is_bundle: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Sulu\Automation;

use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectRepository;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Sulu\Automation;

use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectRepository;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
Expand Down
44 changes: 25 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@
"homepage": "https://github.com/sulu/SuluContentBundle",
"license": "MIT",
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"doctrine/inflector": "^1.4.1 || ^2.0.1",
"doctrine/collections": "^1.0",
"doctrine/orm": "^2.5.3",
"doctrine/persistence": "^1.3 || ^2.0",
"doctrine/doctrine-bundle": "^1.10 || ^2.0",
"friendsofsymfony/rest-bundle": "^2.6 || ^3.0",
"massive/search-bundle": "^2.4",
"ramsey/uuid": "^3.8",
"sulu/sulu": "^2.0.4",
"symfony/config": "^4.3 || ^5.0",
"symfony/dependency-injection": "^4.3 || ^5.0",
"symfony/event-dispatcher": "^4.3 || ^5.0",
"symfony/http-foundation": "^4.3 || ^5.0",
"symfony/http-kernel": "^4.3 || ^5.0",
"symfony/options-resolver": "^4.3 || ^5.0",
"symfony/property-access": "^4.3 || ^5.0",
"symfony/security-core": "^4.3 || ^5.0",
"symfony/serializer": "^4.3 || ^5.0",
"sulu/sulu": "^2.1 || ^2.3@dev",
"symfony/config": "^4.4 || ^5.0",
"symfony/dependency-injection": "^4.4 || ^5.0",
"symfony/event-dispatcher": "^4.4 || ^5.0",
"symfony/http-foundation": "^4.4 || ^5.0",
"symfony/http-kernel": "^4.4 || ^5.0",
"symfony/options-resolver": "^4.4 || ^5.0",
"symfony/property-access": "^4.4 || ^5.0",
"symfony/security-core": "^4.4 || ^5.0",
"symfony/serializer": "^4.4 || ^5.0",
"symfony/translation-contracts": "^1.0 || ^2.0",
"symfony/workflow": "^4.3 || ^5.0",
"symfony/workflow": "^4.4 || ^5.0",
"webmozart/assert": "^1.3"
},
"require-dev": {
"coduo/php-matcher": "^3.2 || ^4.0 || ^5.0",
"coduo/php-matcher": "^3.2 || ^4.0 || ^5.0 || ^6.0",
"doctrine/data-fixtures": "^1.3.3",
"doctrine/doctrine-fixtures-bundle": "^2.0 || ^3.0",
"friendsofphp/php-cs-fixer": "^2.17",
"handcraftedinthealps/code-coverage-checker": "^0.2.1",
Expand All @@ -45,15 +50,16 @@
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-symfony": "^0.12",
"phpstan/phpstan-webmozart-assert": "^0.12",
"sensiolabs-de/deptrac-shim": "^0.6.0",
"qossmic/deptrac-shim": "^0.11.1",
"sulu/automation-bundle": "^2.0@dev",
"symfony/browser-kit": "^4.3 || ^5.0",
"symfony/console": "^4.3 || ^5.0",
"symfony/debug": "^4.3",
"symfony/dotenv": "^4.3 || ^5.0",
"symfony/framework-bundle": "^4.3 || ^5.0",
"symfony/browser-kit": "^4.4 || ^5.0",
"symfony/console": "^4.4 || ^5.0",
"symfony/debug": "^4.4",
"symfony/dotenv": "^4.4 || ^5.0",
"symfony/framework-bundle": "^4.4 || ^5.0",
"symfony/monolog-bundle": "^3.1",
"symfony/phpunit-bridge": "^5.2",
"symfony/string": "^4.4 || ^5.0",
"thecodingmachine/phpstan-strict-rules": "^0.12"
},
"conflict": {
Expand Down
File renamed without changes.

0 comments on commit 817d852

Please sign in to comment.