Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
namespace Hamcrest;
3
 
4
use PHPUnit\Framework\TestCase;
5
 
6
class SampleSelfDescriber implements \Hamcrest\SelfDescribing
7
{
8
    private $_text;
9
 
10
    public function __construct($text)
11
    {
12
        $this->_text = $text;
13
    }
14
 
15
    public function describeTo(\Hamcrest\Description $description)
16
    {
17
        $description->appendText($this->_text);
18
    }
19
}
20
 
21
class StringDescriptionTest extends TestCase
22
{
23
 
24
    private $_description;
25
 
26
    protected function setUp()
27
    {
28
        $this->_description = new \Hamcrest\StringDescription();
29
    }
30
 
31
    public function testAppendTextAppendsTextInformation()
32
    {
33
        $this->_description->appendText('foo')->appendText('bar');
34
        $this->assertEquals('foobar', (string) $this->_description);
35
    }
36
 
37
    public function testAppendValueCanAppendTextTypes()
38
    {
39
        $this->_description->appendValue('foo');
40
        $this->assertEquals('"foo"', (string) $this->_description);
41
    }
42
 
43
    public function testSpecialCharactersAreEscapedForStringTypes()
44
    {
45
        $this->_description->appendValue("foo\\bar\"zip\r\n");
46
        $this->assertEquals('"foo\\bar\\"zip\r\n"', (string) $this->_description);
47
    }
48
 
49
    public function testIntegerValuesCanBeAppended()
50
    {
51
        $this->_description->appendValue(42);
52
        $this->assertEquals('<42>', (string) $this->_description);
53
    }
54
 
55
    public function testFloatValuesCanBeAppended()
56
    {
57
        $this->_description->appendValue(42.78);
58
        $this->assertEquals('<42.78F>', (string) $this->_description);
59
    }
60
 
61
    public function testNullValuesCanBeAppended()
62
    {
63
        $this->_description->appendValue(null);
64
        $this->assertEquals('null', (string) $this->_description);
65
    }
66
 
67
    public function testArraysCanBeAppended()
68
    {
69
        $this->_description->appendValue(array('foo', 42.78));
70
        $this->assertEquals('["foo", <42.78F>]', (string) $this->_description);
71
    }
72
 
73
    public function testObjectsCanBeAppended()
74
    {
75
        $this->_description->appendValue(new \stdClass());
76
        $this->assertEquals('<stdClass>', (string) $this->_description);
77
    }
78
 
79
    public function testBooleanValuesCanBeAppended()
80
    {
81
        $this->_description->appendValue(false);
82
        $this->assertEquals('<false>', (string) $this->_description);
83
    }
84
 
85
    public function testListsOfvaluesCanBeAppended()
86
    {
87
        $this->_description->appendValue(array('foo', 42.78));
88
        $this->assertEquals('["foo", <42.78F>]', (string) $this->_description);
89
    }
90
 
91
    public function testIterableOfvaluesCanBeAppended()
92
    {
93
        $items = new \ArrayObject(array('foo', 42.78));
94
        $this->_description->appendValue($items);
95
        $this->assertEquals('["foo", <42.78F>]', (string) $this->_description);
96
    }
97
 
98
    public function testIteratorOfvaluesCanBeAppended()
99
    {
100
        $items = new \ArrayObject(array('foo', 42.78));
101
        $this->_description->appendValue($items->getIterator());
102
        $this->assertEquals('["foo", <42.78F>]', (string) $this->_description);
103
    }
104
 
105
    public function testListsOfvaluesCanBeAppendedManually()
106
    {
107
        $this->_description->appendValueList('@start@', '@sep@ ', '@end@', array('foo', 42.78));
108
        $this->assertEquals('@start@"foo"@sep@ <42.78F>@end@', (string) $this->_description);
109
    }
110
 
111
    public function testIterableOfvaluesCanBeAppendedManually()
112
    {
113
        $items = new \ArrayObject(array('foo', 42.78));
114
        $this->_description->appendValueList('@start@', '@sep@ ', '@end@', $items);
115
        $this->assertEquals('@start@"foo"@sep@ <42.78F>@end@', (string) $this->_description);
116
    }
117
 
118
    public function testIteratorOfvaluesCanBeAppendedManually()
119
    {
120
        $items = new \ArrayObject(array('foo', 42.78));
121
        $this->_description->appendValueList('@start@', '@sep@ ', '@end@', $items->getIterator());
122
        $this->assertEquals('@start@"foo"@sep@ <42.78F>@end@', (string) $this->_description);
123
    }
124
 
125
    public function testSelfDescribingObjectsCanBeAppended()
126
    {
127
        $this->_description
128
            ->appendDescriptionOf(new \Hamcrest\SampleSelfDescriber('foo'))
129
            ->appendDescriptionOf(new \Hamcrest\SampleSelfDescriber('bar'))
130
            ;
131
        $this->assertEquals('foobar', (string) $this->_description);
132
    }
133
 
134
    public function testSelfDescribingObjectsCanBeAppendedAsLists()
135
    {
136
        $this->_description->appendList('@start@', '@sep@ ', '@end@', array(
137
            new \Hamcrest\SampleSelfDescriber('foo'),
138
            new \Hamcrest\SampleSelfDescriber('bar')
139
        ));
140
        $this->assertEquals('@start@foo@sep@ bar@end@', (string) $this->_description);
141
    }
142
 
143
    public function testSelfDescribingObjectsCanBeAppendedAsIteratedLists()
144
    {
145
        $items = new \ArrayObject(array(
146
            new \Hamcrest\SampleSelfDescriber('foo'),
147
            new \Hamcrest\SampleSelfDescriber('bar')
148
        ));
149
        $this->_description->appendList('@start@', '@sep@ ', '@end@', $items);
150
        $this->assertEquals('@start@foo@sep@ bar@end@', (string) $this->_description);
151
    }
152
 
153
    public function testSelfDescribingObjectsCanBeAppendedAsIterators()
154
    {
155
        $items = new \ArrayObject(array(
156
            new \Hamcrest\SampleSelfDescriber('foo'),
157
            new \Hamcrest\SampleSelfDescriber('bar')
158
        ));
159
        $this->_description->appendList('@start@', '@sep@ ', '@end@', $items->getIterator());
160
        $this->assertEquals('@start@foo@sep@ bar@end@', (string) $this->_description);
161
    }
162
}