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\Text;
3
 
4
/*
5
 Copyright (c) 2009 hamcrest.org
6
 */
7
use Hamcrest\Description;
8
use Hamcrest\TypeSafeMatcher;
9
 
10
/**
11
 * Tests if the value contains a series of substrings in a constrained order.
12
 */
13
class StringContainsInOrder extends TypeSafeMatcher
14
{
15
 
16
    private $_substrings;
17
 
18
    public function __construct(array $substrings)
19
    {
20
        parent::__construct(self::TYPE_STRING);
21
 
22
        $this->_substrings = $substrings;
23
    }
24
 
25
    protected function matchesSafely($item)
26
    {
27
        $fromIndex = 0;
28
 
29
        foreach ($this->_substrings as $substring) {
30
            if (false === $fromIndex = strpos($item, $substring, $fromIndex)) {
31
                return false;
32
            }
33
        }
34
 
35
        return true;
36
    }
37
 
38
    protected function describeMismatchSafely($item, Description $mismatchDescription)
39
    {
40
        $mismatchDescription->appendText('was ')->appendText($item);
41
    }
42
 
43
    public function describeTo(Description $description)
44
    {
45
        $description->appendText('a string containing ')
46
                                ->appendValueList('', ', ', '', $this->_substrings)
47
                                ->appendText(' in order')
48
                                ;
49
    }
50
 
51
    /**
52
     * Matches if value contains $substrings in a constrained order.
53
     *
54
     * @factory ...
55
     */
56
    public static function stringContainsInOrder(/* args... */)
57
    {
58
        $args = func_get_args();
59
 
60
        if (isset($args[0]) && is_array($args[0])) {
61
            $args = $args[0];
62
        }
63
 
64
        return new self($args);
65
    }
66
}