CommandRendererBackgroundTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Shell\Test\Unit;
  7. use \Magento\Framework\Shell\CommandRendererBackground;
  8. class CommandRendererBackgroundTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * Test data for command
  12. *
  13. * @var string
  14. */
  15. protected $testCommand = 'php -r test.php';
  16. /**
  17. * @var \Magento\Framework\OsInfo|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $osInfo;
  20. protected function setUp()
  21. {
  22. $this->osInfo = $this->getMockBuilder(\Magento\Framework\OsInfo::class)->getMock();
  23. }
  24. /**
  25. * @dataProvider commandPerOsTypeDataProvider
  26. * @param bool $isWindows
  27. * @param string $expectedResults
  28. */
  29. public function testRender($isWindows, $expectedResults)
  30. {
  31. $this->osInfo->expects($this->once())
  32. ->method('isWindows')
  33. ->will($this->returnValue($isWindows));
  34. $commandRenderer = new CommandRendererBackground($this->osInfo);
  35. $this->assertEquals(
  36. $expectedResults,
  37. $commandRenderer->render($this->testCommand)
  38. );
  39. }
  40. /**
  41. * Data provider for each os type
  42. *
  43. * @return array
  44. */
  45. public function commandPerOsTypeDataProvider()
  46. {
  47. return [
  48. 'windows' => [true, 'start /B "magento background task" ' . $this->testCommand . ' 2>&1'],
  49. 'unix' => [false, $this->testCommand . ' > /dev/null &'],
  50. ];
  51. }
  52. }