Skip to content

Commit 222ea12

Browse files
Fix Ci compatibility to Sulu 2.6 compatibility and fix ProphecyTrait 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
1 parent 62c1224 commit 222ea12

File tree

9 files changed

+80
-18
lines changed

9 files changed

+80
-18
lines changed

.github/workflows/test-application.yaml

+45-13
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,41 @@ jobs:
2020
matrix:
2121
include:
2222
- php-version: '7.2'
23-
lint: false
2423
dependency-versions: 'lowest'
25-
tools: 'composer:v1'
24+
tools: 'composer:v2'
2625
env:
2726
SYMFONY_DEPRECATIONS_HELPER: disabled
2827

2928
- php-version: '7.4'
30-
lint: true
3129
dependency-versions: 'highest'
3230
tools: 'composer:v2'
3331
env:
3432
SYMFONY_DEPRECATIONS_HELPER: disabled
3533

3634
- php-version: '8.0'
37-
lint: true
3835
dependency-versions: 'highest'
3936
tools: 'composer:v2'
4037
env:
4138
SYMFONY_DEPRECATIONS_HELPER: disabled
39+
4240
- php-version: '8.1'
43-
lint: true
4441
dependency-versions: 'highest'
4542
tools: 'composer:v2'
4643
env:
4744
SYMFONY_DEPRECATIONS_HELPER: disabled
45+
4846
- php-version: '8.2'
49-
lint: true
47+
dependency-versions: 'highest'
48+
tools: 'composer:v2'
49+
env:
50+
SYMFONY_DEPRECATIONS_HELPER: disabled
51+
52+
- php-version: '8.3'
5053
dependency-versions: 'highest'
5154
tools: 'composer:v2'
5255
env:
5356
SYMFONY_DEPRECATIONS_HELPER: weak
57+
5458
services:
5559
mysql:
5660
image: mysql:5.7
@@ -62,7 +66,7 @@ jobs:
6266

6367
steps:
6468
- name: Checkout project
65-
uses: actions/checkout@v2
69+
uses: actions/checkout@v4
6670

6771
- name: Install and configure PHP
6872
uses: shivammathur/setup-php@v2
@@ -71,20 +75,48 @@ jobs:
7175
extensions: 'mysql, gd'
7276
tools: ${{ matrix.tools }}
7377

78+
- name: Remove phpspec/prophecy-phpunit
79+
if: ${{ matrix.php-version == '7.2' }}
80+
run: composer remove phpspec/prophecy-phpunit --no-update --dev
81+
82+
- name: Remove not required test tooling
83+
run: composer remove "*php-cs-fixer*" "*phpstan*" --no-update --dev
84+
7485
- name: Install composer dependencies
75-
uses: ramsey/composer-install@v1
86+
uses: ramsey/composer-install@v2
7687
with:
7788
dependency-versions: ${{matrix.dependency-versions}}
7889

7990
- name: Bootstrap test environment
8091
run: composer bootstrap-test-environment
8192
env: ${{ matrix.env }}
8293

83-
- name: Lint code
84-
if: ${{ matrix.lint }}
85-
run: composer lint
86-
env: ${{ matrix.env }}
87-
8894
- name: Execute test cases
8995
run: composer test
9096
env: ${{ matrix.env }}
97+
98+
lint:
99+
name: 'PHP Lint'
100+
runs-on: ubuntu-latest
101+
102+
env:
103+
DATABASE_URL: 'mysql://root:[email protected]/sulu_comment_test?serverVersion=5.7'
104+
105+
steps:
106+
- name: Checkout project
107+
uses: actions/checkout@v4
108+
109+
- name: Install and configure PHP
110+
uses: shivammathur/setup-php@v2
111+
with:
112+
php-version: 8.3
113+
extensions: 'mysql, gd'
114+
tools: 'composer:v2'
115+
116+
- name: Install composer dependencies
117+
uses: ramsey/composer-install@v2
118+
with:
119+
dependency-versions: 'highest'
120+
121+
- name: Lint code
122+
run: composer lint

Entity/ThreadRepository.php

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function findThreadsByIds(array $ids): array
4646
->setParameter('ids', $ids)
4747
->getQuery();
4848

49+
/** @var ThreadInterface[] */
4950
return $query->getResult();
5051
}
5152

Tests/Application/Kernel.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,23 @@ public function registerBundles(): iterable
3232
return $bundles;
3333
}
3434

35-
public function registerContainerConfiguration(LoaderInterface $loader)
35+
public function registerContainerConfiguration(LoaderInterface $loader): void
3636
{
3737
parent::registerContainerConfiguration($loader);
3838

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

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

49+
/**
50+
* @return array<string, mixed>
51+
*/
4952
protected function getKernelParameters(): array
5053
{
5154
$parameters = parent::getKernelParameters();

Tests/Application/bin/console.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
if (\class_exists(Debug::class)) {
3434
Debug::enable();
3535
} else {
36-
\Symfony\Component\Debug\Debug::enable();
36+
Symfony\Component\Debug\Debug::enable();
3737
}
3838
}
3939

Tests/Unit/Entity/ThreadTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
use Doctrine\Common\Collections\ArrayCollection;
1515
use PHPUnit\Framework\TestCase;
16+
use Prophecy\PhpUnit\ProphecyTrait;
1617
use Sulu\Bundle\CommentBundle\Entity\CommentInterface;
1718
use Sulu\Bundle\CommentBundle\Entity\Thread;
1819

1920
class ThreadTest extends TestCase
2021
{
22+
use ProphecyTrait;
23+
2124
public function testCommentCount()
2225
{
2326
$thread = new Thread('test', 1);

Tests/Unit/Manager/CommentManagerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Prophecy\Argument;
16+
use Prophecy\PhpUnit\ProphecyTrait;
1617
use Sulu\Bundle\CommentBundle\Entity\CommentInterface;
1718
use Sulu\Bundle\CommentBundle\Entity\CommentRepositoryInterface;
1819
use Sulu\Bundle\CommentBundle\Entity\ThreadInterface;
@@ -26,6 +27,8 @@
2627

2728
class CommentManagerTest extends TestCase
2829
{
30+
use ProphecyTrait;
31+
2932
/**
3033
* @var ThreadRepositoryInterface
3134
*/

Tests/bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
}
2020

2121
require $file;
22+
require_once __DIR__ . '/prophecy_php_7_2.php';
2223

2324
// Load cached env vars if the .env.local.php file exists
2425
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)

Tests/prophecy_php_7_2.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Sulu.
5+
*
6+
* (c) Sulu GmbH
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Prophecy\PhpUnit; // BC bridge for PHP 7.2 where we can not install phpspec/prophecy-phpunit package
13+
14+
if (!\trait_exists(ProphecyTrait::class)) {
15+
trait ProphecyTrait
16+
{
17+
}
18+
}

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"massive/search-bundle": "^2.0.0",
2323
"php-ffmpeg/php-ffmpeg": "^0.14 || ^1.0",
2424
"phpspec/prophecy": "^1.17",
25+
"phpspec/prophecy-phpunit": "^2.0",
2526
"phpstan/phpstan": "^1.0",
2627
"phpstan/phpstan-doctrine": "^1.0",
2728
"phpstan/phpstan-phpunit": "^1.0",

0 commit comments

Comments
 (0)