EventTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Illuminate\Tests\Console\Scheduling;
  3. use Illuminate\Console\Scheduling\Event;
  4. use Illuminate\Console\Scheduling\EventMutex;
  5. use Mockery as m;
  6. use PHPUnit\Framework\TestCase;
  7. class EventTest extends TestCase
  8. {
  9. protected function tearDown(): void
  10. {
  11. m::close();
  12. parent::tearDown();
  13. }
  14. /**
  15. * @requires OS Linux|Darwin
  16. */
  17. public function testBuildCommandUsingUnix()
  18. {
  19. $event = new Event(m::mock(EventMutex::class), 'php -i');
  20. $this->assertSame("php -i > '/dev/null' 2>&1", $event->buildCommand());
  21. }
  22. /**
  23. * @requires OS Windows
  24. */
  25. public function testBuildCommandUsingWindows()
  26. {
  27. $event = new Event(m::mock(EventMutex::class), 'php -i');
  28. $this->assertSame('php -i > "NUL" 2>&1', $event->buildCommand());
  29. }
  30. /**
  31. * @requires OS Linux|Darwin
  32. */
  33. public function testBuildCommandInBackgroundUsingUnix()
  34. {
  35. $event = new Event(m::mock(EventMutex::class), 'php -i');
  36. $event->runInBackground();
  37. $scheduleId = '"framework'.DIRECTORY_SEPARATOR.'schedule-eeb46c93d45e928d62aaf684d727e213b7094822"';
  38. $this->assertSame("(php -i > '/dev/null' 2>&1 ; '".PHP_BINARY."' 'artisan' schedule:finish {$scheduleId} \"$?\") > '/dev/null' 2>&1 &", $event->buildCommand());
  39. }
  40. /**
  41. * @requires OS Windows
  42. */
  43. public function testBuildCommandInBackgroundUsingWindows()
  44. {
  45. $event = new Event(m::mock(EventMutex::class), 'php -i');
  46. $event->runInBackground();
  47. $scheduleId = '"framework'.DIRECTORY_SEPARATOR.'schedule-eeb46c93d45e928d62aaf684d727e213b7094822"';
  48. $this->assertSame('start /b cmd /v:on /c "(php -i & "'.PHP_BINARY.'" artisan schedule:finish '.$scheduleId.' ^!ERRORLEVEL^!) > "NUL" 2>&1"', $event->buildCommand());
  49. }
  50. public function testBuildCommandSendOutputTo()
  51. {
  52. $quote = (DIRECTORY_SEPARATOR === '\\') ? '"' : "'";
  53. $event = new Event(m::mock(EventMutex::class), 'php -i');
  54. $event->sendOutputTo('/dev/null');
  55. $this->assertSame("php -i > {$quote}/dev/null{$quote} 2>&1", $event->buildCommand());
  56. $event = new Event(m::mock(EventMutex::class), 'php -i');
  57. $event->sendOutputTo('/my folder/foo.log');
  58. $this->assertSame("php -i > {$quote}/my folder/foo.log{$quote} 2>&1", $event->buildCommand());
  59. }
  60. public function testBuildCommandAppendOutput()
  61. {
  62. $quote = (DIRECTORY_SEPARATOR === '\\') ? '"' : "'";
  63. $event = new Event(m::mock(EventMutex::class), 'php -i');
  64. $event->appendOutputTo('/dev/null');
  65. $this->assertSame("php -i >> {$quote}/dev/null{$quote} 2>&1", $event->buildCommand());
  66. }
  67. public function testNextRunDate()
  68. {
  69. $event = new Event(m::mock(EventMutex::class), 'php -i');
  70. $event->dailyAt('10:15');
  71. $this->assertSame('10:15:00', $event->nextRunDate()->toTimeString());
  72. }
  73. }