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
/*
5
 Copyright (c) 2009 hamcrest.org
6
 */
7
use Hamcrest\Description;
8
use Hamcrest\TypeSafeDiagnosingMatcher;
9
use Hamcrest\Util;
10
 
11
/**
12
 * Matches if an array contains a set of items satisfying nested matchers.
13
 */
14
class IsArrayContainingInOrder extends TypeSafeDiagnosingMatcher
15
{
16
 
17
    private $_elementMatchers;
18
 
19
    public function __construct(array $elementMatchers)
20
    {
21
        parent::__construct(self::TYPE_ARRAY);
22
 
23
        Util::checkAllAreMatchers($elementMatchers);
24
 
25
        $this->_elementMatchers = $elementMatchers;
26
    }
27
 
28
    protected function matchesSafelyWithDiagnosticDescription($array, Description $mismatchDescription)
29
    {
30
        $series = new SeriesMatchingOnce($this->_elementMatchers, $mismatchDescription);
31
 
32
        foreach ($array as $element) {
33
            if (!$series->matches($element)) {
34
                return false;
35
            }
36
        }
37
 
38
        return $series->isFinished();
39
    }
40
 
41
    public function describeTo(Description $description)
42
    {
43
        $description->appendList('[', ', ', ']', $this->_elementMatchers);
44
    }
45
 
46
    /**
47
     * An array with elements that match the given matchers in the same order.
48
     *
49
     * @factory contains ...
50
     */
51
    public static function arrayContaining(/* args... */)
52
    {
53
        $args = func_get_args();
54
 
55
        return new self(Util::createMatcherArray($args));
56
    }
57
}