Skip to content

Commit

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

* Fix php-cs

* Add php 8 to matrix

* Upgrade phpstan

* Normalize psr4 autoload
  • Loading branch information
alexander-schranz authored Apr 27, 2021
1 parent 5e78464 commit 5d65d55
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.github export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
101 changes: 81 additions & 20 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,93 @@
name: PHP

on: pull_request

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

jobs:
tests:
test:
name: 'PHP ${{ matrix.php-version }} (${{ matrix.database }}, ${{ matrix.dependency-versions }})'
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- php-version: '7.2'
database: postgres
dependency-versions: 'lowest'
tools: 'composer:v1'
lint: false
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
DATABASE_URL: postgres://postgres:postgres@127.0.0.1/sulu_form_test?serverVersion=12.5
DATABASE_CHARSET: UTF8
DATABASE_COLLATE:
- php-version: '7.4'
database: mysql
dependency-versions: 'highest'
tools: 'composer:v2'
lint: false
env:
SYMFONY_DEPRECATIONS_HELPER: weak
DATABASE_URL: mysql://root:root@127.0.0.1/sulu_form_test?serverVersion=5.7
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATE: utf8mb4_unicode_ci
- php-version: '8.0'
database: mysql
dependency-versions: 'highest'
tools: 'composer:v2'
lint: true
env:
SYMFONY_DEPRECATIONS_HELPER: weak
DATABASE_URL: mysql://root:root@127.0.0.1/sulu_form_test?serverVersion=5.7
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATE: utf8mb4_unicode_ci

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

postgres:
image: postgres:12.5
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

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

- name: Validate composer.json and composer.lock
run: composer validate
- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: 'imagick'
tools: ${{ matrix.tools }}
coverage: none

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Linting code
dependency-versions: ${{matrix.dependency-versions}}

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

- name: Run unit tests
run: composer phpunit
- name: Execute test cases
run: time composer test
env: ${{ matrix.env }}
4 changes: 2 additions & 2 deletions Exception/ModelFormInvalidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(FormInterface $form)

parent::__construct(
sprintf(
'Invalid form data for "%s" on form "%s": ' . json_encode($this->getErrors(), JSON_PRETTY_PRINT),
'Invalid form data for "%s" on form "%s": ' . json_encode($this->getErrors(), \JSON_PRETTY_PRINT),
\get_class($this->form->getData()),
\get_class($this->form)
)
Expand All @@ -39,7 +39,7 @@ public function toArray(): array
$message = '';

foreach ($this->getErrors() as $fieldName => $field) {
$message .= ucfirst($fieldName) . ': ' . implode(',', $field['messages']) . PHP_EOL;
$message .= ucfirst($fieldName) . ': ' . implode(',', $field['messages']) . \PHP_EOL;
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function createDoctrineListRepresentation(
}

// disable pagination to simplify tree handling and select tree related properties that are used below
$listBuilder->limit(PHP_INT_MAX);
$listBuilder->limit(\PHP_INT_MAX);
$listBuilder->addSelectField($fieldDescriptors['lft']);
$listBuilder->addSelectField($fieldDescriptors['rgt']);
$listBuilder->addSelectField($fieldDescriptors['parentId']);
Expand Down
23 changes: 16 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "sulu-bundle",
"description": "Provide resource functionality for Sulu CMS.",
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"doctrine/collections": "^1.6",
"doctrine/orm": "^2.7",
"sulu/sulu": "^2.0",
Expand All @@ -17,18 +17,27 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.12",
"jackalope/jackalope-doctrine-dbal": "^1.3.4",
"jangregor/phpstan-prophecy": "^0.5.1",
"phpstan/phpstan": "^0.12.1",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-webmozart-assert": "^0.12.2",
"sensiolabs-de/deptrac-shim": "^0.5.0",
"jangregor/phpstan-prophecy": "^0.8.1",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-doctrine": "^0.12.33",
"phpstan/phpstan-phpunit": "^0.12.18",
"phpstan/phpstan-symfony": "^0.12.21",
"phpstan/phpstan-webmozart-assert": "^0.12.12",
"symfony/monolog-bundle": "^3.1",
"symfony/phpunit-bridge": "^4.3",
"thecodingmachine/phpstan-strict-rules": "^0.12"
"thecodingmachine/phpstan-strict-rules": "^0.12.1"
},
"autoload": {
"psr-4": {
"HandcraftedInTheAlps\\Bundle\\SuluResourceBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"autoload-dev": {
"psr-4": {
"HandcraftedInTheAlps\\Bundle\\SuluResourceBundle\\Tests\\": "Tests"
}
},
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
includes:
- vendor/jangregor/phpstan-prophecy/src/extension.neon
- vendor/jangregor/phpstan-prophecy/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-doctrine/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
Expand Down

0 comments on commit 5d65d55

Please sign in to comment.