|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Sylius\Bundle\CoreBundle\Fixture; |
| 4 | + |
| 5 | +use Doctrine\Common\Persistence\ObjectManager; |
| 6 | +use Sylius\Bundle\CoreBundle\Fixture\LocaleFixture; |
| 7 | +use PhpSpec\ObjectBehavior; |
| 8 | +use Prophecy\Argument; |
| 9 | +use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; |
| 10 | +use Sylius\Component\Locale\Model\Locale; |
| 11 | +use Sylius\Component\Locale\Model\LocaleInterface; |
| 12 | +use Sylius\Component\Resource\Factory\FactoryInterface; |
| 13 | + |
| 14 | +class LocaleFixtureSpec extends ObjectBehavior |
| 15 | +{ |
| 16 | + function let(FactoryInterface $localeFactory, ObjectManager $localeManager): void |
| 17 | + { |
| 18 | + $this->beConstructedWith($localeFactory, $localeManager, 'default_LOCALE'); |
| 19 | + } |
| 20 | + |
| 21 | + function it_is_a_fixture(): void |
| 22 | + { |
| 23 | + $this->shouldImplement(FixtureInterface::class); |
| 24 | + } |
| 25 | + |
| 26 | + function it_creates_and_persists_default_locale(FactoryInterface $localeFactory, ObjectManager $localeManager): void |
| 27 | + { |
| 28 | + $localeFactory->createNew()->willReturn(new Locale()); |
| 29 | + |
| 30 | + $localeManager->persist(Argument::that(function (LocaleInterface $locale): bool { |
| 31 | + return $locale->getCode() === 'default_LOCALE'; |
| 32 | + }))->shouldBeCalledOnce(); |
| 33 | + |
| 34 | + $localeManager->flush()->shouldBeCalled(); |
| 35 | + |
| 36 | + $this->load(['locales' => []]); |
| 37 | + } |
| 38 | + |
| 39 | + function it_creates_and_persists_default_locale_and_other_specified_locales(FactoryInterface $localeFactory, ObjectManager $localeManager): void |
| 40 | + { |
| 41 | + $localeFactory->createNew()->willReturn(new Locale(), new Locale()); |
| 42 | + |
| 43 | + $localeManager->persist(Argument::that(function (LocaleInterface $locale): bool { |
| 44 | + return $locale->getCode() === 'default_LOCALE'; |
| 45 | + }))->shouldBeCalledOnce(); |
| 46 | + |
| 47 | + $localeManager->persist(Argument::that(function (LocaleInterface $locale): bool { |
| 48 | + return $locale->getCode() === 'pl_PL'; |
| 49 | + }))->shouldBeCalledOnce(); |
| 50 | + |
| 51 | + $localeManager->flush()->shouldBeCalled(); |
| 52 | + |
| 53 | + $this->load(['locales' => ['pl_PL']]); |
| 54 | + } |
| 55 | + |
| 56 | + function it_deduplicates_passed_locales_and_the_default_one(FactoryInterface $localeFactory, ObjectManager $localeManager): void |
| 57 | + { |
| 58 | + $localeFactory->createNew()->willReturn(new Locale(), new Locale(), new Locale(), new Locale()); |
| 59 | + |
| 60 | + $localeManager->persist(Argument::that(function (LocaleInterface $locale): bool { |
| 61 | + return $locale->getCode() === 'default_LOCALE'; |
| 62 | + }))->shouldBeCalledOnce(); |
| 63 | + |
| 64 | + $localeManager->persist(Argument::that(function (LocaleInterface $locale): bool { |
| 65 | + return $locale->getCode() === 'pl_PL'; |
| 66 | + }))->shouldBeCalledOnce(); |
| 67 | + |
| 68 | + $localeManager->flush()->shouldBeCalled(); |
| 69 | + |
| 70 | + $this->load(['locales' => ['pl_PL', 'default_LOCALE', 'pl_PL']]); |
| 71 | + } |
| 72 | +} |
0 commit comments