Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffa464e

Browse files
committed
Provide failing test scenario for duplicated locales
1 parent 1721dd6 commit ffa464e

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

src/Sylius/Bundle/CoreBundle/Tests/Fixture/LocaleFixtureTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function locales_are_not_required(): void
3636
*/
3737
public function locales_can_be_set(): void
3838
{
39-
$this->assertConfigurationIsValid([['locales' => ['en_US' => true, 'pl_PL' => false, 'es_ES' => true]]], 'locales');
39+
$this->assertConfigurationIsValid([['locales' => ['en_US', 'pl_PL', 'es_ES']]], 'locales');
4040
}
4141

4242
/**
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)