TestCase.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace React\Tests\EventLoop;
  3. use PHPUnit\Framework\TestCase as BaseTestCase;
  4. use React\EventLoop\LoopInterface;
  5. class TestCase extends BaseTestCase
  6. {
  7. protected function expectCallableExactly($amount)
  8. {
  9. $mock = $this->createCallableMock();
  10. $mock
  11. ->expects($this->exactly($amount))
  12. ->method('__invoke');
  13. return $mock;
  14. }
  15. protected function expectCallableOnce()
  16. {
  17. $mock = $this->createCallableMock();
  18. $mock
  19. ->expects($this->once())
  20. ->method('__invoke');
  21. return $mock;
  22. }
  23. protected function expectCallableNever()
  24. {
  25. $mock = $this->createCallableMock();
  26. $mock
  27. ->expects($this->never())
  28. ->method('__invoke');
  29. return $mock;
  30. }
  31. protected function createCallableMock()
  32. {
  33. if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
  34. // PHPUnit 9+
  35. return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
  36. } else {
  37. // legacy PHPUnit 4 - PHPUnit 9
  38. return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
  39. }
  40. }
  41. protected function tickLoop(LoopInterface $loop)
  42. {
  43. $loop->futureTick(function () use ($loop) {
  44. $loop->stop();
  45. });
  46. $loop->run();
  47. }
  48. }