|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Cornford\Alerter; |
|
4
|
|
|
|
|
5
|
|
|
use Cornford\Alerter\Alert; |
|
6
|
|
|
use Cornford\Alerter\AlertDisplay; |
|
7
|
|
|
use PhpSpec\ObjectBehavior; |
|
8
|
|
|
|
|
9
|
|
|
class AlertSpec extends ObjectBehavior |
|
10
|
|
|
{ |
|
11
|
|
|
function it_is_not_initializable() |
|
12
|
|
|
{ |
|
13
|
|
|
$this->shouldHaveType('Cornford\Alerter\Alert'); |
|
14
|
|
|
$this->shouldThrow('\PhpSpec\Exception\Example\ErrorException'); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
function it_can_be_created() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->beConstructedThrough('create', [null, null]); |
|
20
|
|
|
$this->shouldHaveType('Cornford\Alerter\Alert'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
function it_throws_exception_when_created_without_type() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->beConstructedThrough('create', [Alert::TYPE_NONE, 'None']); |
|
26
|
|
|
$this->shouldThrow('Cornford\Alerter\Exceptions\AlertTypeException')->during('create', [null, 'Message']); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
function it_throws_exception_when_created_without_content() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->beConstructedThrough('create', [Alert::TYPE_NONE, 'None']); |
|
32
|
|
|
$this->shouldThrow('Cornford\Alerter\Exceptions\AlertContentException')->during('create', [Alert::TYPE_ERROR, null]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function it_can_return_type() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->beConstructedThrough('create', [Alert::TYPE_INFO, 'Info message']); |
|
38
|
|
|
$this->getType()->shouldEqual(Alert::TYPE_INFO); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_can_return_type_variable() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->beConstructedThrough('create', [Alert::TYPE_INFO, 'Info message']); |
|
44
|
|
|
$this->type->shouldEqual(Alert::TYPE_INFO); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
function it_can_return_content() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->beConstructedThrough('create', [Alert::TYPE_ERROR, 'Error message']); |
|
50
|
|
|
$this->getContent()->shouldEqual('Error message'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_can_return_content_variable() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->beConstructedThrough('create', [Alert::TYPE_ERROR, 'Error message']); |
|
56
|
|
|
$this->content->shouldEqual('Error message'); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
function it_throws_exception_when_requesting_undefined_variable() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->beConstructedThrough('create', [Alert::TYPE_WARNING, 'Waring message']); |
|
62
|
|
|
$this->shouldThrow('\Cornford\Alerter\Exceptions\AlertVariableException')->during('__get', ['undefined']); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
function it_can_be_created_as_a_type_error() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->beConstructedThrough('error', ['Error message']); |
|
68
|
|
|
$this->content->shouldEqual('Error message'); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
function it_can_be_created_as_a_type_info() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->beConstructedThrough('info', ['Info message']); |
|
74
|
|
|
$this->content->shouldEqual('Info message'); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
function it_can_be_created_as_a_type_warning() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->beConstructedThrough('warning', ['Warning message']); |
|
80
|
|
|
$this->content->shouldEqual('Warning message'); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
function it_can_be_created_as_a_type_success() |
|
84
|
|
|
{ |
|
85
|
|
|
$this->beConstructedThrough('success', ['Success message']); |
|
86
|
|
|
$this->content->shouldEqual('Success message'); |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
function it_can_be_created_as_a_type_none() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->beConstructedThrough('none', ['Message']); |
|
92
|
|
|
$this->content->shouldEqual('Message'); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
function it_throws_exception_when_displaying_with_invalid_view_path() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->beConstructedThrough('success', ['Success message']); |
|
98
|
|
|
$this->useViewPath('none directory'); |
|
99
|
|
|
$this->shouldThrow('\Cornford\Alerter\Exceptions\AlertDisplayViewPathException')->during('display', []); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
function it_throws_exception_when_displaying_with_invalid_view() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->beConstructedThrough('success', ['Success message']); |
|
105
|
|
|
$this->useView('none view'); |
|
106
|
|
|
$this->shouldThrow('\Cornford\Alerter\Exceptions\AlertDisplayViewException')->during('display', []); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
function it_can_be_displayed() |
|
110
|
|
|
{ |
|
111
|
|
|
$this->beConstructedThrough('success', ['Success message']); |
|
112
|
|
|
$this->display()->shouldEqual('<p class="alert alert-success">Success message</p>'); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
function it_can_be_displayed_with_bootstrap_view() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->beConstructedThrough('info', ['Info message']); |
|
118
|
|
|
$this->useView(AlertDisplay::VIEW_BOOTSTRAP); |
|
119
|
|
|
$this->display()->shouldEqual('<div class="alert alert-info">Info message</div>'); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.