I18nCollectPhrasesCommandTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Setup\Console\Command;
  7. use Symfony\Component\Console\Tester\CommandTester;
  8. class I18nCollectPhrasesCommandTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var I18nCollectPhrasesCommand
  12. */
  13. private $command;
  14. /**
  15. * @var CommandTester
  16. */
  17. private $tester;
  18. public function setUp()
  19. {
  20. $this->command = new I18nCollectPhrasesCommand();
  21. $this->tester = new CommandTester($this->command);
  22. }
  23. public function tearDown()
  24. {
  25. $property = new \ReflectionProperty(\Magento\Setup\Module\I18n\ServiceLocator::class, '_dictionaryGenerator');
  26. $property->setAccessible(true);
  27. $property->setValue(null);
  28. $property->setAccessible(false);
  29. }
  30. public function testExecuteConsoleOutput()
  31. {
  32. $this->tester->execute(
  33. [
  34. 'directory' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/',
  35. ]
  36. );
  37. $this->assertEquals('Dictionary successfully processed.' . PHP_EOL, $this->tester->getDisplay());
  38. }
  39. public function testExecuteCsvOutput()
  40. {
  41. $outputPath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/output/phrases.csv';
  42. $this->tester->execute(
  43. [
  44. 'directory' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/',
  45. '--output' => $outputPath,
  46. ]
  47. );
  48. $handle = fopen($outputPath, 'r');
  49. $output = fread($handle, filesize($outputPath));
  50. $expected = file_get_contents(
  51. BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv'
  52. );
  53. $this->assertEquals($expected, $output);
  54. unlink($outputPath);
  55. }
  56. /**
  57. * @expectedException \InvalidArgumentException
  58. * @expectedExceptionMessage Specified path doesn't exist
  59. */
  60. public function testExecuteNonExistingPath()
  61. {
  62. $this->tester->execute(
  63. [
  64. 'directory' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/non_exist',
  65. ]
  66. );
  67. }
  68. /**
  69. * @expectedException \InvalidArgumentException
  70. * @expectedExceptionMessage Directory path is not needed when --magento flag is set.
  71. */
  72. public function testExecuteMagentoFlagDirectoryPath()
  73. {
  74. $this->tester->execute(['directory' => 'a', '--magento' => true]);
  75. }
  76. /**
  77. * @expectedException \InvalidArgumentException
  78. * @expectedExceptionMessage Directory path is needed when --magento flag is not set.
  79. */
  80. public function testExecuteNoMagentoFlagNoDirectoryPath()
  81. {
  82. $this->tester->execute([]);
  83. }
  84. }