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\Arrays;
3
 
4
use Hamcrest\AbstractMatcherTest;
5
 
6
class IsArrayTest extends AbstractMatcherTest
7
{
8
 
9
    protected function createMatcher()
10
    {
11
        return IsArray::anArray(array(equalTo('irrelevant')));
12
    }
13
 
14
    public function testMatchesAnArrayThatMatchesAllTheElementMatchers()
15
    {
16
        $this->assertMatches(
17
            anArray(array(equalTo('a'), equalTo('b'), equalTo('c'))),
18
            array('a', 'b', 'c'),
19
            'should match array with matching elements'
20
        );
21
    }
22
 
23
    public function testDoesNotMatchAnArrayWhenElementsDoNotMatch()
24
    {
25
        $this->assertDoesNotMatch(
26
            anArray(array(equalTo('a'), equalTo('b'))),
27
            array('b', 'c'),
28
            'should not match array with different elements'
29
        );
30
    }
31
 
32
    public function testDoesNotMatchAnArrayOfDifferentSize()
33
    {
34
        $this->assertDoesNotMatch(
35
            anArray(array(equalTo('a'), equalTo('b'))),
36
            array('a', 'b', 'c'),
37
            'should not match larger array'
38
        );
39
        $this->assertDoesNotMatch(
40
            anArray(array(equalTo('a'), equalTo('b'))),
41
            array('a'),
42
            'should not match smaller array'
43
        );
44
    }
45
 
46
    public function testDoesNotMatchNull()
47
    {
48
        $this->assertDoesNotMatch(
49
            anArray(array(equalTo('a'))),
50
            null,
51
            'should not match null'
52
        );
53
    }
54
 
55
    public function testHasAReadableDescription()
56
    {
57
        $this->assertDescription(
58
            '["a", "b"]',
59
            anArray(array(equalTo('a'), equalTo('b')))
60
        );
61
    }
62
 
63
    public function testHasAReadableMismatchDescriptionWhenKeysDontMatch()
64
    {
65
        $this->assertMismatchDescription(
66
            'array keys were [<1>, <2>]',
67
            anArray(array(equalTo('a'), equalTo('b'))),
68
            array(1 => 'a', 2 => 'b')
69
        );
70
    }
71
 
72
    public function testSupportsMatchesAssociativeArrays()
73
    {
74
        $this->assertMatches(
75
            anArray(array('x'=>equalTo('a'), 'y'=>equalTo('b'), 'z'=>equalTo('c'))),
76
            array('x'=>'a', 'y'=>'b', 'z'=>'c'),
77
            'should match associative array with matching elements'
78
        );
79
    }
80
 
81
    public function testDoesNotMatchAnAssociativeArrayWhenKeysDoNotMatch()
82
    {
83
        $this->assertDoesNotMatch(
84
            anArray(array('x'=>equalTo('a'), 'y'=>equalTo('b'))),
85
            array('x'=>'b', 'z'=>'c'),
86
            'should not match array with different keys'
87
        );
88
    }
89
}