Skip to content

Commit

Permalink
Merge 3.x into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI authored Nov 11, 2024
2 parents c7b73ef + 7dc7533 commit c46aee3
Show file tree
Hide file tree
Showing 25 changed files with 257 additions and 104 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/test_symfony_7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# TEMPORARILY USED until knplabs/doctrine-behaviors is compatible with Symfony 7

name: Test

on:
schedule:
- cron: '30 0 * * *'
push:
branches:
- 3.x
- 4.x
pull_request:

permissions:
contents: read

jobs:
test:
name: PHP ${{ matrix.php-version }} + ${{ matrix.dependencies }} + ${{ matrix.variant }} (Symfony 7)

runs-on: ubuntu-latest

continue-on-error: ${{ matrix.allowed-to-fail }}

env:
SYMFONY_REQUIRE: ${{matrix.symfony-require}}

strategy:
matrix:
include:
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
symfony-require: 7.0.*
variant: symfony/symfony:"7.0.*"
- php-version: '8.3'
dependencies: highest
allowed-to-fail: false
symfony-require: 7.0.*
variant: symfony/symfony:"7.0.*"

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

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
tools: composer:v2, flex

- name: Add PHPUnit matcher
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Remove knplabs/doctrine-behaviors
run: composer remove knplabs/doctrine-behaviors --dev --no-update

- name: Install variant
if: matrix.variant != 'normal' && !startsWith(matrix.variant, 'symfony/symfony')
run: composer require ${{ matrix.variant }} --no-update

- name: Install Composer dependencies (${{ matrix.dependencies }})
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}

- name: Run Tests with coverage
run: make coverage

- name: Send coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: build/logs/clover.xml
36 changes: 18 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
"homepage": "https://docs.sonata-project.org/projects/SonataTranslationBundle",
"require": {
"php": "^8.0",
"sonata-project/admin-bundle": "^4.14",
"sonata-project/admin-bundle": "^4.15",
"sonata-project/block-bundle": "^4.11 || ^5.0",
"symfony/config": "^5.4 || ^6.2",
"symfony/dependency-injection": "^5.4 || ^6.2",
"symfony/form": "^5.4 || ^6.2",
"symfony/framework-bundle": "^5.4 || ^6.2",
"symfony/http-foundation": "^5.4 || ^6.2",
"symfony/http-kernel": "^5.4 || ^6.2",
"symfony/intl": "^5.4 || ^6.2",
"symfony/options-resolver": "^5.4 || ^6.2",
"symfony/config": "^5.4 || ^6.2 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.2 || ^7.0",
"symfony/form": "^5.4 || ^6.2 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.2 || ^7.0",
"symfony/http-foundation": "^5.4 || ^6.2 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.2 || ^7.0",
"symfony/intl": "^5.4 || ^6.2 || ^7.0",
"symfony/options-resolver": "^5.4 || ^6.2 || ^7.0",
"twig/twig": "^3.0"
},
"require-dev": {
Expand All @@ -40,9 +40,9 @@
"doctrine/persistence": "^3.0.2",
"friendsofphp/php-cs-fixer": "^3.4",
"gedmo/doctrine-extensions": "^3.11",
"knplabs/doctrine-behaviors": "^2.2",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"knplabs/doctrine-behaviors": "^2.6.2",
"matthiasnoback/symfony-config-test": "^4.2 || ^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-doctrine": "^1.0",
Expand All @@ -54,18 +54,18 @@
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^1.1",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^5.4 || ^6.2",
"symfony/css-selector": "^5.4 || ^6.2",
"symfony/doctrine-bridge": "^5.4 || ^6.2",
"symfony/filesystem": "^5.4 || ^6.2",
"symfony/phpunit-bridge": "^6.2",
"symfony/browser-kit": "^5.4 || ^6.2 || ^7.0",
"symfony/css-selector": "^5.4 || ^6.2 || ^7.0",
"symfony/doctrine-bridge": "^5.4 || ^6.2 || ^7.0",
"symfony/filesystem": "^5.4 || ^6.2 || ^7.0",
"symfony/phpunit-bridge": "^7.0",
"vimeo/psalm": "^5.8",
"weirdan/doctrine-psalm-plugin": "^2.0"
},
"conflict": {
"doctrine/persistence": "<3.0.2",
"gedmo/doctrine-extensions": "<3.11",
"knplabs/doctrine-behaviors": "<2.2 || >=3.0"
"knplabs/doctrine-behaviors": "<2.6.2 || >=3.0"
},
"suggest": {
"gedmo/doctrine-extensions": "if you translate orm entities with the gedmo extensions",
Expand Down
4 changes: 3 additions & 1 deletion src/Admin/Extension/AbstractTranslatableAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ abstract class AbstractTranslatableAdminExtension extends AbstractAdminExtension
{
/**
* Request parameter.
*
* @psalm-suppress MissingClassConstType
*/
public const TRANSLATABLE_LOCALE_PARAMETER = 'tl';

protected ?string $translatableLocale = null;

public function __construct(
protected TranslatableChecker $translatableChecker,
private LocaleProviderInterface $localeProvider
private LocaleProviderInterface $localeProvider,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Admin/Extension/Gedmo/TranslatableAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
TranslatableChecker $translatableChecker,
private TranslatableListener $translatableListener,
private ManagerRegistry $managerRegistry,
LocaleProviderInterface $localeProvider
LocaleProviderInterface $localeProvider,
) {
parent::__construct($translatableChecker, $localeProvider);
}
Expand Down Expand Up @@ -79,9 +79,9 @@ private function setLocale(object $object): void
\assert($objectManager instanceof ObjectManager);

$configuration = $this->translatableListener->getConfiguration($objectManager, $objectClassName);
/** @psalm-suppress InvalidArrayOffset */

if (!isset($configuration['locale'])) {
throw new \LogicException(sprintf(
throw new \LogicException(\sprintf(
'There is no locale or language property found on class: "%s"',
$object::class
));
Expand Down
2 changes: 1 addition & 1 deletion src/Block/LocaleSwitcherBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class LocaleSwitcherBlockService extends AbstractBlockService
{
public function __construct(
Environment $twig,
private LocaleProviderInterface $localeProvider
private LocaleProviderInterface $localeProvider,
) {
parent::__construct($twig);
}
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
final class Configuration implements ConfigurationInterface
{
/**
* @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod
* @psalm-suppress UndefinedInterfaceMethod
*
* @see https://github.com/psalm/psalm-plugin-symfony/issues/174
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/TranslationFieldFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field,

$this->setActive(true);
} else {
throw new \LogicException(sprintf('Invalid filter mode given: "%s"', $filterMode));
throw new \LogicException(\sprintf('Invalid filter mode given: "%s"', $filterMode));
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ private function applyGedmoFilters(ProxyQueryInterface $query, string $joinAlias
)
),
$query->getQueryBuilder()->expr()->like(
sprintf('%s.%s', $alias, $field),
\sprintf('%s.%s', $alias, $field),
$query->getQueryBuilder()->expr()->literal('%'.$value.'%')
)
));
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/Knplabs/LocaleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class LocaleProvider implements KnpLocaleProviderInterface
public function __construct(
private RequestStack $requestStack,
private KnpLocaleProviderInterface $localeProvider,
private SonataLocaleProviderInterface $sonataLocaleProvider
private SonataLocaleProviderInterface $sonataLocaleProvider,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Provider/RequestLocaleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class RequestLocaleProvider implements LocaleProviderInterface

public function __construct(
private RequestStack $requestStack,
private string $defaultTranslationLocale
private string $defaultTranslationLocale,
) {
}

Expand Down
11 changes: 3 additions & 8 deletions tests/Admin/Extension/AbstractTranslatableAdminExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ final class AbstractTranslatableAdminExtensionTest extends TestCase
*/
private AbstractTranslatableAdminExtension $extension;

private TranslatableChecker $translatableChecker;

/**
* @psalm-suppress InternalClass https://github.com/vimeo/psalm/issues/6315
*/
protected function setUp(): void
{
$this->translatableChecker = new TranslatableChecker();
$translatableChecker = new TranslatableChecker();

$localeProvider = new class() implements LocaleProviderInterface {
$localeProvider = new class implements LocaleProviderInterface {
public function get(): string
{
return 'es';
Expand All @@ -44,7 +39,7 @@ public function get(): string

$this->extension = new /**
* @template-extends AbstractTranslatableAdminExtension<object>
*/ class($this->translatableChecker, $localeProvider) extends AbstractTranslatableAdminExtension {};
*/ class($translatableChecker, $localeProvider) extends AbstractTranslatableAdminExtension {};
}

public function testSetsPersistentParameters(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function setUp(): void
->method('getManagerForClass')
->willReturn($this->em);

$localeProvider = new class() implements LocaleProviderInterface {
$localeProvider = new class implements LocaleProviderInterface {
public function get(): string
{
return 'es';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ final class TranslatableAdminExtensionTest extends WebTestCase

protected function setUp(): void
{
if (!interface_exists(KnpTranslatableInterface::class)) {
static::markTestSkipped('The "knplabs/doctrine-behaviors" package is not installed.');
}

$translatableChecker = new TranslatableChecker();

$translatableChecker->setSupportedInterfaces([
KnpTranslatableInterface::class,
]);

$localeProvider = new class() implements LocaleProviderInterface {
$localeProvider = new class implements LocaleProviderInterface {
public function get(): string
{
return 'es';
Expand Down
12 changes: 11 additions & 1 deletion tests/App/Admin/KnpCategoryAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\TranslationBundle\Tests\App\Entity\KnpCategory;
use Sonata\TranslationBundle\Tests\App\KnpEntity\KnpCategory;
use Symfony\Component\Form\Extension\Core\Type\TextType;

/**
* @phpstan-extends AbstractAdmin<KnpCategory>
*/
final class KnpCategoryAdmin extends AbstractAdmin
{
protected function generateBaseRouteName(bool $isChildAdmin = false): string
{
return 'admin_app_knpcategory';
}

protected function generateBaseRoutePattern(bool $isChildAdmin = false): string
{
return 'tests/app/knpcategory';
}

protected function configureListFields(ListMapper $list): void
{
$list
Expand Down
Loading

0 comments on commit c46aee3

Please sign in to comment.