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

DevKit updates for 3.x branch #698

Merged
merged 10 commits into from
Dec 16, 2023
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
12 changes: 4 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ jobs:
dependencies: lowest
allowed-to-fail: false
variant: normal
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
variant: sonata-project/block-bundle:"5.0.0-alpha-1"
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
Expand All @@ -54,13 +50,13 @@ jobs:
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
symfony-require: 6.2.*
variant: symfony/symfony:"6.2.*"
symfony-require: 6.3.*
variant: symfony/symfony:"6.3.*"
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
symfony-require: 6.3.*
variant: symfony/symfony:"6.3.*"
symfony-require: 6.4.*
variant: symfony/symfony:"6.4.*"

steps:
- name: Checkout
Expand Down
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
]],
'php_unit_strict' => true,
'php_unit_test_case_static_method_calls' => true,
'php_unit_data_provider_name' => true,
'php_unit_data_provider_return_type' => true,
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress', 'phpstan-var']],
'single_line_throw' => false,
'static_lambda' => true,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^0.17",
"rector/rector": "^0.18",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^5.4 || ^6.2",
"symfony/css-selector": "^5.4 || ^6.2",
Expand Down
10 changes: 8 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
Expand All @@ -30,12 +33,15 @@

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
PHPUnitLevelSetList::UP_TO_PHPUNIT_90,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]);

$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);
$rectorConfig->skip([
CountOnNullRector::class,
ExceptionHandlerTypehintRector::class,
AddSeeTestAnnotationRector::class,
PreferPHPUnitThisCallRector::class,
]);
};
1 change: 1 addition & 0 deletions src/Admin/Extension/Gedmo/TranslatableAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ 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(
'There is no locale or language property found on class: "%s"',
Expand Down
2 changes: 0 additions & 2 deletions src/Block/LocaleSwitcherBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function execute(BlockContextInterface $blockContext, ?Response $response
{
$template = $blockContext->getTemplate();

\assert(\is_string($template));

return $this->renderResponse($template, [
'block_context' => $blockContext,
'block' => $blockContext->getBlock(),
Expand Down
9 changes: 7 additions & 2 deletions src/DependencyInjection/SonataTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand Down Expand Up @@ -155,10 +156,14 @@ private function registerTranslatableListener(ContainerBuilder $container, array
// Registration based on the documentation
// see https://github.com/doctrine-extensions/DoctrineExtensions/blob/7c0d5aeab0f840d2a18a18c3dc10b0117c597a42/doc/symfony4.md#doctrine-extension-listener-services
$container->register('sonata_translation.listener.translatable', TranslatableListener::class)
->addMethodCall('setAnnotationReader', [new Reference('annotation_reader')])
->addMethodCall('setAnnotationReader', [new Reference('annotation_reader', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
->addMethodCall('setDefaultLocale', ['%locale%'])
->addMethodCall('setTranslatableLocale', ['%locale%'])
->addMethodCall('setTranslationFallback', [false])
->addTag('doctrine.event_subscriber');
->addTag('doctrine.event_listener', ['event' => 'postLoad'])
->addTag('doctrine.event_listener', ['event' => 'postPersist'])
->addTag('doctrine.event_listener', ['event' => 'preFlush'])
->addTag('doctrine.event_listener', ['event' => 'onFlush'])
->addTag('doctrine.event_listener', ['event' => 'loadClassMetadata']);
}
}
2 changes: 1 addition & 1 deletion src/Twig/Extension/SonataTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function isTranslatable($object): bool
return $this->getTranslatableChecker()->isTranslatable($object);
}

public function getLocaleName(string $locale, ?string $displayLocale = null): ?string
public function getLocaleName(string $locale, ?string $displayLocale = null): string
{
return Locales::getName($locale, $displayLocale);
}
Expand Down
3 changes: 0 additions & 3 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ protected function configureRoutes(RoutingConfigurator $routes): void
$routes->import(sprintf('%s/config/routes.yaml', $this->getProjectDir()));
}

/**
* @psalm-suppress DeprecatedClass
*/
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->setParameter('app.base_dir', $this->getBaseDir());
Expand Down
32 changes: 32 additions & 0 deletions tests/App/Provider/DummyUserProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\TranslationBundle\Tests\App\Provider;

use Knp\DoctrineBehaviors\Contract\Provider\UserProviderInterface;

final class DummyUserProvider implements UserProviderInterface
{
/**
* @return object|string|null
*/
public function provideUser()
{
return null;
}

public function provideUserEntity(): ?string
{
return null;
}
}
14 changes: 12 additions & 2 deletions tests/App/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Gedmo\Translatable\TranslatableListener;
use Knp\DoctrineBehaviors\Provider\UserProvider;
use Sonata\TranslationBundle\Tests\App\Admin\GedmoCategoryAdmin;
use Sonata\TranslationBundle\Tests\App\Admin\KnpCategoryAdmin;
use Sonata\TranslationBundle\Tests\App\Entity\GedmoCategory;
use Sonata\TranslationBundle\Tests\App\Entity\KnpCategory;
use Sonata\TranslationBundle\Tests\App\Provider\DummyUserProvider;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->services()
Expand All @@ -42,8 +44,16 @@
])

->set('app.gedmo.translation_listener', TranslatableListener::class)
->call('setAnnotationReader', [service('annotation_reader')])
->call('setAnnotationReader', [service('annotation_reader')->nullOnInvalid()])
->call('setDefaultLocale', [param('locale')])
->call('setTranslationFallback', [false])
->tag('doctrine.event_subscriber');
->tag('doctrine.event_listener', ['event' => 'postLoad'])
->tag('doctrine.event_listener', ['event' => 'postPersist'])
->tag('doctrine.event_listener', ['event' => 'preFlush'])
->tag('doctrine.event_listener', ['event' => 'onFlush'])
->tag('doctrine.event_listener', ['event' => 'loadClassMetadata'])

// Temporary fix to decorate User Provider from KNP (see https://github.com/KnpLabs/DoctrineBehaviors/pull/727)
->set(DummyUserProvider::class)
->decorate(UserProvider::class);
};
4 changes: 2 additions & 2 deletions tests/Checker/TranslatableCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
/**
* @return iterable<array{object|class-string, array<class-string>, array<class-string>}>
*/
public function provideTestIsTranslatable(): iterable
public function provideIsTranslatableCases(): iterable
{
yield 'object-by-model' => [
new ModelCustomTranslatable(),
Expand Down Expand Up @@ -61,7 +61,7 @@ public function provideTestIsTranslatable(): iterable
}

/**
* @dataProvider provideTestIsTranslatable
* @dataProvider provideIsTranslatableCases
*
* @phpstan-param object|class-string $classOrObject
* @phpstan-param class-string[] $supportedModels
Expand Down
3 changes: 2 additions & 1 deletion tests/DependencyInjection/SonataTranslationExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Sonata\TranslationBundle\DependencyInjection\SonataTranslationExtension;
use Sonata\TranslationBundle\Filter\TranslationFieldFilter;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ public function testRegistersTranslatableListenerWhenUsingGedmo(): void
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
'sonata_translation.listener.translatable',
'setAnnotationReader',
[new Reference('annotation_reader')]
[new Reference('annotation_reader', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]
);

$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
Expand Down
12 changes: 6 additions & 6 deletions tests/Functional/GedmoCRUDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function setUp(): void
}

/**
* @dataProvider provideLocales
* @dataProvider provideListCases
*/
public function testList(string $locale, string $name): void
{
Expand All @@ -42,7 +42,7 @@ public function testList(string $locale, string $name): void
/**
* @return iterable<array{string, string}>
*/
public function provideLocales(): iterable
public function provideListCases(): iterable
{
yield 'default english' => ['', 'Novel'];
yield 'english' => ['en', 'Novel'];
Expand All @@ -51,7 +51,7 @@ public function provideLocales(): iterable
}

/**
* @dataProvider provideLocalesToCreate
* @dataProvider provideCreateCases
*/
public function testCreate(string $locale, string $newName): void
{
Expand Down Expand Up @@ -87,7 +87,7 @@ public function testCreate(string $locale, string $newName): void
/**
* @return iterable<array{string, string}>
*/
public function provideLocalesToCreate(): iterable
public function provideCreateCases(): iterable
{
yield 'default english' => ['', 'Default New Novel'];
yield 'english' => ['en', 'New Novel'];
Expand All @@ -96,7 +96,7 @@ public function provideLocalesToCreate(): iterable
}

/**
* @dataProvider provideLocalesToEdit
* @dataProvider provideEditCases
*/
public function testEdit(string $locale, string $editedName): void
{
Expand Down Expand Up @@ -128,7 +128,7 @@ public function testEdit(string $locale, string $editedName): void
/**
* @return iterable<array{string, string}>
*/
public function provideLocalesToEdit(): iterable
public function provideEditCases(): iterable
{
yield 'default english' => ['', 'Edited Default Novel'];
yield 'english' => ['en', 'Edited Novel'];
Expand Down
12 changes: 6 additions & 6 deletions tests/Functional/KnpCRUDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function setUp(): void
}

/**
* @dataProvider provideLocales
* @dataProvider provideListCases
*/
public function testList(string $locale, string $name): void
{
Expand All @@ -42,7 +42,7 @@ public function testList(string $locale, string $name): void
/**
* @return iterable<array{string, string}>
*/
public function provideLocales(): iterable
public function provideListCases(): iterable
{
yield 'default english' => ['', 'Novel'];
yield 'english' => ['en', 'Novel'];
Expand All @@ -51,7 +51,7 @@ public function provideLocales(): iterable
}

/**
* @dataProvider provideLocalesToCreate
* @dataProvider provideCreateCases
*/
public function testCreate(string $locale, string $newName): void
{
Expand Down Expand Up @@ -87,7 +87,7 @@ public function testCreate(string $locale, string $newName): void
/**
* @return iterable<array{string, string}>
*/
public function provideLocalesToCreate(): iterable
public function provideCreateCases(): iterable
{
yield 'default english' => ['', 'Default New Novel'];
yield 'english' => ['en', 'New Novel'];
Expand All @@ -96,7 +96,7 @@ public function provideLocalesToCreate(): iterable
}

/**
* @dataProvider provideLocalesToEdit
* @dataProvider provideEditCases
*/
public function testEdit(string $locale, string $editedName): void
{
Expand Down Expand Up @@ -128,7 +128,7 @@ public function testEdit(string $locale, string $editedName): void
/**
* @return iterable<array{string, string}>
*/
public function provideLocalesToEdit(): iterable
public function provideEditCases(): iterable
{
yield 'default english' => ['', 'Edited Default Novel'];
yield 'english' => ['en', 'Edited Novel'];
Expand Down
8 changes: 4 additions & 4 deletions tests/Provider/Knplabs/LocaleProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
final class LocaleProviderTest extends TestCase
{
/**
* @dataProvider provideValues
* @dataProvider provideUsesTheProperProviderBasedOnRequestCases
*/
public function testUsesTheProperProviderBasedOnRequest(
string $expectedLocale,
Expand Down Expand Up @@ -53,7 +53,7 @@ public function testUsesTheProperProviderBasedOnRequest(
/**
* @return iterable<array{string, string, string, bool}>
*/
public function provideValues(): iterable
public function provideUsesTheProperProviderBasedOnRequestCases(): iterable
{
yield 'with sonata enabled it uses sonata provider' => ['en', 'es', 'en', true];
yield 'with sonata disabled it uses knp provider' => ['es', 'es', 'en', false];
Expand All @@ -66,12 +66,12 @@ public function __construct(private string $locale)
{
}

public function provideCurrentLocale(): ?string
public function provideCurrentLocale(): string
{
return $this->locale;
}

public function provideFallbackLocale(): ?string
public function provideFallbackLocale(): string
{
return $this->locale;
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Traits/DoctrineOrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ final protected function getConfiguration(): Configuration
return ORMSetup::createAttributeMetadataConfiguration(
[],
false,
sys_get_temp_dir().'/sonata-translation-bundle'
sys_get_temp_dir().'/sonata-translation-bundle',
null,
true,
);
}
}