Task_Runner_Test.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * PhpUnderControl_TaskRunner_Test
  4. *
  5. * 针对 ../Runner.php Task_Runner 类的PHPUnit单元测试
  6. *
  7. * @author: dogstar 20150515
  8. */
  9. require_once dirname(__FILE__) . '/bootstrap.php';
  10. class PhpUnderControl_TaskRunner_Test extends PHPUnit_Framework_TestCase
  11. {
  12. protected $fileMq;
  13. public $taskRunner;
  14. protected function setUp()
  15. {
  16. parent::setUp();
  17. $this->fileMq = new PhalApi\Task\MQ\FileMQ();
  18. $this->taskRunner = new Task_Runner_Mock($this->fileMq);
  19. }
  20. protected function tearDown()
  21. {
  22. }
  23. /**
  24. * @group testGo
  25. */
  26. public function testGo()
  27. {
  28. $service = 'Demo.TestGo';
  29. $this->fileMq->add($service, array());
  30. $this->fileMq->add($service, array('id' => 123));
  31. $this->fileMq->add($service, array('id' => 888, 'name' => 'phalapi'));
  32. $rs = $this->taskRunner->go($service);
  33. //var_dump($rs);
  34. $this->assertNotEmpty($rs);
  35. $this->assertArrayHasKey('total', $rs);
  36. $this->assertArrayHasKey('fail', $rs);
  37. $this->assertEquals(3, $rs['total']);
  38. $this->assertEquals(0, $rs['fail']);
  39. }
  40. }
  41. class Task_Runner_Mock extends PhalApi\Task\Runner {
  42. protected function youGo($service, $params) {
  43. echo "Task_Runner_Mock::youGo(", $service , ", ", json_encode($params), ") ... \n";
  44. return true;
  45. }
  46. }