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