TestCase.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php namespace thiagoalessio\TesseractOCR\Tests\Common;
  2. class TestCase
  3. {
  4. public function run()
  5. {
  6. $results = array();
  7. if (method_exists($this, 'setUp')) $this->setUp();
  8. foreach ($this->getTests() as $test) {
  9. if (method_exists($this, 'beforeEach')) $this->beforeEach();
  10. try {
  11. $this->$test();
  12. $results[$test] = array('status' => 'pass');
  13. } catch (SkipException $e) {
  14. $results[$test] = array('status' => 'skip');
  15. } catch (\Exception $e) {
  16. $results[$test] = array('status' => 'fail', 'msg' => $e->getMessage());
  17. }
  18. if (method_exists($this, 'afterEach')) $this->afterEach();
  19. }
  20. if (method_exists($this, 'tearDown')) $this->tearDown();
  21. return $results;
  22. }
  23. protected function getTests()
  24. {
  25. $isTest = function ($name) { return preg_match('/^test/', $name); };
  26. $methods = get_class_methods(get_class($this));
  27. return array_filter($methods, $isTest);
  28. }
  29. protected function assertEquals($expected, $actual)
  30. {
  31. if ($expected != $actual) {
  32. throw new \Exception("\t\tExpected: $expected\n\t\t Actual: $actual");
  33. }
  34. }
  35. protected function skip()
  36. {
  37. throw new SkipException();
  38. }
  39. }
  40. class SkipException extends \Exception {}