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 IsArrayContainingInAnyOrder 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
        $matching = new MatchingOnce($this->_elementMatchers, $mismatchDescription);
31
 
32
        foreach ($array as $element) {
33
            if (!$matching->matches($element)) {
34
                return false;
35
            }
36
        }
37
 
38
        return $matching->isFinished($array);
39
    }
40
 
41
    public function describeTo(Description $description)
42
    {
43
        $description->appendList('[', ', ', ']', $this->_elementMatchers)
44
                                ->appendText(' in any order')
45
                                ;
46
    }
47
 
48
    /**
49
     * An array with elements that match the given matchers.
50
     *
51
     * @factory containsInAnyOrder ...
52
     */
53
    public static function arrayContainingInAnyOrder(/* args... */)
54
    {
55
        $args = func_get_args();
56
 
57
        return new self(Util::createMatcherArray($args));
58
    }
59
}