Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ci compatibility to Sulu 2.6 compatibility and fix ProphecyTrait warning #55

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading