Completed
Branch resource-configuration-builder (c854d7)
by Kamil
13:53
created

SyliusResourceSpec   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 22
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 148
rs 10

22 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_correctly_assigns_name_passed_to_the_constructor() 0 6 1
A it_correctly_assigns_model_passed_to_the_constructor() 0 6 1
A it_correctly_assigns_interface_passed_to_the_constructor() 0 6 1
A it_has_no_factory_by_default() 0 4 1
A it_sets_resource_factory_as_used_if_using_default() 0 6 1
A it_uses_given_factory() 0 6 1
A it_has_no_controller_by_default() 0 4 1
A it_sets_resource_controller_as_used_if_using_default() 0 6 1
A it_uses_given_controller() 0 6 1
A it_has_no_repository_by_default() 0 4 1
A it_does_not_set_anything_as_used_if_using_default() 0 6 1
A it_uses_given_repository() 0 6 1
A it_adds_form_without_validation_groups() 0 7 1
A it_adds_form_with_validation_groups() 0 7 1
A it_adds_default_form_if_null_name_is_provided() 0 7 1
A it_adds_default_form_if_empty_name_is_provided() 0 7 1
A it_has_no_translation_resource_by_default() 0 4 1
A it_has_no_options_by_default() 0 4 1
A its_options_are_mutable() 0 6 1
A its_translation_resource_can_be_set() 0 8 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 23.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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 spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
17
use Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration\SyliusResource;
18
use spec\Sylius\Bundle\ResourceBundle\Fixture\Model\Foo;
19
use spec\Sylius\Bundle\ResourceBundle\Fixture\Model\FooInterface;
20
use Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration\SyliusTranslationResource;
21
use Sylius\Component\Resource\Factory\Factory;
22
23
require_once __DIR__ . '/../../Fixture/Model/FooInterface.php';
24
require_once __DIR__ . '/../../Fixture/Model/Foo.php';
25
26
/**
27
 * @mixin SyliusResource
28
 *
29
 * @author Kamil Kokot <[email protected]>
30
 */
31
class SyliusResourceSpec extends ObjectBehavior
32
{
33
    function let()
34
    {
35
        $this->beConstructedWith('foo', Foo::class, FooInterface::class);
36
    }
37
38
    function it_is_initializable()
39
    {
40
        $this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration\SyliusResource');
41
    }
42
43
    function it_correctly_assigns_name_passed_to_the_constructor()
44
    {
45
        $this->beConstructedWith('foo', Foo::class);
46
47
        $this->getName()->shouldReturn('foo');
48
    }
49
50
    function it_correctly_assigns_model_passed_to_the_constructor()
51
    {
52
        $this->beConstructedWith('foo', Foo::class);
53
54
        $this->getModelClass()->shouldReturn(Foo::class);
55
    }
56
57
    function it_correctly_assigns_interface_passed_to_the_constructor()
58
    {
59
        $this->beConstructedWith('foo', Foo::class, FooInterface::class);
60
61
        $this->getInterfaceClass()->shouldReturn(FooInterface::class);
62
    }
63
64
    function it_has_no_factory_by_default()
65
    {
66
        $this->getFactoryClass()->shouldReturn(null);
67
    }
68
    
69
    function it_sets_resource_factory_as_used_if_using_default()
70
    {
71
        $this->useDefaultFactory();
72
        
73
        $this->getFactoryClass()->shouldReturn(Factory::class);
74
    }
75
76
    function it_uses_given_factory()
77
    {
78
        $this->useFactory(\stdClass::class);
79
80
        $this->getFactoryClass()->shouldReturn(\stdClass::class);
81
    }
82
83
    function it_has_no_controller_by_default()
84
    {
85
        $this->getControllerClass()->shouldReturn(null);
86
    }
87
88
    function it_sets_resource_controller_as_used_if_using_default()
89
    {
90
        $this->useDefaultController();
91
92
        $this->getControllerClass()->shouldReturn(ResourceController::class);
93
    }
94
95
    function it_uses_given_controller()
96
    {
97
        $this->useController(\stdClass::class);
98
99
        $this->getControllerClass()->shouldReturn(\stdClass::class);
100
    }
101
102
    function it_has_no_repository_by_default()
103
    {
104
        $this->getRepositoryClass()->shouldReturn(null);
105
    }
106
107
    function it_does_not_set_anything_as_used_if_using_default()
108
    {
109
        $this->useDefaultRepository();
110
111
        $this->getRepositoryClass()->shouldReturn(null);
112
    }
113
114
    function it_uses_given_repository()
115
    {
116
        $this->useRepository(\stdClass::class);
117
118
        $this->getRepositoryClass()->shouldReturn(\stdClass::class);
119
    }
120
121
    function it_adds_form_without_validation_groups()
122
    {
123
        $this->addForm('name', \stdClass::class);
124
125
        $this->getFormsClasses()->shouldReturn(['name' => \stdClass::class]);
126
        $this->getValidationGroups()->shouldReturn([]);
127
    }
128
129
    function it_adds_form_with_validation_groups()
130
    {
131
        $this->addForm('name', \stdClass::class, ['validation group']);
132
133
        $this->getFormsClasses()->shouldReturn(['name' => \stdClass::class]);
134
        $this->getValidationGroups()->shouldReturn(['name' => ['validation group']]);
135
    }
136
137
    function it_adds_default_form_if_null_name_is_provided()
138
    {
139
        $this->addForm(null, \stdClass::class);
140
141
        $this->getFormsClasses()->shouldReturn(['default' => \stdClass::class]);
142
        $this->getValidationGroups()->shouldReturn([]);
143
    }
144
145
    function it_adds_default_form_if_empty_name_is_provided()
146
    {
147
        $this->addForm('', \stdClass::class);
148
149
        $this->getFormsClasses()->shouldReturn(['default' => \stdClass::class]);
150
        $this->getValidationGroups()->shouldReturn([]);
151
    }
152
153
    function it_has_no_translation_resource_by_default()
154
    {
155
        $this->getTranslationResource()->shouldReturn(null);
156
    }
157
158
    function it_has_no_options_by_default()
159
    {
160
        $this->getOptions()->shouldReturn([]);
161
    }
162
163
    function its_options_are_mutable()
164
    {
165
        $this->setOptions(['option' => 'value']);
166
167
        $this->getOptions()->shouldReturn(['option' => 'value']);
168
    }
169
170
    function its_translation_resource_can_be_set()
171
    {
172
        $translationResource = new SyliusTranslationResource(Foo::class);
173
174
        $this->useTranslationResource($translationResource);
175
176
        $this->getTranslationResource()->shouldReturn($translationResource);
177
    }
178
}
179