BinTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace React\Tests\EventLoop;
  3. class BinTest extends TestCase
  4. {
  5. /**
  6. * @before
  7. */
  8. public function setUpBin()
  9. {
  10. if (!defined('PHP_BINARY') || defined('HHVM_VERSION')) {
  11. $this->markTestSkipped('Tests not supported on legacy PHP 5.3 or HHVM');
  12. }
  13. chdir(__DIR__ . '/bin/');
  14. }
  15. public function testExecuteExampleWithoutLoopRunRunsLoopAndExecutesTicks()
  16. {
  17. $output = exec(escapeshellarg(PHP_BINARY) . ' 01-ticks-loop-class.php');
  18. $this->assertEquals('abc', $output);
  19. }
  20. public function testExecuteExampleWithExplicitLoopRunRunsLoopAndExecutesTicks()
  21. {
  22. $output = exec(escapeshellarg(PHP_BINARY) . ' 02-ticks-loop-instance.php');
  23. $this->assertEquals('abc', $output);
  24. }
  25. public function testExecuteExampleWithExplicitLoopRunAndStopRunsLoopAndExecutesTicksUntilStopped()
  26. {
  27. $output = exec(escapeshellarg(PHP_BINARY) . ' 03-ticks-loop-stop.php');
  28. $this->assertEquals('abc', $output);
  29. }
  30. public function testExecuteExampleWithUncaughtExceptionShouldNotRunLoop()
  31. {
  32. $time = microtime(true);
  33. exec(escapeshellarg(PHP_BINARY) . ' 11-uncaught.php 2>/dev/null');
  34. $time = microtime(true) - $time;
  35. $this->assertLessThan(1.0, $time);
  36. }
  37. public function testExecuteExampleWithUndefinedVariableShouldNotRunLoop()
  38. {
  39. $time = microtime(true);
  40. exec(escapeshellarg(PHP_BINARY) . ' 12-undefined.php 2>/dev/null');
  41. $time = microtime(true) - $time;
  42. $this->assertLessThan(1.0, $time);
  43. }
  44. public function testExecuteExampleWithExplicitStopShouldNotRunLoop()
  45. {
  46. $time = microtime(true);
  47. exec(escapeshellarg(PHP_BINARY) . ' 21-stop.php 2>/dev/null');
  48. $time = microtime(true) - $time;
  49. $this->assertLessThan(1.0, $time);
  50. }
  51. public function testExecuteExampleWithExplicitStopInExceptionHandlerShouldNotRunLoop()
  52. {
  53. $time = microtime(true);
  54. exec(escapeshellarg(PHP_BINARY) . ' 22-uncaught-stop.php 2>/dev/null');
  55. $time = microtime(true) - $time;
  56. $this->assertLessThan(1.0, $time);
  57. }
  58. }