Skip to content

Commit

Permalink
Fix Ci compatibility to Sulu 2.6 compatibility and fix ProphecyTrait …
Browse files Browse the repository at this point in the history
…warning (#55)

* Fix prophecy requirement

* Split Test and Lint task

* Fix phpstan error

* Remove lint flag

* Fix PHP 7.2 compatibility

* Fix lint

* Fix phpspec/prophecy-phpunit compatibility

* Fix check in Kernel
  • Loading branch information
alexander-schranz authored Jun 10, 2024
1 parent 62c1224 commit 222ea12
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 18 deletions.
58 changes: 45 additions & 13 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,41 @@ jobs:
matrix:
include:
- php-version: '7.2'
lint: false
dependency-versions: 'lowest'
tools: 'composer:v1'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

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

- php-version: '8.0'
lint: true
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '8.1'
lint: true
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '8.2'
lint: true
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '8.3'
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

services:
mysql:
image: mysql:5.7
Expand All @@ -62,7 +66,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 @@ -71,20 +75,48 @@ jobs:
extensions: 'mysql, gd'
tools: ${{ matrix.tools }}

- name: Remove phpspec/prophecy-phpunit
if: ${{ matrix.php-version == '7.2' }}
run: composer remove phpspec/prophecy-phpunit --no-update --dev

- 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@v2
with:
dependency-versions: ${{matrix.dependency-versions}}

- name: Bootstrap test environment
run: composer bootstrap-test-environment
env: ${{ matrix.env }}

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

- name: Execute test cases
run: composer test
env: ${{ matrix.env }}

lint:
name: 'PHP Lint'
runs-on: ubuntu-latest

env:
DATABASE_URL: 'mysql://root:[email protected]/sulu_comment_test?serverVersion=5.7'

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

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: 'mysql, gd'
tools: 'composer:v2'

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

- name: Lint code
run: composer lint
1 change: 1 addition & 0 deletions Entity/ThreadRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function findThreadsByIds(array $ids): array
->setParameter('ids', $ids)
->getQuery();

/** @var ThreadInterface[] */
return $query->getResult();
}

Expand Down
11 changes: 7 additions & 4 deletions Tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ public function registerBundles(): iterable
return $bundles;
}

public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);

$context = $this->getContext();
$loader->load(__DIR__ . '/config/config_' . $context . '.yml');

if (\version_compare(Kernel::VERSION, '6.0.0', '>=')) {
$loader->load(__DIR__ . '/config/security-6.yml');
} else {
if (\class_exists(\Symfony\Bundle\SecurityBundle\Command\UserPasswordEncoderCommand::class)) { // detect Symfony <= 5.4
$loader->load(__DIR__ . '/config/security-5-4.yml');
} else {
$loader->load(__DIR__ . '/config/security-6.yml');
}
}

/**
* @return array<string, mixed>
*/
protected function getKernelParameters(): array
{
$parameters = parent::getKernelParameters();
Expand Down
2 changes: 1 addition & 1 deletion Tests/Application/bin/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if (\class_exists(Debug::class)) {
Debug::enable();
} else {
\Symfony\Component\Debug\Debug::enable();
Symfony\Component\Debug\Debug::enable();
}
}

Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Entity/ThreadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\CommentBundle\Entity\CommentInterface;
use Sulu\Bundle\CommentBundle\Entity\Thread;

class ThreadTest extends TestCase
{
use ProphecyTrait;

public function testCommentCount()
{
$thread = new Thread('test', 1);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Manager/CommentManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\CommentBundle\Entity\CommentInterface;
use Sulu\Bundle\CommentBundle\Entity\CommentRepositoryInterface;
use Sulu\Bundle\CommentBundle\Entity\ThreadInterface;
Expand All @@ -26,6 +27,8 @@

class CommentManagerTest extends TestCase
{
use ProphecyTrait;

/**
* @var ThreadRepositoryInterface
*/
Expand Down
1 change: 1 addition & 0 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}

require $file;
require_once __DIR__ . '/prophecy_php_7_2.php';

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
Expand Down
18 changes: 18 additions & 0 deletions Tests/prophecy_php_7_2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Prophecy\PhpUnit; // BC bridge for PHP 7.2 where we can not install phpspec/prophecy-phpunit package

if (!\trait_exists(ProphecyTrait::class)) {
trait ProphecyTrait
{
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"massive/search-bundle": "^2.0.0",
"php-ffmpeg/php-ffmpeg": "^0.14 || ^1.0",
"phpspec/prophecy": "^1.17",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
Expand Down

0 comments on commit 222ea12

Please sign in to comment.