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\FeatureMatcher;
9
use Hamcrest\Matcher;
10
use Hamcrest\Util;
11
 
12
/**
13
 * Matches if array size satisfies a nested matcher.
14
 */
15
class HasToString extends FeatureMatcher
16
{
17
 
18
    public function __construct(Matcher $toStringMatcher)
19
    {
20
        parent::__construct(
21
            self::TYPE_OBJECT,
22
            null,
23
            $toStringMatcher,
24
            'an object with toString()',
25
            'toString()'
26
        );
27
    }
28
 
29
    public function matchesSafelyWithDiagnosticDescription($actual, Description $mismatchDescription)
30
    {
31
        if (method_exists($actual, 'toString') || method_exists($actual, '__toString')) {
32
            return parent::matchesSafelyWithDiagnosticDescription($actual, $mismatchDescription);
33
        }
34
 
35
        return false;
36
    }
37
 
38
    protected function featureValueOf($actual)
39
    {
40
        if (method_exists($actual, 'toString')) {
41
            return $actual->toString();
42
        }
43
 
44
        return (string) $actual;
45
    }
46
 
47
    /**
48
     * Does array size satisfy a given matcher?
49
     *
50
     * @factory
51
     */
52
    public static function hasToString($matcher)
53
    {
54
        return new self(Util::wrapValueWithIsEqual($matcher));
55
    }
56
}