Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * PHPUnit
4
 *
5
 * Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 *   * Redistributions of source code must retain the above copyright
13
 *     notice, this list of conditions and the following disclaimer.
14
 *
15
 *   * Redistributions in binary form must reproduce the above copyright
16
 *     notice, this list of conditions and the following disclaimer in
17
 *     the documentation and/or other materials provided with the
18
 *     distribution.
19
 *
20
 *   * Neither the name of Sebastian Bergmann nor the names of his
21
 *     contributors may be used to endorse or promote products derived
22
 *     from this software without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
 * POSSIBILITY OF SUCH DAMAGE.
36
 *
37
 * @category   Testing
38
 * @package    PHPUnit
39
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
40
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
41
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 * @link       http://www.phpunit.de/
43
 * @since      File available since Release 2.0.0
44
 */
45
 
46
require_once 'PHPUnit/Framework.php';
47
require_once 'PHPUnit/Util/Type.php';
48
 
49
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
50
 
51
/**
52
 * Thrown when an assertion for string equality failed.
53
 *
54
 * @category   Testing
55
 * @package    PHPUnit
56
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
57
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
58
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
59
 * @version    Release: 3.4.15
60
 * @link       http://www.phpunit.de/
61
 * @since      Class available since Release 2.0.0
62
 */
63
abstract class PHPUnit_Framework_ComparisonFailure extends PHPUnit_Framework_AssertionFailedError
64
{
65
    /**
66
     * Expected value of the retrieval which does not match $actual.
67
     * @var mixed
68
     */
69
    protected $expected;
70
 
71
    /**
72
     * Actually retrieved value which does not match $expected.
73
     * @var mixed
74
     */
75
    protected $actual;
76
 
77
    /**
78
     * @var boolean
79
     */
80
    protected $identical;
81
 
82
    /**
83
     * Optional message which is placed in front of the first line
84
     * returned by toString().
85
     * @var string
86
     */
87
    protected $message;
88
 
89
    /**
90
     * Initialises with the expected value and the actual value.
91
     *
92
     * @param mixed $expected Expected value retrieved.
93
     * @param mixed $actual Actual value retrieved.
94
     * @param boolean $identical
95
     * @param string $message A string which is prefixed on all returned lines
96
     *                        in the difference output.
97
     */
98
    public function __construct($expected, $actual, $identical = FALSE, $message = '')
99
    {
100
        $this->expected  = $expected;
101
        $this->actual    = $actual;
102
        $this->identical = $identical;
103
        $this->message   = $message;
104
    }
105
 
106
    /**
107
     * @return mixed
108
     */
109
    public function getActual()
110
    {
111
        return $this->actual;
112
    }
113
 
114
    /**
115
     * @return mixed
116
     */
117
    public function getExpected()
118
    {
119
        return $this->expected;
120
    }
121
 
122
    /**
123
     * @return boolean
124
     */
125
    public function identical()
126
    {
127
        return $this->identical;
128
    }
129
 
130
    /**
131
     * Figures out which diff class to use for the input types then
132
     * instantiates that class and returns the object.
133
     * @note The diff is type sensitive, if the type differs only the types
134
     *       are shown.
135
     *
136
     * @param mixed $expected Expected value retrieved.
137
     * @param mixed $actual Actual value retrieved.
138
     * @param string $message A string which is prefixed on all returned lines
139
     *                        in the difference output.
140
     * @return PHPUnit_Framework_ComparisonFailure
141
     */
142
    public static function diffIdentical($expected, $actual, $message = '')
143
    {
144
        if (gettype($expected) !== gettype($actual)) {
145
            return new PHPUnit_Framework_ComparisonFailure_Type(
146
              $expected, $actual, TRUE, $message
147
            );
148
        }
149
 
150
        else if (is_array($expected) && is_array($actual)) {
151
            return new PHPUnit_Framework_ComparisonFailure_Array(
152
              $expected, $actual, TRUE, $message
153
            );
154
        }
155
 
156
        else if (is_object($expected) && is_object($actual)) {
157
            return new PHPUnit_Framework_ComparisonFailure_Object(
158
              $expected, $actual, TRUE, $message
159
            );
160
        }
161
 
162
        else if (is_string($expected) && !is_object($actual)) {
163
            return new PHPUnit_Framework_ComparisonFailure_String(
164
              $expected, $actual, TRUE, $message
165
            );
166
        }
167
 
168
        else if (is_null($expected) || is_scalar($expected)) {
169
            return new PHPUnit_Framework_ComparisonFailure_Scalar(
170
              $expected, $actual, TRUE, $message
171
            );
172
        }
173
    }
174
 
175
    /**
176
     * Figures out which diff class to use for the input types then
177
     * instantiates that class and returns the object.
178
     * @note The diff is not type sensitive, if the type differs the $actual
179
     *       value will be converted to the same type as the $expected.
180
     *
181
     * @param mixed $expected Expected value retrieved.
182
     * @param mixed $actual Actual value retrieved.
183
     * @param string $message A string which is prefixed on all returned lines
184
     *                        in the difference output.
185
     * @return PHPUnit_Framework_ComparisonFailure
186
     */
187
    public static function diffEqual($expected, $actual, $message = '')
188
    {
189
        if (is_array($expected) && is_array($actual)) {
190
            return new PHPUnit_Framework_ComparisonFailure_Array(
191
              $expected, $actual, FALSE, $message
192
            );
193
        }
194
 
195
        else if (is_object($expected) && is_object($actual)) {
196
            return new PHPUnit_Framework_ComparisonFailure_Object(
197
              $expected, $actual, FALSE, $message
198
            );
199
        }
200
 
201
        else if (is_string($expected) && !is_object($actual)) {
202
            return new PHPUnit_Framework_ComparisonFailure_String(
203
              $expected, $actual, FALSE, $message
204
            );
205
        }
206
 
207
        else if (is_null($expected) || is_scalar($expected)) {
208
            return new PHPUnit_Framework_ComparisonFailure_Scalar(
209
              $expected, $actual, FALSE, $message
210
            );
211
        }
212
    }
213
}
214
 
215
require_once 'PHPUnit/Framework/ComparisonFailure/Array.php';
216
require_once 'PHPUnit/Framework/ComparisonFailure/Object.php';
217
require_once 'PHPUnit/Framework/ComparisonFailure/Scalar.php';
218
require_once 'PHPUnit/Framework/ComparisonFailure/String.php';
219
require_once 'PHPUnit/Framework/ComparisonFailure/Type.php';
220
?>