PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/phpunit/phpunit/PHPUnit/Util/DeprecatedFeature/Logger.php

https://bitbucket.org/alexpozdnyakov/kohana
PHP | 201 lines | 63 code | 16 blank | 122 comment | 7 complexity | d66246abb9a1f7e6ff439f32e326b613 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * PHPUnit
  4. *
  5. * Copyright (c) 2002-2010, 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 Ralph Schindler <ralph.schindler@zend.com>
  40. * @author Sebastian Bergmann <sebastian@phpunit.de>
  41. * @copyright 2002-2010 Sebastian Bergmann <sebastian@phpunit.de>
  42. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  43. * @link http://www.phpunit.de/
  44. * @since File available since Release 3.5.7
  45. */
  46. /**
  47. * Test Listener that tracks the usage of deprecated features.
  48. *
  49. * @package PHPUnit
  50. * @subpackage Framework
  51. * @author Ralph Schindler <ralph.schindler@zend.com>
  52. * @author Sebastian Bergmann <sebastian@phpunit.de>
  53. * @copyright 2002-2010 Sebastian Bergmann <sebastian@phpunit.de>
  54. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  55. * @link http://www.phpunit.de/
  56. * @since Class available since Release 3.5.7
  57. */
  58. class PHPUnit_Util_DeprecatedFeature_Logger implements PHPUnit_Framework_TestListener
  59. {
  60. /**
  61. * @var PHPUnit_Framework_TestCase
  62. */
  63. protected static $currentTest = NULL;
  64. /**
  65. * This is the publically accessible API for notifying the system that a
  66. * deprecated feature has been used.
  67. *
  68. * If it is run via a TestRunner and the test extends
  69. * PHPUnit_Framework_TestCase, then this will inject the result into the
  70. * test runner for display, if not, it will throw the notice to STDERR.
  71. *
  72. * @param string $message
  73. * @param int|bool $backtraceDepth
  74. */
  75. public static function log($message, $backtraceDepth = 2)
  76. {
  77. if ($backtraceDepth !== FALSE) {
  78. $trace = debug_backtrace(FALSE);
  79. if (is_int($backtraceDepth)) {
  80. $traceItem = $trace[$backtraceDepth];
  81. }
  82. if (!isset($traceItem['file'])) {
  83. $reflectionClass = new ReflectionClass($traceItem['class']);
  84. $traceItem['file'] = $reflectionClass->getFileName();
  85. }
  86. if (!isset($traceItem['line']) &&
  87. isset($traceItem['class']) &&
  88. isset($traceItem['function'])) {
  89. if (!isset($reflectionClass)) {
  90. $reflectionClass = new ReflectionClass($traceItem['class']);
  91. }
  92. $method = $reflectionClass->getMethod($traceItem['function']);
  93. $traceItem['line'] = '(between ' . $method->getStartLine() .
  94. ' and ' . $method->getEndLine() . ')';
  95. }
  96. }
  97. $deprecatedFeature = new PHPUnit_Util_DeprecatedFeature(
  98. $message, $traceItem
  99. );
  100. if (self::$currentTest instanceof PHPUnit_Framework_TestCase) {
  101. $result = self::$currentTest->getTestResultObject();
  102. $result->addDeprecatedFeature($deprecatedFeature);
  103. } else {
  104. file_put_contents('php://stderr', $deprecatedFeature);
  105. }
  106. }
  107. /**
  108. * An error occurred.
  109. *
  110. * @param PHPUnit_Framework_Test $test
  111. * @param Exception $e
  112. * @param float $time
  113. */
  114. public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
  115. {
  116. }
  117. /**
  118. * A failure occurred.
  119. *
  120. * @param PHPUnit_Framework_Test $test
  121. * @param PHPUnit_Framework_AssertionFailedError $e
  122. * @param float $time
  123. */
  124. public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
  125. {
  126. }
  127. /**
  128. * Incomplete test.
  129. *
  130. * @param PHPUnit_Framework_Test $test
  131. * @param Exception $e
  132. * @param float $time
  133. */
  134. public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
  135. {
  136. }
  137. /**
  138. * Skipped test.
  139. *
  140. * @param PHPUnit_Framework_Test $test
  141. * @param Exception $e
  142. * @param float $time
  143. * @since Method available since Release 3.0.0
  144. */
  145. public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
  146. {
  147. }
  148. /**
  149. * A test suite started.
  150. *
  151. * @param PHPUnit_Framework_TestSuite $suite
  152. * @since Method available since Release 2.2.0
  153. */
  154. public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
  155. {
  156. }
  157. /**
  158. * A test suite ended.
  159. *
  160. * @param PHPUnit_Framework_TestSuite $suite
  161. * @since Method available since Release 2.2.0
  162. */
  163. public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
  164. {
  165. }
  166. /**
  167. * A test started.
  168. *
  169. * @param PHPUnit_Framework_Test $test
  170. */
  171. public function startTest(PHPUnit_Framework_Test $test)
  172. {
  173. self::$currentTest = $test;
  174. }
  175. /**
  176. * A test ended.
  177. *
  178. * @param PHPUnit_Framework_Test $test
  179. * @param float $time
  180. */
  181. public function endTest(PHPUnit_Framework_Test $test, $time)
  182. {
  183. self::$currentTest = NULL;
  184. }
  185. }