|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Component\Resource\Metadata; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Component\Resource\Metadata\MetadataInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class MetadataSpec extends ObjectBehavior |
|
23
|
|
|
{ |
|
24
|
|
|
function let(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->beConstructedThrough('fromAliasAndConfiguration', [ |
|
27
|
|
|
'app.product', |
|
28
|
|
|
[ |
|
29
|
|
|
'driver' => 'doctrine/orm', |
|
30
|
|
|
'templates' => 'AppBundle:Resource', |
|
31
|
|
|
'classes' => [ |
|
32
|
|
|
'model' => 'AppBundle\Model\Resource', |
|
33
|
|
|
'form' => [ |
|
34
|
|
|
'default' => 'AppBundle\Form\Type\ResourceType', |
|
35
|
|
|
'choice' => 'AppBundle\Form\Type\ResourceChoiceType', |
|
36
|
|
|
'autocomplete' => 'AppBundle\Type\ResourceAutocompleteType', |
|
37
|
|
|
], |
|
38
|
|
|
], |
|
39
|
|
|
], |
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
function it_implements_metadata_interface(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->shouldImplement(MetadataInterface::class); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_has_alias(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->getAlias()->shouldReturn('app.product'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_has_application_name(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->getApplicationName()->shouldReturn('app'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function it_has_resource_name(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->getName()->shouldReturn('product'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
function it_humanizes_simple_names(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->getHumanizedName()->shouldReturn('product'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function it_humanizes_more_complex_names(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->beConstructedThrough('fromAliasAndConfiguration', ['app.product_option', ['driver' => 'doctrine/orm']]); |
|
71
|
|
|
|
|
72
|
|
|
$this->getHumanizedName()->shouldReturn('product option'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
function it_has_plural_resource_name(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$this->getPluralName()->shouldReturn('products'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
function it_has_driver(): void |
|
81
|
|
|
{ |
|
82
|
|
|
$this->getDriver()->shouldReturn('doctrine/orm'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
function it_has_templates_namespace(): void |
|
86
|
|
|
{ |
|
87
|
|
|
$this->getTemplatesNamespace()->shouldReturn('AppBundle:Resource'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function it_has_access_to_specific_config_parameter(): void |
|
91
|
|
|
{ |
|
92
|
|
|
$this->getParameter('driver')->shouldReturn('doctrine/orm'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
function it_checks_if_specific_parameter_exists(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$this->hasParameter('foo')->shouldReturn(false); |
|
98
|
|
|
$this->hasParameter('driver')->shouldReturn(true); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
function it_throws_an_exception_when_parameter_does_not_exist(): void |
|
102
|
|
|
{ |
|
103
|
|
|
$this |
|
104
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
|
105
|
|
|
->during('getParameter', ['foo']) |
|
106
|
|
|
; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
function it_has_access_to_specific_classes(): void |
|
110
|
|
|
{ |
|
111
|
|
|
$this->getClass('model')->shouldReturn('AppBundle\Model\Resource'); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
function it_throws_an_exception_when_class_does_not_exist(): void |
|
115
|
|
|
{ |
|
116
|
|
|
$this |
|
117
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
|
118
|
|
|
->during('getClass', ['foo']) |
|
119
|
|
|
; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
function it_checks_if_specific_class_exists(): void |
|
123
|
|
|
{ |
|
124
|
|
|
$this->hasClass('bar')->shouldReturn(false); |
|
125
|
|
|
$this->hasClass('model')->shouldReturn(true); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
function it_generates_service_id(): void |
|
129
|
|
|
{ |
|
130
|
|
|
$this->getServiceId('factory')->shouldReturn('app.factory.product'); |
|
131
|
|
|
$this->getServiceId('repository')->shouldReturn('app.repository.product'); |
|
132
|
|
|
$this->getServiceId('form.type')->shouldReturn('app.form.type.product'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
function it_generates_permission_code(): void |
|
136
|
|
|
{ |
|
137
|
|
|
$this->getPermissionCode('show')->shouldReturn('app.product.show'); |
|
138
|
|
|
$this->getPermissionCode('create')->shouldReturn('app.product.create'); |
|
139
|
|
|
$this->getPermissionCode('custom')->shouldReturn('app.product.custom'); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|