LimeTestCase.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the Lime framework.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. class LimeTestCase extends LimeTest
  12. {
  13. protected
  14. $testRunner = null;
  15. public function __construct($plan = null, array $options = array())
  16. {
  17. parent::__construct($plan, $options);
  18. $this->testRunner = new LimeTestRunner($this->getOutput());
  19. $this->testRunner->addBefore(array($this, 'setUp'));
  20. $this->testRunner->addAfter(array($this, 'tearDown'));
  21. // attention: the following lines are not tested
  22. $this->testRunner->addExceptionHandler(array($this, 'handleException'));
  23. $this->testRunner->addAfter(array($this, 'verifyException'));
  24. foreach (get_class_methods($this) as $method)
  25. {
  26. if (strpos($method, 'test') === 0 && strlen($method) > 4)
  27. {
  28. $this->testRunner->addTest(array($this, $method), $this->humanize($method));
  29. }
  30. }
  31. }
  32. public function setUp() {}
  33. public function tearDown() {}
  34. public function run()
  35. {
  36. $this->testRunner->run();
  37. }
  38. protected function humanize($method)
  39. {
  40. if (substr($method, 0, 4) == 'test')
  41. {
  42. $method = substr($method, 4);
  43. }
  44. $method = preg_replace('/([a-z])([A-Z])/', '$1 $2', $method);
  45. return ucfirst(strtolower($method));
  46. }
  47. }