PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/script/lib/PHPUnit/TextUI/Command.php

https://bitbucket.org/renaatdemuynck/chamilo
PHP | 899 lines | 647 code | 134 blank | 118 comment | 89 complexity | 8b41fdb4c771baf0af336dd5a3334818 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT, GPL-2.0
  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 TextUI
  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 3.0.0
  44. */
  45. /**
  46. * A TestRunner for the Command Line Interface (CLI)
  47. * PHP SAPI Module.
  48. *
  49. * @package PHPUnit
  50. * @subpackage TextUI
  51. * @author Sebastian Bergmann <sebastian@phpunit.de>
  52. * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
  53. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  54. * @version Release: 3.5.9
  55. * @link http://www.phpunit.de/
  56. * @since Class available since Release 3.0.0
  57. */
  58. class PHPUnit_TextUI_Command
  59. {
  60. /**
  61. * @var array
  62. */
  63. protected $arguments = array('listGroups' => FALSE, 'loader' => NULL, 'syntaxCheck' => FALSE,
  64. 'useDefaultConfiguration' => TRUE);
  65. /**
  66. * @var array
  67. */
  68. protected $options = array();
  69. /**
  70. * @var array
  71. */
  72. protected $longOptions = array('colors' => NULL, 'bootstrap=' => NULL, 'configuration=' => NULL,
  73. 'coverage-html=' => NULL, 'coverage-clover=' => NULL, 'debug' => NULL, 'exclude-group=' => NULL,
  74. 'filter=' => NULL, 'group=' => NULL, 'help' => NULL, 'include-path=' => NULL, 'list-groups' => NULL,
  75. 'loader=' => NULL, 'log-dbus' => NULL, 'log-json=' => NULL, 'log-junit=' => NULL, 'log-tap=' => NULL,
  76. 'process-isolation' => NULL, 'repeat=' => NULL, 'skeleton-class' => NULL, 'skeleton-test' => NULL,
  77. 'stderr' => NULL, 'stop-on-error' => NULL, 'stop-on-failure' => NULL, 'stop-on-incomplete' => NULL,
  78. 'stop-on-skipped' => NULL, 'story' => NULL, 'story-html=' => NULL, 'story-text=' => NULL, 'strict' => NULL,
  79. 'syntax-check' => NULL, 'tap' => NULL, 'testdox' => NULL, 'testdox-html=' => NULL, 'testdox-text=' => NULL,
  80. 'no-configuration' => NULL, 'no-globals-backup' => NULL, 'static-backup' => NULL, 'verbose' => NULL,
  81. 'version' => NULL, 'wait' => NULL);
  82. /**
  83. * @param boolean $exit
  84. */
  85. public static function main($exit = TRUE)
  86. {
  87. $command = new PHPUnit_TextUI_Command();
  88. $command->run($_SERVER['argv'], $exit);
  89. }
  90. /**
  91. * @param array $argv
  92. * @param boolean $exit
  93. */
  94. public function run(array $argv, $exit = TRUE)
  95. {
  96. $this->handleArguments($argv);
  97. $runner = new PHPUnit_TextUI_TestRunner($this->arguments['loader']);
  98. if (is_object($this->arguments['test']) && $this->arguments['test'] instanceof PHPUnit_Framework_Test)
  99. {
  100. $suite = $this->arguments['test'];
  101. }
  102. else
  103. {
  104. $suite = $runner->getTest($this->arguments['test'], $this->arguments['testFile'], $this->arguments['syntaxCheck']);
  105. }
  106. if (count($suite) == 0)
  107. {
  108. $skeleton = new PHPUnit_Util_Skeleton_Test($suite->getName(), $this->arguments['testFile']);
  109. $result = $skeleton->generate(TRUE);
  110. if (! $result['incomplete'])
  111. {
  112. eval(str_replace(array('<?php', '?>'), '', $result['code']));
  113. $suite = new PHPUnit_Framework_TestSuite($this->arguments['test'] . 'Test');
  114. }
  115. }
  116. if ($this->arguments['listGroups'])
  117. {
  118. PHPUnit_TextUI_TestRunner :: printVersionString();
  119. print "Available test group(s):\n";
  120. $groups = $suite->getGroups();
  121. sort($groups);
  122. foreach ($groups as $group)
  123. {
  124. print " - $group\n";
  125. }
  126. exit(PHPUnit_TextUI_TestRunner :: SUCCESS_EXIT);
  127. }
  128. unset($this->arguments['test']);
  129. unset($this->arguments['testFile']);
  130. try
  131. {
  132. $result = $runner->doRun($suite, $this->arguments);
  133. }
  134. catch (PHPUnit_Framework_Exception $e)
  135. {
  136. print $e->getMessage() . "\n";
  137. }
  138. if ($exit)
  139. {
  140. if (isset($result) && $result->wasSuccessful())
  141. {
  142. exit(PHPUnit_TextUI_TestRunner :: SUCCESS_EXIT);
  143. }
  144. else
  145. if (! isset($result) || $result->errorCount() > 0)
  146. {
  147. exit(PHPUnit_TextUI_TestRunner :: EXCEPTION_EXIT);
  148. }
  149. else
  150. {
  151. exit(PHPUnit_TextUI_TestRunner :: FAILURE_EXIT);
  152. }
  153. }
  154. }
  155. /**
  156. * Handles the command-line arguments.
  157. *
  158. * A child class of PHPUnit_TextUI_Command can hook into the argument
  159. * parsing by adding the switch(es) to the $longOptions array and point to a
  160. * callback method that handles the switch(es) in the child class like this
  161. *
  162. * <code>
  163. * <?php
  164. * class MyCommand extends PHPUnit_TextUI_Command
  165. * {
  166. * public function __construct()
  167. * {
  168. * $this->longOptions['--my-switch'] = 'myHandler';
  169. * }
  170. *
  171. * // --my-switch foo -> myHandler('foo')
  172. * protected function myHandler($value)
  173. * {
  174. * }
  175. * }
  176. * </code>
  177. *
  178. * @param array $argv
  179. */
  180. protected function handleArguments(array $argv)
  181. {
  182. try
  183. {
  184. $this->options = PHPUnit_Util_Getopt :: getopt($argv, 'd:c:', array_keys($this->longOptions));
  185. }
  186. catch (RuntimeException $e)
  187. {
  188. PHPUnit_TextUI_TestRunner :: showError($e->getMessage());
  189. }
  190. $skeletonClass = FALSE;
  191. $skeletonTest = FALSE;
  192. foreach ($this->options[0] as $option)
  193. {
  194. switch ($option[0])
  195. {
  196. case '--colors' :
  197. {
  198. $this->arguments['colors'] = TRUE;
  199. }
  200. break;
  201. case '--bootstrap' :
  202. {
  203. $this->arguments['bootstrap'] = $option[1];
  204. }
  205. break;
  206. case 'c' :
  207. case '--configuration' :
  208. {
  209. $this->arguments['configuration'] = $option[1];
  210. }
  211. break;
  212. case '--coverage-clover' :
  213. {
  214. if (extension_loaded('tokenizer') && extension_loaded('xdebug'))
  215. {
  216. $this->arguments['coverageClover'] = $option[1];
  217. }
  218. else
  219. {
  220. if (! extension_loaded('tokenizer'))
  221. {
  222. $this->showMessage('The tokenizer extension is not loaded.');
  223. }
  224. else
  225. {
  226. $this->showMessage('The Xdebug extension is not loaded.');
  227. }
  228. }
  229. }
  230. break;
  231. case '--coverage-html' :
  232. {
  233. if (extension_loaded('tokenizer') && extension_loaded('xdebug'))
  234. {
  235. $this->arguments['reportDirectory'] = $option[1];
  236. }
  237. else
  238. {
  239. if (! extension_loaded('tokenizer'))
  240. {
  241. $this->showMessage('The tokenizer extension is not loaded.');
  242. }
  243. else
  244. {
  245. $this->showMessage('The Xdebug extension is not loaded.');
  246. }
  247. }
  248. }
  249. break;
  250. case 'd' :
  251. {
  252. $ini = explode('=', $option[1]);
  253. if (isset($ini[0]))
  254. {
  255. if (isset($ini[1]))
  256. {
  257. ini_set($ini[0], $ini[1]);
  258. }
  259. else
  260. {
  261. ini_set($ini[0], TRUE);
  262. }
  263. }
  264. }
  265. break;
  266. case '--debug' :
  267. {
  268. $this->arguments['debug'] = TRUE;
  269. }
  270. break;
  271. case '--help' :
  272. {
  273. $this->showHelp();
  274. exit(PHPUnit_TextUI_TestRunner :: SUCCESS_EXIT);
  275. }
  276. break;
  277. case '--filter' :
  278. {
  279. $this->arguments['filter'] = $option[1];
  280. }
  281. break;
  282. case '--group' :
  283. {
  284. $this->arguments['groups'] = explode(',', $option[1]);
  285. }
  286. break;
  287. case '--exclude-group' :
  288. {
  289. $this->arguments['excludeGroups'] = explode(',', $option[1]);
  290. }
  291. break;
  292. case '--include-path' :
  293. {
  294. $includePath = $option[1];
  295. }
  296. break;
  297. case '--list-groups' :
  298. {
  299. $this->arguments['listGroups'] = TRUE;
  300. }
  301. break;
  302. case '--loader' :
  303. {
  304. $this->arguments['loader'] = $option[1];
  305. }
  306. break;
  307. case '--log-dbus' :
  308. {
  309. $this->arguments['logDbus'] = TRUE;
  310. }
  311. break;
  312. case '--log-json' :
  313. {
  314. $this->arguments['jsonLogfile'] = $option[1];
  315. }
  316. break;
  317. case '--log-junit' :
  318. {
  319. $this->arguments['junitLogfile'] = $option[1];
  320. }
  321. break;
  322. case '--log-tap' :
  323. {
  324. $this->arguments['tapLogfile'] = $option[1];
  325. }
  326. break;
  327. case '--process-isolation' :
  328. {
  329. $this->arguments['processIsolation'] = TRUE;
  330. $this->arguments['syntaxCheck'] = FALSE;
  331. }
  332. break;
  333. case '--repeat' :
  334. {
  335. $this->arguments['repeat'] = (int) $option[1];
  336. }
  337. break;
  338. case '--stderr' :
  339. {
  340. $this->arguments['printer'] = new PHPUnit_TextUI_ResultPrinter('php://stderr', isset($this->arguments['verbose']) ? $this->arguments['verbose'] : FALSE);
  341. }
  342. break;
  343. case '--stop-on-error' :
  344. {
  345. $this->arguments['stopOnError'] = TRUE;
  346. }
  347. break;
  348. case '--stop-on-failure' :
  349. {
  350. $this->arguments['stopOnFailure'] = TRUE;
  351. }
  352. break;
  353. case '--stop-on-incomplete' :
  354. {
  355. $this->arguments['stopOnIncomplete'] = TRUE;
  356. }
  357. break;
  358. case '--stop-on-skipped' :
  359. {
  360. $this->arguments['stopOnSkipped'] = TRUE;
  361. }
  362. break;
  363. case '--skeleton-test' :
  364. {
  365. $skeletonTest = TRUE;
  366. $skeletonClass = FALSE;
  367. }
  368. break;
  369. case '--skeleton-class' :
  370. {
  371. $skeletonClass = TRUE;
  372. $skeletonTest = FALSE;
  373. }
  374. break;
  375. case '--tap' :
  376. {
  377. $this->arguments['printer'] = new PHPUnit_Util_Log_TAP();
  378. }
  379. break;
  380. case '--story' :
  381. {
  382. $this->showMessage('The --story functionality is deprecated and ' . 'will be removed in the future.', FALSE);
  383. $this->arguments['printer'] = new PHPUnit_Extensions_Story_ResultPrinter_Text();
  384. }
  385. break;
  386. case '--story-html' :
  387. {
  388. $this->showMessage('The --story-html functionality is deprecated and ' . 'will be removed in the future.', FALSE);
  389. $this->arguments['storyHTMLFile'] = $option[1];
  390. }
  391. break;
  392. case '--story-text' :
  393. {
  394. $this->showMessage('The --story-text functionality is deprecated and ' . 'will be removed in the future.', FALSE);
  395. $this->arguments['storyTextFile'] = $option[1];
  396. }
  397. break;
  398. case '--syntax-check' :
  399. {
  400. $this->arguments['syntaxCheck'] = TRUE;
  401. }
  402. break;
  403. case '--testdox' :
  404. {
  405. $this->arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text();
  406. }
  407. break;
  408. case '--testdox-html' :
  409. {
  410. $this->arguments['testdoxHTMLFile'] = $option[1];
  411. }
  412. break;
  413. case '--testdox-text' :
  414. {
  415. $this->arguments['testdoxTextFile'] = $option[1];
  416. }
  417. break;
  418. case '--no-configuration' :
  419. {
  420. $this->arguments['useDefaultConfiguration'] = FALSE;
  421. }
  422. break;
  423. case '--no-globals-backup' :
  424. {
  425. $this->arguments['backupGlobals'] = FALSE;
  426. }
  427. break;
  428. case '--static-backup' :
  429. {
  430. $this->arguments['backupStaticAttributes'] = TRUE;
  431. }
  432. break;
  433. case '--verbose' :
  434. {
  435. $this->arguments['verbose'] = TRUE;
  436. }
  437. break;
  438. case '--version' :
  439. {
  440. PHPUnit_TextUI_TestRunner :: printVersionString();
  441. exit(PHPUnit_TextUI_TestRunner :: SUCCESS_EXIT);
  442. }
  443. break;
  444. case '--wait' :
  445. {
  446. $this->arguments['wait'] = TRUE;
  447. }
  448. break;
  449. case '--strict' :
  450. {
  451. $this->arguments['strict'] = TRUE;
  452. }
  453. break;
  454. default :
  455. {
  456. $optionName = str_replace('--', '', $option[0]);
  457. if (isset($this->longOptions[$optionName]))
  458. {
  459. $handler = $this->longOptions[$optionName];
  460. }
  461. else
  462. if (isset($this->longOptions[$optionName . '=']))
  463. {
  464. $handler = $this->longOptions[$optionName . '='];
  465. }
  466. if (isset($handler) && is_callable(array($this, $handler)))
  467. {
  468. $this->$handler($option[1]);
  469. }
  470. }
  471. }
  472. }
  473. if (isset($this->arguments['printer']) && $this->arguments['printer'] instanceof PHPUnit_Extensions_Story_ResultPrinter_Text && isset($this->arguments['processIsolation']) && $this->arguments['processIsolation'])
  474. {
  475. $this->showMessage('The story result printer cannot be used in process isolation.');
  476. }
  477. $this->handleCustomTestSuite();
  478. if (! isset($this->arguments['test']))
  479. {
  480. if (isset($this->options[1][0]))
  481. {
  482. $this->arguments['test'] = $this->options[1][0];
  483. }
  484. if (isset($this->options[1][1]))
  485. {
  486. $this->arguments['testFile'] = $this->options[1][1];
  487. }
  488. else
  489. {
  490. $this->arguments['testFile'] = '';
  491. }
  492. if (isset($this->arguments['test']) && is_file($this->arguments['test']))
  493. {
  494. $this->arguments['testFile'] = realpath($this->arguments['test']);
  495. $this->arguments['test'] = substr($this->arguments['test'], 0, strrpos($this->arguments['test'], '.'));
  496. }
  497. }
  498. if (isset($includePath))
  499. {
  500. ini_set('include_path', $includePath . PATH_SEPARATOR . ini_get('include_path'));
  501. }
  502. if (isset($this->arguments['bootstrap']))
  503. {
  504. $this->handleBootstrap($this->arguments['bootstrap'], $this->arguments['syntaxCheck']);
  505. }
  506. if ($this->arguments['loader'] !== NULL)
  507. {
  508. $this->arguments['loader'] = $this->handleLoader($this->arguments['loader']);
  509. }
  510. if (isset($this->arguments['configuration']) && is_dir($this->arguments['configuration']))
  511. {
  512. $configurationFile = $this->arguments['configuration'] . '/phpunit.xml';
  513. if (file_exists($configurationFile))
  514. {
  515. $this->arguments['configuration'] = realpath($configurationFile);
  516. }
  517. else
  518. if (file_exists($configurationFile . '.dist'))
  519. {
  520. $this->arguments['configuration'] = realpath($configurationFile . '.dist');
  521. }
  522. }
  523. else
  524. if (! isset($this->arguments['configuration']) && $this->arguments['useDefaultConfiguration'])
  525. {
  526. if (file_exists('phpunit.xml'))
  527. {
  528. $this->arguments['configuration'] = realpath('phpunit.xml');
  529. }
  530. else
  531. if (file_exists('phpunit.xml.dist'))
  532. {
  533. $this->arguments['configuration'] = realpath('phpunit.xml.dist');
  534. }
  535. }
  536. if (isset($this->arguments['configuration']))
  537. {
  538. $configuration = PHPUnit_Util_Configuration :: getInstance($this->arguments['configuration']);
  539. $phpunit = $configuration->getPHPUnitConfiguration();
  540. if (isset($phpunit['syntaxCheck']))
  541. {
  542. $this->arguments['syntaxCheck'] = $phpunit['syntaxCheck'];
  543. }
  544. if (isset($phpunit['testSuiteLoaderClass']))
  545. {
  546. if (isset($phpunit['testSuiteLoaderFile']))
  547. {
  548. $file = $phpunit['testSuiteLoaderFile'];
  549. }
  550. else
  551. {
  552. $file = '';
  553. }
  554. $this->arguments['loader'] = $this->handleLoader($phpunit['testSuiteLoaderClass'], $file);
  555. }
  556. $configuration->handlePHPConfiguration();
  557. if (! isset($this->arguments['bootstrap']))
  558. {
  559. $phpunitConfiguration = $configuration->getPHPUnitConfiguration();
  560. if (isset($phpunitConfiguration['bootstrap']))
  561. {
  562. $this->handleBootstrap($phpunitConfiguration['bootstrap'], $this->arguments['syntaxCheck']);
  563. }
  564. }
  565. $browsers = $configuration->getSeleniumBrowserConfiguration();
  566. if (! empty($browsers))
  567. {
  568. PHPUnit_Extensions_SeleniumTestCase :: $browsers = $browsers;
  569. }
  570. if (! isset($this->arguments['test']))
  571. {
  572. $testSuite = $configuration->getTestSuiteConfiguration($this->arguments['syntaxCheck']);
  573. if ($testSuite !== NULL)
  574. {
  575. $this->arguments['test'] = $testSuite;
  576. }
  577. }
  578. }
  579. if (isset($this->arguments['test']) && is_string($this->arguments['test']) && substr($this->arguments['test'], - 5, 5) == '.phpt')
  580. {
  581. $test = new PHPUnit_Extensions_PhptTestCase($this->arguments['test']);
  582. $this->arguments['test'] = new PHPUnit_Framework_TestSuite();
  583. $this->arguments['test']->addTest($test);
  584. }
  585. if (! isset($this->arguments['test']) || (isset($this->arguments['testDatabaseLogRevision']) && ! isset($this->arguments['testDatabaseDSN'])))
  586. {
  587. $this->showHelp();
  588. exit(PHPUnit_TextUI_TestRunner :: EXCEPTION_EXIT);
  589. }
  590. if (! isset($this->arguments['syntaxCheck']))
  591. {
  592. $this->arguments['syntaxCheck'] = FALSE;
  593. }
  594. if ($skeletonClass || $skeletonTest)
  595. {
  596. if (isset($this->arguments['test']) && $this->arguments['test'] !== FALSE)
  597. {
  598. PHPUnit_TextUI_TestRunner :: printVersionString();
  599. if ($skeletonClass)
  600. {
  601. $class = 'PHPUnit_Util_Skeleton_Class';
  602. }
  603. else
  604. {
  605. $class = 'PHPUnit_Util_Skeleton_Test';
  606. }
  607. try
  608. {
  609. $args = array();
  610. $reflector = new ReflectionClass($class);
  611. for($i = 0; $i <= 3; $i ++)
  612. {
  613. if (isset($this->options[1][$i]))
  614. {
  615. $args[] = $this->options[1][$i];
  616. }
  617. }
  618. $skeleton = $reflector->newInstanceArgs($args);
  619. $skeleton->write();
  620. }
  621. catch (Exception $e)
  622. {
  623. print $e->getMessage() . "\n";
  624. exit(PHPUnit_TextUI_TestRunner :: FAILURE_EXIT);
  625. }
  626. printf('Wrote skeleton for "%s" to "%s".' . "\n", $skeleton->getOutClassName(), $skeleton->getOutSourceFile());
  627. exit(PHPUnit_TextUI_TestRunner :: SUCCESS_EXIT);
  628. }
  629. else
  630. {
  631. $this->showHelp();
  632. exit(PHPUnit_TextUI_TestRunner :: EXCEPTION_EXIT);
  633. }
  634. }
  635. }
  636. /**
  637. * Handles the loading of the PHPUnit_Runner_TestSuiteLoader implementation.
  638. *
  639. * @param string $loaderClass
  640. * @param string $loaderFile
  641. */
  642. protected function handleLoader($loaderClass, $loaderFile = '')
  643. {
  644. if (! class_exists($loaderClass, FALSE))
  645. {
  646. if ($loaderFile == '')
  647. {
  648. $loaderFile = PHPUnit_Util_Filesystem :: classNameToFilename($loaderClass);
  649. }
  650. $loaderFile = PHPUnit_Util_Filesystem :: fileExistsInIncludePath($loaderFile);
  651. if ($loaderFile !== FALSE)
  652. {
  653. require $loaderFile;
  654. }
  655. }
  656. if (class_exists($loaderClass, FALSE))
  657. {
  658. $class = new ReflectionClass($loaderClass);
  659. if ($class->implementsInterface('PHPUnit_Runner_TestSuiteLoader') && $class->isInstantiable())
  660. {
  661. $loader = $class->newInstance();
  662. }
  663. }
  664. if (! isset($loader))
  665. {
  666. PHPUnit_TextUI_TestRunner :: showError(sprintf('Could not use "%s" as loader.',
  667. $loaderClass));
  668. }
  669. return $loader;
  670. }
  671. /**
  672. * Loads a bootstrap file.
  673. *
  674. * @param string $filename
  675. * @param boolean $syntaxCheck
  676. */
  677. protected function handleBootstrap($filename, $syntaxCheck = FALSE)
  678. {
  679. try
  680. {
  681. PHPUnit_Util_Fileloader :: checkAndLoad($filename, $syntaxCheck);
  682. }
  683. catch (RuntimeException $e)
  684. {
  685. PHPUnit_TextUI_TestRunner :: showError($e->getMessage());
  686. }
  687. }
  688. /**
  689. * Shows a message.
  690. *
  691. * @param string $message
  692. * @param boolean $exit
  693. */
  694. protected function showMessage($message, $exit = TRUE)
  695. {
  696. PHPUnit_TextUI_TestRunner :: printVersionString();
  697. print $message . "\n";
  698. if ($exit)
  699. {
  700. exit(PHPUnit_TextUI_TestRunner :: EXCEPTION_EXIT);
  701. }
  702. else
  703. {
  704. print "\n";
  705. }
  706. }
  707. /**
  708. * Show the help message.
  709. */
  710. protected function showHelp()
  711. {
  712. PHPUnit_TextUI_TestRunner :: printVersionString();
  713. print <<<EOT
  714. Usage: phpunit [switches] UnitTest [UnitTest.php]
  715. phpunit [switches] <directory>
  716. --log-junit <file> Log test execution in JUnit XML format to file.
  717. --log-tap <file> Log test execution in TAP format to file.
  718. --log-dbus Log test execution to DBUS.
  719. --log-json <file> Log test execution in JSON format.
  720. --coverage-html <dir> Generate code coverage report in HTML format.
  721. --coverage-clover <file> Write code coverage data in Clover XML format.
  722. --testdox-html <file> Write agile documentation in HTML format to file.
  723. --testdox-text <file> Write agile documentation in Text format to file.
  724. --filter <pattern> Filter which tests to run.
  725. --group ... Only runs tests from the specified group(s).
  726. --exclude-group ... Exclude tests from the specified group(s).
  727. --list-groups List available test groups.
  728. --loader <loader> TestSuiteLoader implementation to use.
  729. --repeat <times> Runs the test(s) repeatedly.
  730. --tap Report test execution progress in TAP format.
  731. --testdox Report test execution progress in TestDox format.
  732. --colors Use colors in output.
  733. --stderr Write to STDERR instead of STDOUT.
  734. --stop-on-error Stop execution upon first error.
  735. --stop-on-failure Stop execution upon first error or failure.
  736. --stop-on-skipped Stop execution upon first skipped test.
  737. --stop-on-incomplete Stop execution upon first incomplete test.
  738. --strict Mark a test as incomplete if no assertions are made.
  739. --verbose Output more verbose information.
  740. --wait Waits for a keystroke after each test.
  741. --skeleton-class Generate Unit class for UnitTest in UnitTest.php.
  742. --skeleton-test Generate UnitTest class for Unit in Unit.php.
  743. --process-isolation Run each test in a separate PHP process.
  744. --no-globals-backup Do not backup and restore \$GLOBALS for each test.
  745. --static-backup Backup and restore static attributes for each test.
  746. --syntax-check Try to check source files for syntax errors.
  747. --bootstrap <file> A "bootstrap" PHP file that is run before the tests.
  748. --configuration <file> Read configuration from XML file.
  749. --no-configuration Ignore default configuration file (phpunit.xml).
  750. --include-path <path(s)> Prepend PHP's include_path with given path(s).
  751. -d key[=value] Sets a php.ini value.
  752. --help Prints this usage information.
  753. --version Prints the version and exits.
  754. EOT;
  755. }
  756. /**
  757. * Custom callback for test suite discovery.
  758. */
  759. protected function handleCustomTestSuite()
  760. {
  761. }
  762. }