Skip to content

Commit

Permalink
Merge 2.x into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Oct 9, 2021
2 parents 737b8d5 + 84d8dd8 commit c0ab559
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
21 changes: 21 additions & 0 deletions phpstan-object-manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Sonata\TranslationBundle\Tests\App\AppKernel;

require __DIR__.'/vendor/autoload.php';

$kernel = new AppKernel();
$kernel->boot();

return $kernel->getContainer()->get('doctrine')->getManager();
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ parameters:
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php

doctrine:
objectManagerLoader: phpstan-object-manager.php

paths:
- src
- tests
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/SonataTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private function registerTranslatableListener(ContainerBuilder $container, array
$container->register('sonata_translation.listener.translatable', TranslatableListener::class)
->addMethodCall('setAnnotationReader', [new Reference('annotation_reader')])
->addMethodCall('setDefaultLocale', ['%locale%'])
->addMethodCall('setTranslatableLocale', ['%locale%'])
->addMethodCall('setTranslationFallback', [false])
->addTag('doctrine.event_subscriber');
}
Expand Down
16 changes: 6 additions & 10 deletions tests/App/DataFixtures/GedmoCategoryFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Translatable\Entity\Translation;
use Sonata\TranslationBundle\Tests\App\Entity\GedmoCategory;

final class GedmoCategoryFixtures extends Fixture
Expand All @@ -25,17 +26,12 @@ public function load(ObjectManager $manager): void
{
$novelCategory = new GedmoCategory(self::CATEGORY, 'Novel');

$manager->persist($novelCategory);
$manager->flush();

$novelCategory->setLocale('es');
$novelCategory->setName('Novela');

$manager->flush();

$novelCategory->setLocale('fr');
$novelCategory->setName('Roman');
$repository = $manager->getRepository(Translation::class);
$repository
->translate($novelCategory, 'name', 'es', 'Novela')
->translate($novelCategory, 'name', 'fr', 'Roman');

$manager->persist($novelCategory);
$manager->flush();
}
}
2 changes: 1 addition & 1 deletion tests/App/Entity/KnpCategoryTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class KnpCategoryTranslation implements TranslationInterface
/**
* @var string|null
*
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;

Expand Down
6 changes: 6 additions & 0 deletions tests/DependencyInjection/SonataTranslationExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public function testRegistersTranslatableListenerWhenUsingGedmo(): void
'setAnnotationReader',
[new Reference('annotation_reader')]
);

$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
'sonata_translation.listener.translatable',
'setTranslatableLocale',
['%locale%']
);
}

protected function getContainerExtensions(): array
Expand Down

0 comments on commit c0ab559

Please sign in to comment.