PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Mutagenesis/Adapter/PhpunitAdapterTest.php

http://github.com/padraic/mutagenesis
PHP | 360 lines | 317 code | 21 blank | 22 comment | 1 complexity | d7e644f1d1a03058cbed6358c1b9f4ac MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Mutagenesis
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://github.com/padraic/mutateme/blob/rewrite/LICENSE
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to padraic@php.net so we can send you a copy immediately.
  14. *
  15. * @category Mutagenesis
  16. * @package Mutagenesis
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
  19. * @license http://github.com/padraic/mutateme/blob/rewrite/LICENSE New BSD License
  20. */
  21. use Mockery as m;
  22. require_once 'Mutagenesis/Adapter/Phpunit.php';
  23. class Mutagenesis_Adapter_PhpunitAdapterTest extends PHPUnit_Framework_TestCase
  24. {
  25. protected $bootstrap = null;
  26. public function setUp()
  27. {
  28. $this->root = dirname(__FILE__) . '/_files';
  29. }
  30. public function tearDown()
  31. {
  32. if (file_exists(sys_get_temp_dir() . '/mutagenesis.xml')) {
  33. unlink(sys_get_temp_dir() . '/mutagenesis.xml');
  34. }
  35. m::close();
  36. }
  37. /**
  38. * @group baserun
  39. */
  40. public function testAdapterRunsDefaultPhpunitCommand()
  41. {
  42. $runner = m::mock('\Mutagenesis\Runner\Base');
  43. $runner->shouldReceive('getOptions')->andReturn(
  44. array(
  45. 'src' => dirname(__FILE__) . '/_files/phpunit',
  46. 'tests' => dirname(__FILE__) . '/_files/phpunit',
  47. 'base' => dirname(__FILE__) . '/_files/phpunit',
  48. 'cache' => sys_get_temp_dir(),
  49. 'clioptions' => array(),
  50. 'constraint' => 'MM1_MathTest MathTest.php'
  51. )
  52. );
  53. $runner->shouldReceive(array(
  54. 'getBootstrap' => null,
  55. 'getTimeout' => 1200
  56. ));
  57. $adapter = new \Mutagenesis\Adapter\Phpunit;
  58. $result = $adapter->runTests(
  59. $runner,
  60. true,
  61. true
  62. );
  63. $this->assertStringStartsWith(
  64. \PHPUnit_Runner_Version::getVersionString(),
  65. $result[1]['stdout']
  66. );
  67. }
  68. public function testAdapterRunsPhpunitCommandWithAlltestsFileTarget()
  69. {
  70. $runner = m::mock('\Mutagenesis\Runner\Base');
  71. $runner->shouldReceive('getOptions')->andReturn(
  72. array(
  73. 'src' => dirname(__FILE__) . '/_files/phpunit2',
  74. 'tests' => dirname(__FILE__) . '/_files/phpunit2',
  75. 'base' => dirname(__FILE__) . '/_files/phpunit2',
  76. 'cache' => sys_get_temp_dir(),
  77. 'clioptions' => array(),
  78. 'constraint' => 'AllTests.php'
  79. )
  80. );
  81. $runner->shouldReceive(array(
  82. 'getBootstrap' => null,
  83. 'getTimeout' => 1200
  84. ));
  85. $adapter = new \Mutagenesis\Adapter\Phpunit;
  86. $result = $adapter->runTests(
  87. $runner,
  88. true,
  89. true
  90. );
  91. $this->assertStringStartsWith(
  92. \PHPUnit_Runner_Version::getVersionString(),
  93. $result[1]['stdout']
  94. );
  95. }
  96. public function testAdapterDetectsTestsPassing()
  97. {
  98. $runner = m::mock('\Mutagenesis\Runner\Base');
  99. $runner->shouldReceive('getOptions')->andReturn(
  100. array(
  101. 'tests' => $this->root,
  102. 'clioptions' => array(),
  103. 'cache' => sys_get_temp_dir(),
  104. 'constraint' => 'PassTest'
  105. )
  106. );
  107. $runner->shouldReceive(array(
  108. 'getBootstrap' => null,
  109. 'getTimeout' => 1200
  110. ));
  111. $adapter = new \Mutagenesis\Adapter\Phpunit;
  112. $result = $adapter->runTests(
  113. $runner,
  114. true,
  115. true
  116. );
  117. $this->assertTrue($adapter->processOutput($result[1]['stdout']));
  118. }
  119. public function testAdapterDetectsTestsFailingFromTestFail()
  120. {
  121. $runner = m::mock('\Mutagenesis\Runner\Base');
  122. $runner->shouldReceive('getOptions')->andReturn(
  123. array(
  124. 'tests' => $this->root,
  125. 'clioptions' => array(),
  126. 'cache' => sys_get_temp_dir(),
  127. 'constraint' => 'FailTest'
  128. )
  129. );
  130. $runner->shouldReceive(array(
  131. 'getBootstrap' => null,
  132. 'getTimeout' => 1200
  133. ));
  134. $adapter = new \Mutagenesis\Adapter\Phpunit;
  135. $result = $adapter->runTests(
  136. $runner,
  137. true,
  138. true
  139. );
  140. $this->assertFalse($adapter->processOutput($result[1]['stdout']));
  141. }
  142. public function testAdapterDetectsTestsFailingFromException()
  143. {
  144. $runner = m::mock('\Mutagenesis\Runner\Base');
  145. $runner->shouldReceive('getOptions')->andReturn(
  146. array(
  147. 'tests' => $this->root,
  148. 'clioptions' => array(),
  149. 'cache' => sys_get_temp_dir(),
  150. 'constraint' => 'ExceptionTest'
  151. )
  152. );
  153. $runner->shouldReceive(array(
  154. 'getBootstrap' => null,
  155. 'getTimeout' => 1200
  156. ));
  157. $adapter = new \Mutagenesis\Adapter\Phpunit;
  158. $result = $adapter->runTests(
  159. $runner,
  160. true,
  161. true
  162. );
  163. $this->assertFalse($adapter->processOutput($result[1]['stdout']));
  164. }
  165. public function testAdapterDetectsTestsFailingFromError()
  166. {
  167. $runner = m::mock('\Mutagenesis\Runner\Base');
  168. $runner->shouldReceive('getOptions')->andReturn(
  169. array(
  170. 'tests' => $this->root,
  171. 'clioptions' => array(),
  172. 'cache' => sys_get_temp_dir(),
  173. 'constraint' => 'ErrorTest'
  174. )
  175. );
  176. $runner->shouldReceive(array(
  177. 'getBootstrap' => null,
  178. 'getTimeout' => 1200
  179. ));
  180. $adapter = new \Mutagenesis\Adapter\Phpunit;
  181. $result = $adapter->runTests(
  182. $runner,
  183. true,
  184. true
  185. );
  186. $this->assertFalse($adapter->processOutput($result[1]['stdout']));
  187. }
  188. public function testAdapterOutputProcessingDetectsFailOverMultipleLinesWithNoDepOnFinalStatusReport()
  189. {
  190. $adapter = new \Mutagenesis\Adapter\Phpunit;
  191. $output = <<<OUTPUT
  192. PHPUnit 3.4.12 by Sebastian Bergmann.
  193. ............................................................ 60 / 300
  194. ............................................................ 120 / 300
  195. ............................................................ 180 / 300
  196. ............................................................ 240 / 300
  197. ...........................E................................ 300 / 300
  198. Time: 0 seconds, Memory: 11.00Mb
  199. OK (300 tests, 300 assertions)
  200. OUTPUT;
  201. $this->assertFalse($adapter->processOutput($output));
  202. }
  203. public function testAdapterDetectsFailOverMultipleTestCaseRuns()
  204. {
  205. $runner = m::mock('\Mutagenesis\Runner\Base');
  206. $runner->shouldReceive('getOptions')->andReturn(
  207. array(
  208. 'tests' => $this->root,
  209. 'clioptions' => array(),
  210. 'cache' => sys_get_temp_dir(),
  211. 'constraint' => ''
  212. )
  213. );
  214. $runner->shouldReceive(array(
  215. 'getBootstrap' => null,
  216. 'getTimeout' => 1200
  217. ));
  218. $adapter = new \Mutagenesis\Adapter\Phpunit;
  219. $result = $adapter->runTests(
  220. $runner,
  221. true,
  222. true,
  223. array(),
  224. array(
  225. array(
  226. 'class' => 'PassTest',
  227. 'file' => 'PassTest.php'
  228. ),
  229. array(
  230. 'class' => 'FailTest',
  231. 'file' => 'FailTest.php'
  232. )
  233. )
  234. );
  235. $this->assertFalse($adapter->processOutput($result[1]['stdout']));
  236. }
  237. public function testAdapterDetectsErrorOverMultipleTestCaseRuns()
  238. {
  239. $runner = m::mock('\Mutagenesis\Runner\Base');
  240. $runner->shouldReceive('getOptions')->andReturn(
  241. array(
  242. 'tests' => $this->root,
  243. 'clioptions' => array(),
  244. 'cache' => sys_get_temp_dir(),
  245. 'constraint' => ''
  246. )
  247. );
  248. $runner->shouldReceive(array(
  249. 'getBootstrap' => null,
  250. 'getTimeout' => 1200
  251. ));
  252. $adapter = new \Mutagenesis\Adapter\Phpunit;
  253. $result = $adapter->runTests(
  254. $runner,
  255. true,
  256. true,
  257. array(),
  258. array(
  259. array(
  260. 'class' => 'PassTest',
  261. 'file' => 'PassTest.php'
  262. ),
  263. array(
  264. 'class' => 'ErrorTest',
  265. 'file' => 'ErrorTest.php'
  266. )
  267. )
  268. );
  269. $this->assertFalse($adapter->processOutput($result[1]['stdout']));
  270. }
  271. public function testAdapterDetectsExceptionOverMultipleTestCaseRuns()
  272. {
  273. $runner = m::mock('\Mutagenesis\Runner\Base');
  274. $runner->shouldReceive('getOptions')->andReturn(
  275. array(
  276. 'tests' => $this->root,
  277. 'clioptions' => array(),
  278. 'cache' => sys_get_temp_dir(),
  279. 'constraint' => ''
  280. )
  281. );
  282. $runner->shouldReceive(array(
  283. 'getBootstrap' => null,
  284. 'getTimeout' => 1200
  285. ));
  286. $adapter = new \Mutagenesis\Adapter\Phpunit;
  287. $result = $adapter->runTests(
  288. $runner,
  289. true,
  290. true,
  291. array(),
  292. array(
  293. array(
  294. 'class' => 'PassTest',
  295. 'file' => 'PassTest.php'
  296. ),
  297. array(
  298. 'class' => 'ExceptionTest',
  299. 'file' => 'ExceptionTest.php'
  300. )
  301. )
  302. );
  303. $this->assertFalse($adapter->processOutput($result[1]['stdout']));
  304. }
  305. public function testAdapterDetectsPassOverMultipleTestCaseRuns()
  306. {
  307. $runner = m::mock('\Mutagenesis\Runner\Base');
  308. $runner->shouldReceive('getOptions')->andReturn(
  309. array(
  310. 'tests' => $this->root,
  311. 'clioptions' => array(),
  312. 'cache' => sys_get_temp_dir(),
  313. 'constraint' => ''
  314. )
  315. );
  316. $runner->shouldReceive(array(
  317. 'getBootstrap' => null,
  318. 'getTimeout' => 1200
  319. ));
  320. $adapter = new \Mutagenesis\Adapter\Phpunit;
  321. $result = $adapter->runTests(
  322. $runner,
  323. true,
  324. true,
  325. array(),
  326. array(
  327. array(
  328. 'class' => 'PassTest',
  329. 'file' => 'PassTest.php'
  330. ),
  331. array(
  332. 'class' => 'PassTest',
  333. 'file' => 'PassTest.php'
  334. )
  335. )
  336. );
  337. $this->assertTrue($adapter->processOutput($result[1]['stdout']));
  338. }
  339. }