Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace spec\Prophecy\Argument\Token;
|
Chris@0
|
4
|
Chris@0
|
5 use PhpSpec\ObjectBehavior;
|
Chris@0
|
6 use Prophecy\Argument;
|
Chris@0
|
7
|
Chris@0
|
8 class IdenticalValueTokenSpec extends ObjectBehavior
|
Chris@0
|
9 {
|
Chris@0
|
10 function let()
|
Chris@0
|
11 {
|
Chris@0
|
12 $this->beConstructedWith(42);
|
Chris@0
|
13 }
|
Chris@0
|
14
|
Chris@0
|
15 function it_is_initializable()
|
Chris@0
|
16 {
|
Chris@0
|
17 $this->shouldHaveType('Prophecy\Argument\Token\IdenticalValueToken');
|
Chris@0
|
18 }
|
Chris@0
|
19
|
Chris@0
|
20 function it_scores_11_if_string_value_is_identical_to_argument()
|
Chris@0
|
21 {
|
Chris@0
|
22 $this->beConstructedWith('foo');
|
Chris@0
|
23 $this->scoreArgument('foo')->shouldReturn(11);
|
Chris@0
|
24 }
|
Chris@0
|
25
|
Chris@0
|
26 function it_scores_11_if_boolean_value_is_identical_to_argument()
|
Chris@0
|
27 {
|
Chris@0
|
28 $this->beConstructedWith(false);
|
Chris@0
|
29 $this->scoreArgument(false)->shouldReturn(11);
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 function it_scores_11_if_integer_value_is_identical_to_argument()
|
Chris@0
|
33 {
|
Chris@0
|
34 $this->beConstructedWith(31);
|
Chris@0
|
35 $this->scoreArgument(31)->shouldReturn(11);
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 function it_scores_11_if_float_value_is_identical_to_argument()
|
Chris@0
|
39 {
|
Chris@0
|
40 $this->beConstructedWith(31.12);
|
Chris@0
|
41 $this->scoreArgument(31.12)->shouldReturn(11);
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 function it_scores_11_if_array_value_is_identical_to_argument()
|
Chris@0
|
45 {
|
Chris@0
|
46 $this->beConstructedWith(array('foo' => 'bar'));
|
Chris@0
|
47 $this->scoreArgument(array('foo' => 'bar'))->shouldReturn(11);
|
Chris@0
|
48 }
|
Chris@0
|
49
|
Chris@0
|
50 function it_scores_11_if_object_value_is_identical_to_argument()
|
Chris@0
|
51 {
|
Chris@0
|
52 $object = new \stdClass();
|
Chris@0
|
53
|
Chris@0
|
54 $this->beConstructedWith($object);
|
Chris@0
|
55 $this->scoreArgument($object)->shouldReturn(11);
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 function it_scores_false_if_value_is_not_identical_to_argument()
|
Chris@0
|
59 {
|
Chris@0
|
60 $this->beConstructedWith(new \stdClass());
|
Chris@0
|
61 $this->scoreArgument('foo')->shouldReturn(false);
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 function it_scores_false_if_object_value_is_not_the_same_instance_than_argument()
|
Chris@0
|
65 {
|
Chris@0
|
66 $this->beConstructedWith(new \stdClass());
|
Chris@0
|
67 $this->scoreArgument(new \stdClass())->shouldReturn(false);
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 function it_scores_false_if_integer_value_is_not_identical_to_boolean_argument()
|
Chris@0
|
71 {
|
Chris@0
|
72 $this->beConstructedWith(1);
|
Chris@0
|
73 $this->scoreArgument(true)->shouldReturn(false);
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 function it_is_not_last()
|
Chris@0
|
77 {
|
Chris@0
|
78 $this->shouldNotBeLast();
|
Chris@0
|
79 }
|
Chris@0
|
80
|
Chris@0
|
81 function it_generates_proper_string_representation_for_integer()
|
Chris@0
|
82 {
|
Chris@0
|
83 $this->beConstructedWith(42);
|
Chris@0
|
84 $this->__toString()->shouldReturn('identical(42)');
|
Chris@0
|
85 }
|
Chris@0
|
86
|
Chris@0
|
87 function it_generates_proper_string_representation_for_string()
|
Chris@0
|
88 {
|
Chris@0
|
89 $this->beConstructedWith('some string');
|
Chris@0
|
90 $this->__toString()->shouldReturn('identical("some string")');
|
Chris@0
|
91 }
|
Chris@0
|
92
|
Chris@0
|
93 function it_generates_single_line_representation_for_multiline_string()
|
Chris@0
|
94 {
|
Chris@0
|
95 $this->beConstructedWith("some\nstring");
|
Chris@0
|
96 $this->__toString()->shouldReturn('identical("some\\nstring")');
|
Chris@0
|
97 }
|
Chris@0
|
98
|
Chris@0
|
99 function it_generates_proper_string_representation_for_double()
|
Chris@0
|
100 {
|
Chris@0
|
101 $this->beConstructedWith(42.3);
|
Chris@0
|
102 $this->__toString()->shouldReturn('identical(42.3)');
|
Chris@0
|
103 }
|
Chris@0
|
104
|
Chris@0
|
105 function it_generates_proper_string_representation_for_boolean_true()
|
Chris@0
|
106 {
|
Chris@0
|
107 $this->beConstructedWith(true);
|
Chris@0
|
108 $this->__toString()->shouldReturn('identical(true)');
|
Chris@0
|
109 }
|
Chris@0
|
110
|
Chris@0
|
111 function it_generates_proper_string_representation_for_boolean_false()
|
Chris@0
|
112 {
|
Chris@0
|
113 $this->beConstructedWith(false);
|
Chris@0
|
114 $this->__toString()->shouldReturn('identical(false)');
|
Chris@0
|
115 }
|
Chris@0
|
116
|
Chris@0
|
117 function it_generates_proper_string_representation_for_null()
|
Chris@0
|
118 {
|
Chris@0
|
119 $this->beConstructedWith(null);
|
Chris@0
|
120 $this->__toString()->shouldReturn('identical(null)');
|
Chris@0
|
121 }
|
Chris@0
|
122
|
Chris@0
|
123 function it_generates_proper_string_representation_for_empty_array()
|
Chris@0
|
124 {
|
Chris@0
|
125 $this->beConstructedWith(array());
|
Chris@0
|
126 $this->__toString()->shouldReturn('identical([])');
|
Chris@0
|
127 }
|
Chris@0
|
128
|
Chris@0
|
129 function it_generates_proper_string_representation_for_array()
|
Chris@0
|
130 {
|
Chris@0
|
131 $this->beConstructedWith(array('zet', 42));
|
Chris@0
|
132 $this->__toString()->shouldReturn('identical(["zet", 42])');
|
Chris@0
|
133 }
|
Chris@0
|
134
|
Chris@0
|
135 function it_generates_proper_string_representation_for_resource()
|
Chris@0
|
136 {
|
Chris@0
|
137 $resource = fopen(__FILE__, 'r');
|
Chris@0
|
138 $this->beConstructedWith($resource);
|
Chris@0
|
139 $this->__toString()->shouldReturn('identical(stream:'.$resource.')');
|
Chris@0
|
140 }
|
Chris@0
|
141
|
Chris@0
|
142 function it_generates_proper_string_representation_for_object($object)
|
Chris@0
|
143 {
|
Chris@0
|
144 $objHash = sprintf('%s:%s',
|
Chris@0
|
145 get_class($object->getWrappedObject()),
|
Chris@0
|
146 spl_object_hash($object->getWrappedObject())
|
Chris@0
|
147 );
|
Chris@0
|
148
|
Chris@0
|
149 $this->beConstructedWith($object);
|
Chris@0
|
150 $this->__toString()->shouldReturn("identical($objHash Object (\n 'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)\n))");
|
Chris@0
|
151 }
|
Chris@0
|
152 }
|