youTryToGetSettingWithinSection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Galileo\SettingBundle\Features\Context\Features;
4
5
use Behat\Gherkin\Node\TableNode;
6
use Galileo\SettingBundle\Lib\Application\SettingApplication;
7
use Galileo\SettingBundle\Lib\Infrastructure\Internal\InMemorySettingRepository;
8
use Galileo\SettingBundle\Lib\Model\Setting;
9
10
trait GetSettingContext
11
{
12
    /**
13
     * @var SettingApplication
14
     */
15
    private $settingService;
16
17
    /**
18
     * @var Setting
19
     */
20
    private $responseValue;
21
22
    /**
23
     * @Given /^there are persisted settings in storage system$/
24
     */
25
    public function thereArePersistedSettingsInStorageSystem(TableNode $table)
26
    {
27
        $this->settingService = new SettingApplication(new InMemorySettingRepository($table->getRows()));
28
    }
29
30
    /**
31
     * @When /^you try to get ([a-z_]*)$/
32
     */
33
    public function youTryToGetNotExisting($settingName)
34
    {
35
        $this->responseValue = $this->settingService->get($settingName);
36
    }
37
38
    /**
39
     * @When you try to get :setting within :section
40
     *
41
     * @param string $setting
42
     * @param string $section
43
     */
44
    public function youTryToGetSettingWithinSection($setting, $section)
45
    {
46
        $this->responseValue = $this->settingService->section($section)->get($setting, 'null');
47
    }
48
49
    /**
50
     * @When /^you try to get ([a-z_]*) with default value '(.*)'$/
51
     */
52
    public function youTryToGetNotExistingWithDefaultValue($setting, $value)
53
    {
54
        $this->responseValue = $this->settingService->get($setting, $value);
55
    }
56
57
58
    /**
59
     * @Then /^you should get setting with (.*) value$/
60
     */
61
    public function youShouldGetSettingWithValue($value)
62
    {
63
        if ($value == 'null') {
64
            $value = null;
65
        }
66
67
        assert($value === $this->responseValue, "[$value] compared to [$this->responseValue]");
68
    }
69
}
70