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