ProcessSpec.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace spec\Supervisor;
  3. use Supervisor\Connector;
  4. use PhpSpec\ObjectBehavior;
  5. class ProcessSpec extends ObjectBehavior
  6. {
  7. protected $process = [
  8. 'name' => 'process name',
  9. 'group' => 'group name',
  10. 'start' => 1200361776,
  11. 'stop' => 0,
  12. 'now' => 1200361812,
  13. 'state' => 20,
  14. 'statename' => 'RUNNING',
  15. 'spawnerr' => '',
  16. 'exitstatus' => 0,
  17. 'stdout_logfile' => '/path/to/stdout-log',
  18. 'stderr_logfile' => '/path/to/stderr-log',
  19. 'pid' => 1,
  20. ];
  21. function let(Connector $connector)
  22. {
  23. $this->beConstructedWith($this->process, $connector);
  24. }
  25. function it_is_initializable()
  26. {
  27. $this->shouldHaveType('Supervisor\Process');
  28. }
  29. function it_has_payload()
  30. {
  31. $this->getPayload()->shouldReturn($this->process);
  32. }
  33. function it_has_a_name()
  34. {
  35. $this->getName()->shouldReturn($this->process['name']);
  36. $this->offsetExists('name')->shouldReturn(true);
  37. $this->offsetGet('name')->shouldReturn($this->process['name']);
  38. $this->__toString()->shouldReturn($this->process['name']);
  39. }
  40. function it_checks_if_process_is_running()
  41. {
  42. $this->isRunning()->shouldReturn(true);
  43. }
  44. function it_checks_process_state()
  45. {
  46. $this->checkState(20)->shouldReturn(true);
  47. $this->checkState(2)->shouldReturn(false);
  48. }
  49. function it_throws_an_exception_when_being_altered_by_calling_offset_set()
  50. {
  51. $this->shouldThrow('LogicException')->duringOffsetSet('key', 'value');
  52. }
  53. function it_throws_an_exception_when_being_altered_by_calling_offset_unset()
  54. {
  55. $this->shouldThrow('LogicException')->duringOffsetUnset('key', 'value');
  56. }
  57. }