Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Testing\Constraints;
4
 
5
use PHPUnit\Framework\Constraint\Constraint;
6
use ReflectionClass;
7
 
8
class SeeInOrder extends Constraint
9
{
10
    /**
11
     * The string under validation.
12
     *
13
     * @var string
14
     */
15
    protected $content;
16
 
17
    /**
18
     * The last value that failed to pass validation.
19
     *
20
     * @var string
21
     */
22
    protected $failedValue;
23
 
24
    /**
25
     * Create a new constraint instance.
26
     *
27
     * @param  string  $content
28
     * @return void
29
     */
30
    public function __construct($content)
31
    {
32
        $this->content = $content;
33
    }
34
 
35
    /**
36
     * Determine if the rule passes validation.
37
     *
38
     * @param  array  $values
39
     * @return bool
40
     */
41
    public function matches($values): bool
42
    {
43
        $position = 0;
44
 
45
        foreach ($values as $value) {
46
            if (empty($value)) {
47
                continue;
48
            }
49
 
50
            $valuePosition = mb_strpos($this->content, $value, $position);
51
 
52
            if ($valuePosition === false || $valuePosition < $position) {
53
                $this->failedValue = $value;
54
 
55
                return false;
56
            }
57
 
58
            $position = $valuePosition + mb_strlen($value);
59
        }
60
 
61
        return true;
62
    }
63
 
64
    /**
65
     * Get the description of the failure.
66
     *
67
     * @param  array  $values
68
     * @return string
69
     */
70
    public function failureDescription($values): string
71
    {
72
        return sprintf(
73
            'Failed asserting that \'%s\' contains "%s" in specified order.',
74
            $this->content,
75
            $this->failedValue
76
        );
77
    }
78
 
79
    /**
80
     * Get a string representation of the object.
81
     *
82
     * @return string
83
     */
84
    public function toString(): string
85
    {
86
        return (new ReflectionClass($this))->name;
87
    }
88
}