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;
3
 
4
use PHPUnit\Framework\TestCase;
5
 
6
class UnknownType {
7
}
8
 
9
abstract class AbstractMatcherTest extends TestCase
10
{
11
 
12
    const ARGUMENT_IGNORED = "ignored";
13
    const ANY_NON_NULL_ARGUMENT = "notnull";
14
 
15
    abstract protected function createMatcher();
16
 
17
    public function assertMatches(\Hamcrest\Matcher $matcher, $arg, $message)
18
    {
19
        $this->assertTrue($matcher->matches($arg), $message);
20
    }
21
 
22
    public function assertDoesNotMatch(\Hamcrest\Matcher $matcher, $arg, $message)
23
    {
24
        $this->assertFalse($matcher->matches($arg), $message);
25
    }
26
 
27
    public function assertDescription($expected, \Hamcrest\Matcher $matcher)
28
    {
29
        $description = new \Hamcrest\StringDescription();
30
        $description->appendDescriptionOf($matcher);
31
        $this->assertEquals($expected, (string) $description, 'Expected description');
32
    }
33
 
34
    public function assertMismatchDescription($expected, \Hamcrest\Matcher $matcher, $arg)
35
    {
36
        $description = new \Hamcrest\StringDescription();
37
        $this->assertFalse(
38
            $matcher->matches($arg),
39
            'Precondtion: Matcher should not match item'
40
        );
41
        $matcher->describeMismatch($arg, $description);
42
        $this->assertEquals(
43
            $expected,
44
            (string) $description,
45
            'Expected mismatch description'
46
        );
47
    }
48
 
49
    public function testIsNullSafe()
50
    {
51
        //Should not generate any notices
52
        $this->createMatcher()->matches(null);
53
        $this->createMatcher()->describeMismatch(
54
            null,
55
            new \Hamcrest\NullDescription()
56
        );
57
    }
58
 
59
    public function testCopesWithUnknownTypes()
60
    {
61
        //Should not generate any notices
62
        $this->createMatcher()->matches(new UnknownType());
63
        $this->createMatcher()->describeMismatch(
64
            new UnknownType(),
65
            new NullDescription()
66
        );
67
    }
68
}