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
 
8
use Hamcrest\Description;
9
use Hamcrest\Matcher;
10
use Hamcrest\TypeSafeDiagnosingMatcher;
11
 
12
class Every extends TypeSafeDiagnosingMatcher
13
{
14
 
15
    private $_matcher;
16
 
17
    public function __construct(Matcher $matcher)
18
    {
19
        parent::__construct(self::TYPE_ARRAY);
20
 
21
        $this->_matcher = $matcher;
22
    }
23
 
24
    protected function matchesSafelyWithDiagnosticDescription($items, Description $mismatchDescription)
25
    {
26
        foreach ($items as $item) {
27
            if (!$this->_matcher->matches($item)) {
28
                $mismatchDescription->appendText('an item ');
29
                $this->_matcher->describeMismatch($item, $mismatchDescription);
30
 
31
                return false;
32
            }
33
        }
34
 
35
        return true;
36
    }
37
 
38
    public function describeTo(Description $description)
39
    {
40
        $description->appendText('every item is ')->appendDescriptionOf($this->_matcher);
41
    }
42
 
43
    /**
44
     * @param Matcher $itemMatcher
45
     *   A matcher to apply to every element in an array.
46
     *
47
     * @return \Hamcrest\Core\Every
48
     *   Evaluates to TRUE for a collection in which every item matches $itemMatcher
49
     *
50
     * @factory
51
     */
52
    public static function everyItem(Matcher $itemMatcher)
53
    {
54
        return new self($itemMatcher);
55
    }
56
}