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 UtilTest extends TestCase
7
{
8
 
9
    public function testWrapValueWithIsEqualLeavesMatchersUntouched()
10
    {
11
        $matcher = new \Hamcrest\Text\MatchesPattern('/fo+/');
12
        $newMatcher = \Hamcrest\Util::wrapValueWithIsEqual($matcher);
13
        $this->assertSame($matcher, $newMatcher);
14
    }
15
 
16
    public function testWrapValueWithIsEqualWrapsPrimitive()
17
    {
18
        $matcher = \Hamcrest\Util::wrapValueWithIsEqual('foo');
19
        $this->assertInstanceOf('Hamcrest\Core\IsEqual', $matcher);
20
        $this->assertTrue($matcher->matches('foo'));
21
    }
22
 
23
    public function testCheckAllAreMatchersAcceptsMatchers()
24
    {
25
        \Hamcrest\Util::checkAllAreMatchers(array(
26
            new \Hamcrest\Text\MatchesPattern('/fo+/'),
27
            new \Hamcrest\Core\IsEqual('foo'),
28
        ));
29
    }
30
 
31
    /**
32
     * @expectedException InvalidArgumentException
33
     */
34
    public function testCheckAllAreMatchersFailsForPrimitive()
35
    {
36
        \Hamcrest\Util::checkAllAreMatchers(array(
37
            new \Hamcrest\Text\MatchesPattern('/fo+/'),
38
            'foo',
39
        ));
40
    }
41
 
42
    private function callAndAssertCreateMatcherArray($items)
43
    {
44
        $matchers = \Hamcrest\Util::createMatcherArray($items);
45
        $this->assertInternalType('array', $matchers);
46
        $this->assertSameSize($items, $matchers);
47
        foreach ($matchers as $matcher) {
48
            $this->assertInstanceOf('\Hamcrest\Matcher', $matcher);
49
        }
50
 
51
        return $matchers;
52
    }
53
 
54
    public function testCreateMatcherArrayLeavesMatchersUntouched()
55
    {
56
        $matcher = new \Hamcrest\Text\MatchesPattern('/fo+/');
57
        $items = array($matcher);
58
        $matchers = $this->callAndAssertCreateMatcherArray($items);
59
        $this->assertSame($matcher, $matchers[0]);
60
    }
61
 
62
    public function testCreateMatcherArrayWrapsPrimitiveWithIsEqualMatcher()
63
    {
64
        $matchers = $this->callAndAssertCreateMatcherArray(array('foo'));
65
        $this->assertInstanceOf('Hamcrest\Core\IsEqual', $matchers[0]);
66
        $this->assertTrue($matchers[0]->matches('foo'));
67
    }
68
 
69
    public function testCreateMatcherArrayDoesntModifyOriginalArray()
70
    {
71
        $items = array('foo');
72
        $this->callAndAssertCreateMatcherArray($items);
73
        $this->assertSame('foo', $items[0]);
74
    }
75
 
76
    public function testCreateMatcherArrayUnwrapsSingleArrayElement()
77
    {
78
        $matchers = $this->callAndAssertCreateMatcherArray(array(array('foo')));
79
        $this->assertInstanceOf('Hamcrest\Core\IsEqual', $matchers[0]);
80
        $this->assertTrue($matchers[0]->matches('foo'));
81
    }
82
}