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

SyliusTranslationResourceSpec   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 21
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 139
rs 10

21 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 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_options_by_default() 0 4 1
A its_options_are_mutable() 0 6 1
A it_has_no_translatable_fields_by_default() 0 4 1
A its_translatable_fields_can_be_set() 0 6 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 30 and the first side effect is on line 22.

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