PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/script/lib/PHPUnit/Framework/ComparisonFailure.php

https://bitbucket.org/chamilo/chamilo-dev/
PHP | 206 lines | 76 code | 17 blank | 113 comment | 24 complexity | ab6fc3b193e96eeb37aa1e31867652be MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
  1. <?php
  2. /**
  3. * PHPUnit
  4. *
  5. * Copyright (c) 2002-2011, Sebastian Bergmann <sebastian@phpunit.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. * @package PHPUnit
  38. * @subpackage Framework
  39. * @author Sebastian Bergmann <sebastian@phpunit.de>
  40. * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.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. * Thrown when an assertion for string equality failed.
  47. *
  48. * @package PHPUnit
  49. * @subpackage Framework
  50. * @author Sebastian Bergmann <sebastian@phpunit.de>
  51. * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
  52. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  53. * @version Release: 3.5.9
  54. * @link http://www.phpunit.de/
  55. * @since Class available since Release 2.0.0
  56. */
  57. abstract class PHPUnit_Framework_ComparisonFailure extends PHPUnit_Framework_AssertionFailedError
  58. {
  59. /**
  60. * Expected value of the retrieval which does not match $actual.
  61. * @var mixed
  62. */
  63. protected $expected;
  64. /**
  65. * Actually retrieved value which does not match $expected.
  66. * @var mixed
  67. */
  68. protected $actual;
  69. /**
  70. * @var boolean
  71. */
  72. protected $identical;
  73. /**
  74. * Optional message which is placed in front of the first line
  75. * returned by toString().
  76. * @var string
  77. */
  78. protected $message;
  79. /**
  80. * Initialises with the expected value and the actual value.
  81. *
  82. * @param mixed $expected Expected value retrieved.
  83. * @param mixed $actual Actual value retrieved.
  84. * @param boolean $identical
  85. * @param string $message A string which is prefixed on all returned lines
  86. * in the difference output.
  87. */
  88. public function __construct($expected, $actual, $identical = FALSE, $message = '')
  89. {
  90. $this->expected = $expected;
  91. $this->actual = $actual;
  92. $this->identical = $identical;
  93. $this->message = $message;
  94. }
  95. /**
  96. * @return mixed
  97. */
  98. public function getActual()
  99. {
  100. return $this->actual;
  101. }
  102. /**
  103. * @return mixed
  104. */
  105. public function getExpected()
  106. {
  107. return $this->expected;
  108. }
  109. /**
  110. * @return boolean
  111. */
  112. public function identical()
  113. {
  114. return $this->identical;
  115. }
  116. /**
  117. * Figures out which diff class to use for the input types then
  118. * instantiates that class and returns the object.
  119. * @note The diff is type sensitive, if the type differs only the types
  120. * are shown.
  121. *
  122. * @param mixed $expected Expected value retrieved.
  123. * @param mixed $actual Actual value retrieved.
  124. * @param string $message A string which is prefixed on all returned lines
  125. * in the difference output.
  126. * @return PHPUnit_Framework_ComparisonFailure
  127. */
  128. public static function diffIdentical($expected, $actual, $message = '')
  129. {
  130. if (gettype($expected) !== gettype($actual))
  131. {
  132. return new PHPUnit_Framework_ComparisonFailure_Type($expected, $actual, TRUE, $message);
  133. }
  134. else
  135. if (is_array($expected) && is_array($actual))
  136. {
  137. return new PHPUnit_Framework_ComparisonFailure_Array($expected, $actual, TRUE, $message);
  138. }
  139. else
  140. if (is_object($expected) && is_object($actual))
  141. {
  142. return new PHPUnit_Framework_ComparisonFailure_Object($expected, $actual, TRUE, $message);
  143. }
  144. else
  145. if (is_string($expected) && ! is_object($actual))
  146. {
  147. return new PHPUnit_Framework_ComparisonFailure_String($expected, $actual, TRUE, $message);
  148. }
  149. else
  150. if (is_null($expected) || is_scalar($expected))
  151. {
  152. return new PHPUnit_Framework_ComparisonFailure_Scalar($expected, $actual, TRUE, $message);
  153. }
  154. }
  155. /**
  156. * Figures out which diff class to use for the input types then
  157. * instantiates that class and returns the object.
  158. * @note The diff is not type sensitive, if the type differs the $actual
  159. * value will be converted to the same type as the $expected.
  160. *
  161. * @param mixed $expected Expected value retrieved.
  162. * @param mixed $actual Actual value retrieved.
  163. * @param string $message A string which is prefixed on all returned lines
  164. * in the difference output.
  165. * @return PHPUnit_Framework_ComparisonFailure
  166. */
  167. public static function diffEqual($expected, $actual, $message = '')
  168. {
  169. if (is_array($expected) && is_array($actual))
  170. {
  171. return new PHPUnit_Framework_ComparisonFailure_Array($expected, $actual, FALSE, $message);
  172. }
  173. else
  174. if (is_object($expected) && is_object($actual))
  175. {
  176. return new PHPUnit_Framework_ComparisonFailure_Object($expected, $actual, FALSE, $message);
  177. }
  178. else
  179. if (is_string($expected) && ! is_object($actual))
  180. {
  181. return new PHPUnit_Framework_ComparisonFailure_String($expected, $actual, FALSE, $message);
  182. }
  183. else
  184. if (is_null($expected) || is_scalar($expected))
  185. {
  186. return new PHPUnit_Framework_ComparisonFailure_Scalar($expected, $actual, FALSE, $message);
  187. }
  188. }
  189. }