Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of sebastian/comparator.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianBergmann\Comparator;
11
 
12
use RuntimeException;
13
use SebastianBergmann\Diff\Differ;
14
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
15
 
16
/**
17
 * Thrown when an assertion for string equality failed.
18
 */
19
class ComparisonFailure extends RuntimeException
20
{
21
    /**
22
     * Expected value of the retrieval which does not match $actual.
23
     *
24
     * @var mixed
25
     */
26
    protected $expected;
27
 
28
    /**
29
     * Actually retrieved value which does not match $expected.
30
     *
31
     * @var mixed
32
     */
33
    protected $actual;
34
 
35
    /**
36
     * The string representation of the expected value.
37
     *
38
     * @var string
39
     */
40
    protected $expectedAsString;
41
 
42
    /**
43
     * The string representation of the actual value.
44
     *
45
     * @var string
46
     */
47
    protected $actualAsString;
48
 
49
    /**
50
     * @var bool
51
     */
52
    protected $identical;
53
 
54
    /**
55
     * Optional message which is placed in front of the first line
56
     * returned by toString().
57
     *
58
     * @var string
59
     */
60
    protected $message;
61
 
62
    /**
63
     * Initialises with the expected value and the actual value.
64
     *
65
     * @param mixed  $expected         expected value retrieved
66
     * @param mixed  $actual           actual value retrieved
67
     * @param string $expectedAsString
68
     * @param string $actualAsString
69
     * @param bool   $identical
70
     * @param string $message          a string which is prefixed on all returned lines
71
     *                                 in the difference output
72
     */
73
    public function __construct($expected, $actual, $expectedAsString, $actualAsString, $identical = false, $message = '')
74
    {
75
        $this->expected         = $expected;
76
        $this->actual           = $actual;
77
        $this->expectedAsString = $expectedAsString;
78
        $this->actualAsString   = $actualAsString;
79
        $this->message          = $message;
80
    }
81
 
82
    public function getActual()
83
    {
84
        return $this->actual;
85
    }
86
 
87
    public function getExpected()
88
    {
89
        return $this->expected;
90
    }
91
 
92
    /**
93
     * @return string
94
     */
95
    public function getActualAsString()
96
    {
97
        return $this->actualAsString;
98
    }
99
 
100
    /**
101
     * @return string
102
     */
103
    public function getExpectedAsString()
104
    {
105
        return $this->expectedAsString;
106
    }
107
 
108
    /**
109
     * @return string
110
     */
111
    public function getDiff()
112
    {
113
        if (!$this->actualAsString && !$this->expectedAsString) {
114
            return '';
115
        }
116
 
117
        $differ = new Differ(new UnifiedDiffOutputBuilder("\n--- Expected\n+++ Actual\n"));
118
 
119
        return $differ->diff($this->expectedAsString, $this->actualAsString);
120
    }
121
 
122
    /**
123
     * @return string
124
     */
125
    public function toString()
126
    {
127
        return $this->message . $this->getDiff();
128
    }
129
}