Skip to content

Commit

Permalink
Merge pull request #140 from alexander-schranz/enhancement/ci-update
Browse files Browse the repository at this point in the history
Fix Ci for Sulu 2.6 and adjust CI script for PHP 8.3 and Linting
  • Loading branch information
Prokyonn authored Jun 10, 2024
2 parents 2513db3 + 115cf30 commit ae269fb
Show file tree
Hide file tree
Showing 74 changed files with 905 additions and 62 deletions.
61 changes: 49 additions & 12 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

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

env:
Expand All @@ -22,31 +22,41 @@ jobs:
matrix:
include:
- php-version: '7.3'
lint: false
coverage: false
dependency-versions: 'lowest'
tools: 'composer:v1'
tools: 'composer:v2'
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

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

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

- php-version: '8.3'
coverage: false
dependency-versions: 'highest'
tools: 'composer:v2'
Expand All @@ -64,7 +74,7 @@ jobs:

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

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
Expand All @@ -74,19 +84,18 @@ jobs:
coverage: pcov
tools: ${{ matrix.tools }}

- name: Remove not required test tooling
run: composer remove "*php-cs-fixer*" "*phpstan*" --no-update --dev

- name: Install composer dependencies
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v3
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 unit test cases
run: composer test -- Tests/Unit --coverage-php var/coverage.php --coverage-html coverage-report --log-junit var/junit.xml

Expand All @@ -96,3 +105,31 @@ jobs:
- name: Check code coverage
if: ${{ matrix.coverage }}
run: php vendor/bin/code-coverage-checker "var/coverage.php" "line" "95" "Content"

lint:
name: 'PHP 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

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

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: ctype, iconv, mysql
tools: highest

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

- name: Lint code
run: composer lint
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

# tests
Tests/Application/var
Tests/Application/.env.dev.local
Tests/Application/.env.test.local
Tests/Application/.env.local
Tests/Application/.env.*.local

# php-cs-fixer
.php_cs.cache
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'ignored_tags' => ['todo', 'var'],
],
'trailing_comma_in_multiline' => ['elements' => ['arrays', /*'arguments', 'parameters' */]],
'modernize_strpos' => false, // remove when min requirement PHP 8
])
->setFinder($finder);

Expand Down
2 changes: 1 addition & 1 deletion Content/ContentTypeResolver/AccountSelectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (empty($data) || !\is_array($data)) {
return new ContentView([], ['ids' => []]);
}

Expand Down
2 changes: 1 addition & 1 deletion Content/ContentTypeResolver/CategorySelectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (empty($data) || !\is_array($data)) {
return new ContentView([], ['ids' => []]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function resolve($data, PropertyInterface $property, string $locale, arra
/** @var int[]|null $ids */
$ids = $data;

if (empty($ids)) {
if (empty($ids) || !\is_array($ids)) {
return new ContentView([], ['ids' => []]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (empty($data) || !\is_array($data)) {
return new ContentView([], ['ids' => []]);
}

Expand Down
2 changes: 1 addition & 1 deletion Content/ContentTypeResolver/ContactSelectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (empty($data) || !\is_array($data)) {
return new ContentView([], ['ids' => []]);
}

Expand Down
6 changes: 3 additions & 3 deletions Content/ContentTypeResolver/MediaSelectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (empty($data) || !\is_array($data)) {
return new ContentView([], ['ids' => []]);
}

$ids = $data['ids'] ?? [];

$content = [];
if (\count($ids)) {
if (\is_array($ids) && \count($ids)) {
$medias = $this->mediaManager->getByIds($ids, $locale);
$content = $this->resolveApiMedias($medias, $locale);
}
Expand All @@ -64,7 +64,7 @@ public function resolve($data, PropertyInterface $property, string $locale, arra
/**
* @param Media[] $medias
*
* @return array[]
* @return array<array<string, mixed>>
*/
private function resolveApiMedias(array $medias, string $locale): array
{
Expand Down
2 changes: 1 addition & 1 deletion Content/ContentTypeResolver/PageSelectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (empty($data) || !\is_array($data)) {
return new ContentView([], ['ids' => []]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (!\is_numeric($data)) {
return new ContentView(null, ['id' => null]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (!\is_numeric($data)) {
return new ContentView(null, ['id' => null]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ public function __construct(ContentTypeResolverInterface $collectionSelectionRes

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
/** @var int|null $id */
$id = $data;

if (empty($id)) {
if (!\is_numeric($id)) {
return new ContentView(null, ['id' => null]);
}

$content = $this->collectionSelectionResolver->resolve([$id], $property, $locale, $attributes);
$content = $this->collectionSelectionResolver->resolve([(int) $id], $property, $locale, $attributes);

/** @var mixed[]|null $contentData */
$contentData = $content->getContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public function __construct(

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (!\is_numeric($data)) {
return new ContentView(null, ['id' => null]);
}

$contact = $this->contactManager->getById($data, $locale);
$contact = $this->contactManager->getById((int) $data, $locale);
$serializationContext = new SerializationContext();
$serializationContext->setGroups(['partialContact']);

Expand Down
4 changes: 2 additions & 2 deletions Content/ContentTypeResolver/SingleMediaSelectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public function __construct(ContentTypeResolverInterface $mediaSelectionResolver

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (empty($data) || !\is_array($data)) {
return new ContentView(null, ['id' => null]);
}

$ids = \array_key_exists('id', $data) ? [$data['id']] : [];
$ids = \array_key_exists('id', $data) && \is_numeric($data['id']) ? [(int) $data['id']] : [];
$content = $this->mediaSelectionResolver->resolve(['ids' => $ids], $property, $locale, $attributes);

return new ContentView($content->getContent()[0] ?? null, \array_merge(['id' => null], $data));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(ContentTypeResolverInterface $pageSelectionResolver)

public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView
{
if (empty($data)) {
if (!\is_string($data)) {
return new ContentView(null, ['id' => null]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function resolve($data, PropertyInterface $property, string $locale, arra
$snippetId = $data ?: null;

$contentView = $this->snippetSelectionResolver->resolve(
$snippetId ? [$snippetId] : null,
\is_string($snippetId) ? [$snippetId] : null,
$property,
$locale,
$attributes
Expand Down
2 changes: 1 addition & 1 deletion Content/ContentTypeResolver/SnippetSelectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function resolve($data, PropertyInterface $property, string $locale, arra
/** @var string $defaultArea */
$defaultArea = isset($params['default']) ? $params['default']->getValue() : null;

$snippetIds = $data ?? [];
$snippetIds = \is_array($data) ? $data : [];
if (empty($snippetIds) && $defaultArea) {
$defaultSnippetId = $this->defaultSnippetManager->loadIdentifier($webspaceKey, $defaultArea);
$snippetIds = $defaultSnippetId ? [$defaultSnippetId] : [];
Expand Down
2 changes: 1 addition & 1 deletion Content/Serializer/AccountSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function serialize(AccountInterface $account, string $locale, ?Serializat
}

if (null !== $apiAccount->getLogo()) {
/** @var mixed[] $logoData */
/** @var array{id: int, url: string, thumbnails: array<string, string>} $logoData */
$logoData = $apiAccount->getLogo();
$logo = $this->mediaManager->getById($logoData['id'], $locale);
$accountData['logo'] = $this->mediaSerializer->serialize($logo->getEntity(), $locale);
Expand Down
2 changes: 1 addition & 1 deletion Content/Serializer/ContactSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function serialize(ContactInterface $contact, string $locale, ?Serializat
}

if (null !== $apiContact->getAvatar()) {
/** @var mixed[] $avatarData */
/** @var array{id: int, url: string, thumbnails: array<string, string>} $avatarData */
$avatarData = $apiContact->getAvatar();
$avatar = $this->mediaManager->getById($avatarData['id'], $locale);
$contactData['avatar'] = $this->mediaSerializer->serialize($avatar->getEntity(), $locale);
Expand Down
2 changes: 1 addition & 1 deletion Content/Serializer/MediaSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function serialize(MediaInterface $media, string $locale, ?SerializationC
$fileName = \pathinfo($fileName)['filename'] . '.' . $preferredExtension;

// extension brackets cannot be added here because of the urlencoding
$fileName = \pathinfo($fileName)['filename'] . '.' . 'extension';
$fileName = \pathinfo($fileName)['filename'] . '.extension';
$formatUri = $this->formatCache->getMediaUrl(
$formatMediaApi->getId(),
$fileName,
Expand Down
2 changes: 2 additions & 0 deletions EventSubscriber/NavigationInvalidationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ private function collectNavigationContexts(object $document, ?string $eventLocal
$defaultNavigationContexts = [];

if ($liveNode->hasProperty($propertyName)) {
/** @var string[] $liveNavigationContexts */
$liveNavigationContexts = $liveNode->getProperty($propertyName)->getValue();
}

if ($defaultNode->hasProperty($propertyName)) {
/** @var string[] $defaultNavigationContexts */
$defaultNavigationContexts = $defaultNode->getProperty($propertyName)->getValue();
}

Expand Down
Loading

0 comments on commit ae269fb

Please sign in to comment.