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\BaseMatcher;
9
use Hamcrest\Description;
10
use Hamcrest\Matcher;
11
 
12
class CombinableMatcher extends BaseMatcher
13
{
14
 
15
    private $_matcher;
16
 
17
    public function __construct(Matcher $matcher)
18
    {
19
        $this->_matcher = $matcher;
20
    }
21
 
22
    public function matches($item)
23
    {
24
        return $this->_matcher->matches($item);
25
    }
26
 
27
    public function describeTo(Description $description)
28
    {
29
        $description->appendDescriptionOf($this->_matcher);
30
    }
31
 
32
    /** Diversion from Hamcrest-Java... Logical "and" not permitted */
33
    public function andAlso(Matcher $other)
34
    {
35
        return new self(new AllOf($this->_templatedListWith($other)));
36
    }
37
 
38
    /** Diversion from Hamcrest-Java... Logical "or" not permitted */
39
    public function orElse(Matcher $other)
40
    {
41
        return new self(new AnyOf($this->_templatedListWith($other)));
42
    }
43
 
44
    /**
45
     * This is useful for fluently combining matchers that must both pass.
46
     * For example:
47
     * <pre>
48
     *   assertThat($string, both(containsString("a"))->andAlso(containsString("b")));
49
     * </pre>
50
     *
51
     * @factory
52
     */
53
    public static function both(Matcher $matcher)
54
    {
55
        return new self($matcher);
56
    }
57
 
58
    /**
59
     * This is useful for fluently combining matchers where either may pass,
60
     * for example:
61
     * <pre>
62
     *   assertThat($string, either(containsString("a"))->orElse(containsString("b")));
63
     * </pre>
64
     *
65
     * @factory
66
     */
67
    public static function either(Matcher $matcher)
68
    {
69
        return new self($matcher);
70
    }
71
 
72
    // -- Private Methods
73
 
74
    private function _templatedListWith(Matcher $other)
75
    {
76
        return array($this->_matcher, $other);
77
    }
78
}