DevTestsRunCommandTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. // @codingStandardsIgnoreStart
  7. namespace Magento\Developer\Console\Command {
  8. use Symfony\Component\Console\Tester\CommandTester;
  9. $devTestsRunCommandTestPassthruReturnVar = null;
  10. /**
  11. * Mock for PHP builtin passthtru function
  12. *
  13. * @param string $command
  14. * @param int|null $return_var
  15. * @return void
  16. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  17. */
  18. function passthru($command, &$return_var = null)
  19. {
  20. global $devTestsRunCommandTestPassthruReturnVar;
  21. $return_var = $devTestsRunCommandTestPassthruReturnVar;
  22. }
  23. /**
  24. * Class DevTestsRunCommandTest
  25. *
  26. * Tests dev:tests:run command. Only tests error case because DevTestsRunCommand calls phpunit with
  27. * passthru, so there is no good way to mock out running the tests.
  28. */
  29. class DevTestsRunCommandTest extends \PHPUnit\Framework\TestCase
  30. {
  31. /**
  32. * @var DevTestsRunCommand
  33. */
  34. private $command;
  35. protected function setUp()
  36. {
  37. $this->command = new DevTestsRunCommand();
  38. }
  39. public function testExecuteBadType()
  40. {
  41. $commandTester = new CommandTester($this->command);
  42. $commandTester->execute([DevTestsRunCommand::INPUT_ARG_TYPE => 'bad']);
  43. $this->assertContains('Invalid type: "bad"', $commandTester->getDisplay());
  44. }
  45. public function testPassArgumentsToPHPUnit()
  46. {
  47. global $devTestsRunCommandTestPassthruReturnVar;
  48. $devTestsRunCommandTestPassthruReturnVar = 0;
  49. $commandTester = new CommandTester($this->command);
  50. $commandTester->execute(
  51. [
  52. DevTestsRunCommand::INPUT_ARG_TYPE => 'unit',
  53. '-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites',
  54. ]
  55. );
  56. $this->assertContains(
  57. 'phpunit --list-suites',
  58. $commandTester->getDisplay(),
  59. 'Parameters should be passed to PHPUnit'
  60. );
  61. $this->assertContains(
  62. 'PASSED (',
  63. $commandTester->getDisplay(),
  64. 'PHPUnit runs should have passed'
  65. );
  66. }
  67. public function testPassArgumentsToPHPUnitNegative()
  68. {
  69. global $devTestsRunCommandTestPassthruReturnVar;
  70. $devTestsRunCommandTestPassthruReturnVar = 255;
  71. $commandTester = new CommandTester($this->command);
  72. $commandTester->execute(
  73. [
  74. DevTestsRunCommand::INPUT_ARG_TYPE => 'unit',
  75. '-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites',
  76. ]
  77. );
  78. $this->assertContains(
  79. 'phpunit --list-suites',
  80. $commandTester->getDisplay(),
  81. 'Parameters should be passed to PHPUnit'
  82. );
  83. $this->assertContains(
  84. 'FAILED - ',
  85. $commandTester->getDisplay(),
  86. 'PHPUnit runs should have passed'
  87. );
  88. }
  89. }
  90. }