|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace spec\Knp\DictionaryBundle\Dictionary; |
|
6
|
|
|
|
|
7
|
|
|
use Knp\DictionaryBundle\Dictionary; |
|
8
|
|
|
use Knp\DictionaryBundle\Dictionary\Collection; |
|
9
|
|
|
use PhpSpec\ObjectBehavior; |
|
10
|
|
|
|
|
11
|
|
|
final class CollectionSpec extends ObjectBehavior |
|
12
|
|
|
{ |
|
13
|
|
|
function let(Dictionary $dictionary, Dictionary $dictionary2) |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
$this->beConstructedWith($dictionary, $dictionary2); |
|
16
|
|
|
$dictionary->getName()->willReturn('foo'); |
|
17
|
|
|
$dictionary2->getName()->willReturn('dictionary'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
function it_is_initializable() |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
$this->shouldHaveType(Collection::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
function it_is_an_array_access() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->shouldHaveType(\ArrayAccess::class); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function it_is_iterable() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->shouldHaveType(\IteratorAggregate::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function it_is_countable() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->shouldHaveType(\Countable::class); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
function it_should_entry_if_it_exists() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->shouldHaveKey('foo'); |
|
43
|
|
|
$this->shouldNotHaveKey('baz'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function it_counts_entries() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->count()->shouldReturn(2); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function it_is_a_list_ob_dictionaries($dictionary, $dictionary2) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->getIterator()->getArrayCopy()->shouldReturn([ |
|
|
|
|
|
|
54
|
|
|
'foo' => $dictionary, |
|
55
|
|
|
'dictionary' => $dictionary2, |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
function its_offsetSet_method_cannot_be_called() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->shouldThrow(\RuntimeException::class)->duringOffsetSet('foo', 'bar'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
function its_offsetUnset_method_cannot_be_called() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->shouldThrow(\RuntimeException::class)->duringOffsetUnset('foo'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.