From 0e7d13144ed8870b041eb8ab9a8177ffb9c73f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Fri, 18 Oct 2024 08:49:12 +0200 Subject: [PATCH 1/2] [phpspec-2-phpunit] migration of tests (Translation) --- ...ImmutableTranslationLocaleProviderSpec.php | 25 ++++++----- .../TranslatableEntityLocaleAssignerSpec.php | 43 ++++++++++++------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/Component/spec/Translation/Provider/ImmutableTranslationLocaleProviderSpec.php b/src/Component/spec/Translation/Provider/ImmutableTranslationLocaleProviderSpec.php index eb21a8310..092cb8a6d 100644 --- a/src/Component/spec/Translation/Provider/ImmutableTranslationLocaleProviderSpec.php +++ b/src/Component/spec/Translation/Provider/ImmutableTranslationLocaleProviderSpec.php @@ -11,30 +11,33 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Translation\Provider; +namespace Sylius\Resource\Tests\Translation\Provider; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; +use Sylius\Resource\Translation\Provider\ImmutableTranslationLocaleProvider; use Sylius\Resource\Translation\Provider\TranslationLocaleProviderInterface; -final class ImmutableTranslationLocaleProviderSpec extends ObjectBehavior +final class ImmutableTranslationLocaleProviderTest extends TestCase { - function let(): void + private ImmutableTranslationLocaleProvider $localeProvider; + + protected function setUp(): void { - $this->beConstructedWith(['pl_PL', 'en_US'], 'pl_PL'); + $this->localeProvider = new ImmutableTranslationLocaleProvider(['pl_PL', 'en_US'], 'pl_PL'); } - function it_implements_translation_locale_provider_interface(): void + public function testItImplementsTranslationLocaleProviderInterface(): void { - $this->shouldImplement(TranslationLocaleProviderInterface::class); + $this->assertInstanceOf(TranslationLocaleProviderInterface::class, $this->localeProvider); } - function it_returns_defined_locales_codes(): void + public function testItReturnsDefinedLocalesCodes(): void { - $this->getDefinedLocalesCodes()->shouldReturn(['pl_PL', 'en_US']); + $this->assertSame(['pl_PL', 'en_US'], $this->localeProvider->getDefinedLocalesCodes()); } - function it_returns_the_default_locale_code(): void + public function testItReturnsTheDefaultLocaleCode(): void { - $this->getDefaultLocaleCode()->shouldReturn('pl_PL'); + $this->assertSame('pl_PL', $this->localeProvider->getDefaultLocaleCode()); } } diff --git a/src/Component/spec/Translation/TranslatableEntityLocaleAssignerSpec.php b/src/Component/spec/Translation/TranslatableEntityLocaleAssignerSpec.php index f42abf0c8..dd3f1e870 100644 --- a/src/Component/spec/Translation/TranslatableEntityLocaleAssignerSpec.php +++ b/src/Component/spec/Translation/TranslatableEntityLocaleAssignerSpec.php @@ -11,34 +11,47 @@ declare(strict_types=1); -namespace spec\Sylius\Resource\Translation; +namespace Sylius\Resource\Tests\Translation; -use PhpSpec\ObjectBehavior; +use PHPUnit\Framework\TestCase; use Sylius\Resource\Model\TranslatableInterface; use Sylius\Resource\Translation\Provider\TranslationLocaleProviderInterface; +use Sylius\Resource\Translation\TranslatableEntityLocaleAssigner; use Sylius\Resource\Translation\TranslatableEntityLocaleAssignerInterface; -final class TranslatableEntityLocaleAssignerSpec extends ObjectBehavior +final class TranslatableEntityLocaleAssignerTest extends TestCase { - function let(TranslationLocaleProviderInterface $translationLocaleProvider): void + private TranslationLocaleProviderInterface $translationLocaleProvider; + + private TranslatableEntityLocaleAssigner $localeAssigner; + + protected function setUp(): void { - $this->beConstructedWith($translationLocaleProvider); + $this->translationLocaleProvider = $this->createMock(TranslationLocaleProviderInterface::class); + $this->localeAssigner = new TranslatableEntityLocaleAssigner($this->translationLocaleProvider); } - function it_implements_traslatable_entity_locale_assigner_interface(): void + public function testItImplementsTranslatableEntityLocaleAssignerInterface(): void { - $this->shouldImplement(TranslatableEntityLocaleAssignerInterface::class); + $this->assertInstanceOf(TranslatableEntityLocaleAssignerInterface::class, $this->localeAssigner); } - function it_should_assign_current_and_default_locale_to_given_translatable_entity( - TranslationLocaleProviderInterface $translationLocaleProvider, - TranslatableInterface $translatableEntity, - ): void { - $translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US'); + public function testItAssignsCurrentAndDefaultLocaleToGivenTranslatableEntity(): void + { + $translatableEntity = $this->createMock(TranslatableInterface::class); + + $this->translationLocaleProvider + ->method('getDefaultLocaleCode') + ->willReturn('en_US'); + + $translatableEntity->expects($this->once()) + ->method('setCurrentLocale') + ->with('en_US'); - $translatableEntity->setCurrentLocale('en_US')->shouldBeCalled(); - $translatableEntity->setFallbackLocale('en_US')->shouldBeCalled(); + $translatableEntity->expects($this->once()) + ->method('setFallbackLocale') + ->with('en_US'); - $this->assignLocale($translatableEntity); + $this->localeAssigner->assignLocale($translatableEntity); } } From 008d154a5a5b36c40f31cbf40f9243bc55180349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Fri, 18 Oct 2024 08:50:14 +0200 Subject: [PATCH 2/2] Move tests --- .../Provider/ImmutableTranslationLocaleProviderTest.php} | 0 .../Translation/TranslatableEntityLocaleAssignerTest.php} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/Component/{spec/Translation/Provider/ImmutableTranslationLocaleProviderSpec.php => tests/Translation/Provider/ImmutableTranslationLocaleProviderTest.php} (100%) rename src/Component/{spec/Translation/TranslatableEntityLocaleAssignerSpec.php => tests/Translation/TranslatableEntityLocaleAssignerTest.php} (100%) diff --git a/src/Component/spec/Translation/Provider/ImmutableTranslationLocaleProviderSpec.php b/src/Component/tests/Translation/Provider/ImmutableTranslationLocaleProviderTest.php similarity index 100% rename from src/Component/spec/Translation/Provider/ImmutableTranslationLocaleProviderSpec.php rename to src/Component/tests/Translation/Provider/ImmutableTranslationLocaleProviderTest.php diff --git a/src/Component/spec/Translation/TranslatableEntityLocaleAssignerSpec.php b/src/Component/tests/Translation/TranslatableEntityLocaleAssignerTest.php similarity index 100% rename from src/Component/spec/Translation/TranslatableEntityLocaleAssignerSpec.php rename to src/Component/tests/Translation/TranslatableEntityLocaleAssignerTest.php