PhpUnitAnalyzer.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\Troubleshooting;
  7. use Magento\Mtf\ObjectManagerInterface;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. /**
  11. * PHPUnit analyzer based on the URL specified in the phpunit.xml.
  12. */
  13. class PhpUnitAnalyzer extends \Symfony\Component\Console\Command\Command
  14. {
  15. /**
  16. * Object manager instance.
  17. *
  18. * @var ObjectManagerInterface
  19. */
  20. private $objectManager;
  21. /**
  22. * @param ObjectManagerInterface $objectManager
  23. */
  24. public function __construct(ObjectManagerInterface $objectManager)
  25. {
  26. parent::__construct();
  27. $this->objectManager = $objectManager;
  28. }
  29. /**
  30. * Configure command.
  31. *
  32. * @return void
  33. */
  34. protected function configure()
  35. {
  36. parent::configure();
  37. $this->setName('troubleshooting:check-phpunit-config-file')
  38. ->setDescription('Check if phpunit file is available.');
  39. }
  40. /**
  41. * Execute command for checkout phpunit.xml config file availability.
  42. *
  43. * @param InputInterface $input
  44. * @param OutputInterface $output
  45. * @return void
  46. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  47. */
  48. protected function execute(InputInterface $input, OutputInterface $output)
  49. {
  50. $output = $this->objectManager->create(
  51. \Magento\Mtf\Console\Output::class,
  52. ['output' => $output]
  53. );
  54. $output->writeln("Checking phpunit.xml file availability...");
  55. $messages = [];
  56. $configFileExists = false;
  57. if (file_exists(MTF_PHPUNIT_FILE)) {
  58. $configFileExists = true;
  59. } else {
  60. if (file_exists(MTF_PHPUNIT_FILE . '.dist')) {
  61. if (!copy(MTF_PHPUNIT_FILE . '.dist', MTF_PHPUNIT_FILE)) {
  62. $messages['error'][] = 'Failed to copy phpunit.xml.dist to phpunit.xml.';
  63. } else {
  64. $messages['info'][] = 'phpunit.xml file has been created based on phpunit.xml.dist. '
  65. . 'Please, adjust your PHPUnit configuration to use new file.';
  66. $configFileExists = true;
  67. }
  68. }
  69. }
  70. if (!$configFileExists) {
  71. $messages['error'][] = 'Cannot define phpunit configuration path.';
  72. }
  73. $output->outputMessages($messages);
  74. $output->writeln("phpunit.xml check finished.");
  75. }
  76. }