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