Skip to content

Commit

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

* Increase sulu version

* Remove ignore platform reqs

* Fix phpstan error

* Fix tests on prefer lowest

* Apply suggestions from code review

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

* Fix json tests

Co-authored-by: nnatter <[email protected]>
  • Loading branch information
alexander-schranz and niklasnatter authored Feb 23, 2021
1 parent d46cf05 commit 9317a74
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 59 deletions.
39 changes: 35 additions & 4 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,42 @@ on:

jobs:
test:
name: 'PHP 7.4 (highest)'
name: 'PHP ${{ matrix.php-version }} (${{ matrix.dependency-versions }}, Lint ${{ matrix.lint }})'
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.3'
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
Expand All @@ -33,20 +61,22 @@ jobs:
- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: ${{ matrix.php-version }}
extensions: ctype, iconv, mysql
coverage: pcov
tools: composer
tools: ${{ matrix.tools }}

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: 'highest'
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 unit test cases
Expand All @@ -56,4 +86,5 @@ jobs:
run: composer test -- Tests/Functional --log-junit var/junit.xml

- name: Check code coverage
if: ${{ matrix.coverage }}
run: php vendor/bin/code-coverage-checker "var/coverage.php" "line" "95" "Content"
10 changes: 8 additions & 2 deletions Content/StructureResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,16 @@ private function getStructureData(StructureInterface $structure): array
$created = $document->getCreated();
}

$structureContent = null;

if (method_exists($structure, 'getContent')) {
$structureContent = $structure->getContent();
}

$type = 'unknown';
if (method_exists($structure, 'getContent') && method_exists($structure->getContent(), 'getTemplateType')) {
if (\is_object($structureContent) && method_exists($structureContent, 'getTemplateType')) {
// determine type for structure that is implemented based on the SuluContentBundle
$type = $structure->getContent()->getTemplateType();
$type = $structureContent->getTemplateType();
} elseif ($document instanceof StructureBehavior) {
// determine type for structure that is implemented in the SuluPageBundle or the SuluArticleBundle
$type = $this->documentInspector->getMetadata($document)->getAlias();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"categories": [],
"tags": [],
"images": [],
"segments": [],
"segments": "@[email protected]().optional()",
"icon": [],
"audience_targeting_groups": []
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/Functional/Controller/responses/navigation__get.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"template": "default",
"parent": "@uuid@",
"url": "\/test-1",
"path": "@[email protected](\"/test-1\").optional()",
"urls": {
"de": "\/test-1"
},
Expand All @@ -36,6 +37,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-2\").optional()",
"url": "\/test-2",
"urls": {
"de": "\/test-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-3\").optional()",
"url": "\/test-3",
"urls": {
"de": "\/test-3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1\").optional()",
"url": "\/test-1",
"urls": {
"de": "\/test-1"
Expand All @@ -35,6 +36,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1/test-1a\").optional()",
"url": "/test-1a",
"urls": {
"de": "/test-1a"
Expand All @@ -59,6 +61,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1/test-1b\").optional()",
"url": "/test-1b",
"urls": {
"de": "/test-1b"
Expand All @@ -85,6 +88,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-2\").optional()",
"url": "\/test-2",
"urls": {
"de": "\/test-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1\").optional()",
"url": "\/test-1",
"urls": {
"de": "\/test-1"
Expand All @@ -36,6 +37,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1/test-1a\").optional()",
"url": "/test-1a",
"urls": {
"de": "/test-1a"
Expand All @@ -60,6 +62,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-2\").optional()",
"url": "\/test-2",
"urls": {
"de": "\/test-2"
Expand All @@ -84,6 +87,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1/test-1b\").optional()",
"url": "/test-1b",
"urls": {
"de": "/test-1b"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1\").optional()",
"url": "\/test-1",
"urls": {
"de": "\/test-1"
Expand All @@ -30,7 +31,7 @@
"categories": [],
"audience_targeting_groups": [],
"tags": [],
"segments": [],
"segments": "@[email protected]().optional()",
"icon": [],
"images": []
},
Expand All @@ -51,6 +52,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-2\").optional()",
"url": "\/test-2",
"urls": {
"de": "\/test-2"
Expand All @@ -65,7 +67,7 @@
"categories": [],
"audience_targeting_groups": [],
"tags": [],
"segments": [],
"segments": "@[email protected]().optional()",
"icon": [
{
"id": "@integer@",
Expand Down Expand Up @@ -106,4 +108,3 @@
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1/test-1a\").optional()",
"url": "/test-1a",
"urls": {
"de": "/test-1a"
Expand All @@ -36,6 +37,7 @@
"webspaceKey": "sulu_io",
"template": "default",
"parent": "@uuid@",
"path": "@[email protected](\"/test-1/test-1b\").optional()",
"url": "/test-1b",
"urls": {
"de": "/test-1b"
Expand Down
Loading

0 comments on commit 9317a74

Please sign in to comment.