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\Core;
3
 
4
/*
5
 Copyright (c) 2009 hamcrest.org
6
 */
7
use Hamcrest\Description;
8
use Hamcrest\DiagnosingMatcher;
9
use Hamcrest\Util;
10
 
11
/**
12
 * Calculates the logical conjunction of multiple matchers. Evaluation is
13
 * shortcut, so subsequent matchers are not called if an earlier matcher
14
 * returns <code>false</code>.
15
 */
16
class AllOf extends DiagnosingMatcher
17
{
18
 
19
    private $_matchers;
20
 
21
    public function __construct(array $matchers)
22
    {
23
        Util::checkAllAreMatchers($matchers);
24
 
25
        $this->_matchers = $matchers;
26
    }
27
 
28
    public function matchesWithDiagnosticDescription($item, Description $mismatchDescription)
29
    {
30
        /** @var $matcher \Hamcrest\Matcher */
31
        foreach ($this->_matchers as $matcher) {
32
            if (!$matcher->matches($item)) {
33
                $mismatchDescription->appendDescriptionOf($matcher)->appendText(' ');
34
                $matcher->describeMismatch($item, $mismatchDescription);
35
 
36
                return false;
37
            }
38
        }
39
 
40
        return true;
41
    }
42
 
43
    public function describeTo(Description $description)
44
    {
45
        $description->appendList('(', ' and ', ')', $this->_matchers);
46
    }
47
 
48
    /**
49
     * Evaluates to true only if ALL of the passed in matchers evaluate to true.
50
     *
51
     * @factory ...
52
     */
53
    public static function allOf(/* args... */)
54
    {
55
        $args = func_get_args();
56
 
57
        return new self(Util::createMatcherArray($args));
58
    }
59
}