You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
1.4 KiB

  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__) . '/test_env.php';
  10. if (!class_exists('Task_Runner')) {
  11. require dirname(__FILE__) . '/../Runner.php';
  12. }
  13. class PhpUnderControl_TaskRunner_Test extends PHPUnit_Framework_TestCase
  14. {
  15. protected $fileMq;
  16. public $taskRunner;
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $this->fileMq = new Task_MQ_File();
  21. $this->taskRunner = new Task_Runner_Mock($this->fileMq);
  22. }
  23. protected function tearDown()
  24. {
  25. }
  26. /**
  27. * @group testGo
  28. */
  29. public function testGo()
  30. {
  31. $service = 'Demo.TestGo';
  32. $this->fileMq->add($service, array());
  33. $this->fileMq->add($service, array('id' => 123));
  34. $this->fileMq->add($service, array('id' => 888, 'name' => 'phalapi'));
  35. $rs = $this->taskRunner->go($service);
  36. //var_dump($rs);
  37. $this->assertNotEmpty($rs);
  38. $this->assertArrayHasKey('total', $rs);
  39. $this->assertArrayHasKey('fail', $rs);
  40. $this->assertEquals(3, $rs['total']);
  41. $this->assertEquals(0, $rs['fail']);
  42. }
  43. }
  44. class Task_Runner_Mock extends Task_Runner {
  45. protected function youGo($service, $params) {
  46. echo "Task_Runner_Mock::youGo(", $service , ", ", json_encode($params), ") ... \n";
  47. return true;
  48. }
  49. }