Completed
Push — master ( 6371af...afb902 )
by Paweł
30:14 queued 14:41
created

LocaleContext::saveLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Component\Locale\Converter\LocaleNameConverterInterface;
16
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
17
use Sylius\Component\Locale\Model\LocaleInterface;
18
use Sylius\Component\Resource\Factory\FactoryInterface;
19
use Sylius\Component\Resource\Repository\RepositoryInterface;
20
21
/**
22
 * @author Arkadiusz Krakowiak <[email protected]>
23
 */
24
final class LocaleContext implements Context
25
{
26
    /**
27
     * @var SharedStorageInterface
28
     */
29
    private $sharedStorage;
30
31
    /**
32
     * @var FactoryInterface
33
     */
34
    private $localeFactory;
35
36
    /**
37
     * @var RepositoryInterface
38
     */
39
    private $localeRepository;
40
41
    /**
42
     * @param SharedStorageInterface $sharedStorage
43
     * @param FactoryInterface $localeFactory
44
     * @param RepositoryInterface $localeRepository
45
     */
46
    public function __construct(
47
        SharedStorageInterface $sharedStorage,
48
        FactoryInterface $localeFactory,
49
        RepositoryInterface $localeRepository
50
    ) {
51
        $this->localeFactory = $localeFactory;
52
        $this->localeRepository = $localeRepository;
53
        $this->sharedStorage = $sharedStorage;
54
    }
55
56
    /**
57
     * @Given the store has locale :localeCode
58
     * @Given the store is available in :localeCode
59
     */
60
    public function theStoreHasLocale($localeCode)
61
    {
62
        $locale = $this->localeFactory->createNew();
63
        $locale->setCode($localeCode);
64
65
        $this->saveLocale($locale);
66
    }
67
68
    /**
69
     * @Given the store has disabled locale :localeCode
70
     */
71
    public function theStoreHasDisabledLocale($localeCode)
72
    {
73
        $locale = $this->localeFactory->createNew();
74
        $locale->setCode($localeCode);
75
        $locale->disable();
76
77
        $this->saveLocale($locale);
78
    }
79
80
    /**
81
     * @param LocaleInterface $locale
82
     */
83
    private function saveLocale(LocaleInterface $locale)
84
    {
85
        $this->sharedStorage->set('locale', $locale);
86
        $this->localeRepository->add($locale);
87
    }
88
}
89