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
 
10
/**
11
 * Tests whether the value is an instance of a class.
12
 */
13
class IsInstanceOf extends DiagnosingMatcher
14
{
15
 
16
    private $_theClass;
17
 
18
    /**
19
     * Creates a new instance of IsInstanceOf
20
     *
21
     * @param string $theClass
22
     *   The predicate evaluates to true for instances of this class
23
     *   or one of its subclasses.
24
     */
25
    public function __construct($theClass)
26
    {
27
        $this->_theClass = $theClass;
28
    }
29
 
30
    protected function matchesWithDiagnosticDescription($item, Description $mismatchDescription)
31
    {
32
        if (!is_object($item)) {
33
            $mismatchDescription->appendText('was ')->appendValue($item);
34
 
35
            return false;
36
        }
37
 
38
        if (!($item instanceof $this->_theClass)) {
39
            $mismatchDescription->appendText('[' . get_class($item) . '] ')
40
                                                    ->appendValue($item);
41
 
42
            return false;
43
        }
44
 
45
        return true;
46
    }
47
 
48
    public function describeTo(Description $description)
49
    {
50
        $description->appendText('an instance of ')
51
                                ->appendText($this->_theClass)
52
                                ;
53
    }
54
 
55
    /**
56
     * Is the value an instance of a particular type?
57
     * This version assumes no relationship between the required type and
58
     * the signature of the method that sets it up, for example in
59
     * <code>assertThat($anObject, anInstanceOf('Thing'));</code>
60
     *
61
     * @factory any
62
     */
63
    public static function anInstanceOf($theClass)
64
    {
65
        return new self($theClass);
66
    }
67
}