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 spec\Sylius\Bundle\ResourceBundle\Event; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class ResourceControllerEventSpec extends ObjectBehavior |
22
|
|
|
{ |
23
|
|
|
function let() |
24
|
|
|
{ |
25
|
|
|
$this->beConstructedWith('message'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_is_initializable() |
29
|
|
|
{ |
30
|
|
|
$this->shouldHaveType(ResourceControllerEvent::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_stops_event_propagation() |
34
|
|
|
{ |
35
|
|
|
$this->stop('message', ResourceControllerEvent::TYPE_SUCCESS, ['parameter']); |
36
|
|
|
$this->getMessageType()->shouldReturn(ResourceControllerEvent::TYPE_SUCCESS); |
37
|
|
|
$this->getMessageParameters()->shouldReturn(['parameter']); |
38
|
|
|
$this->getMessage()->shouldReturn('message'); |
39
|
|
|
$this->isPropagationStopped()->shouldReturn(true); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_check_if_an_error_has_been_detected() |
43
|
|
|
{ |
44
|
|
|
$this->isStopped()->shouldReturn(false); |
45
|
|
|
$this->stop('message'); |
46
|
|
|
$this->isStopped()->shouldReturn(true); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_has_no_message_type_by_default() |
50
|
|
|
{ |
51
|
|
|
$this->getMessageType()->shouldReturn(''); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function its_message_type_is_mutable() |
55
|
|
|
{ |
56
|
|
|
$this->setMessageType(ResourceControllerEvent::TYPE_SUCCESS); |
57
|
|
|
$this->getMessageType()->shouldReturn(ResourceControllerEvent::TYPE_SUCCESS); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function it_has_not_message_by_default() |
61
|
|
|
{ |
62
|
|
|
$this->getMessage()->shouldReturn(''); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function its_message_is_mutable() |
66
|
|
|
{ |
67
|
|
|
$this->setMessage('message'); |
68
|
|
|
$this->getMessage()->shouldReturn('message'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function it_has_empty_message_parameters_by_default() |
72
|
|
|
{ |
73
|
|
|
$this->getMessageParameters()->shouldReturn([]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
function its_message_parameter_is_mutable() |
77
|
|
|
{ |
78
|
|
|
$this->setMessageParameters(['parameters']); |
79
|
|
|
$this->getMessageParameters()->shouldReturn(['parameters']); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function it_has_response() |
83
|
|
|
{ |
84
|
|
|
$response = new Response(); |
85
|
|
|
|
86
|
|
|
$this->setResponse($response); |
87
|
|
|
|
88
|
|
|
$this->getResponse()->shouldReturn($response); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
function it_has_response_if_it_was_set_before() |
92
|
|
|
{ |
93
|
|
|
$response = new Response(); |
94
|
|
|
$this->setResponse($response); |
95
|
|
|
|
96
|
|
|
$this->hasResponse()->shouldReturn(true); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
function it_has_not_response_if_it_was_not_set_before() |
100
|
|
|
{ |
101
|
|
|
$this->hasResponse()->shouldReturn(false); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|