|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Tests\Command; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Psr\Container\ContainerInterface; |
| 16 | +use Symfony\Bundle\FrameworkBundle\Command\EventDispatcherDebugCommand; |
| 17 | +use Symfony\Bundle\FrameworkBundle\Console\Application; |
| 18 | +use Symfony\Component\Console\Tester\CommandTester; |
| 19 | +use Symfony\Component\DependencyInjection\Container; |
| 20 | +use Symfony\Component\EventDispatcher\EventDispatcher; |
| 21 | +use Symfony\Component\HttpKernel\KernelInterface; |
| 22 | +use Symfony\Contracts\EventDispatcher\Event; |
| 23 | + |
| 24 | +class EventDispatcherDebugCommandTest extends TestCase |
| 25 | +{ |
| 26 | + private $fs; |
| 27 | + |
| 28 | + // public function testDumpMessagesAndClean() |
| 29 | + // { |
| 30 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); |
| 31 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]); |
| 32 | + // $this->assertMatchesRegularExpression('/foo/', $tester->getDisplay()); |
| 33 | + // $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); |
| 34 | + // } |
| 35 | + |
| 36 | + // public function testDumpMessagesAsTreeAndClean() |
| 37 | + // { |
| 38 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); |
| 39 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--as-tree' => 1]); |
| 40 | + // $this->assertMatchesRegularExpression('/foo/', $tester->getDisplay()); |
| 41 | + // $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); |
| 42 | + // } |
| 43 | + |
| 44 | + // public function testDumpSortedMessagesAndClean() |
| 45 | + // { |
| 46 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]); |
| 47 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'asc']); |
| 48 | + // $this->assertMatchesRegularExpression("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay())); |
| 49 | + // $this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay()); |
| 50 | + // } |
| 51 | + |
| 52 | + // public function testDumpReverseSortedMessagesAndClean() |
| 53 | + // { |
| 54 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]); |
| 55 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'desc']); |
| 56 | + // $this->assertMatchesRegularExpression("/\*test\*foo\*bar/", preg_replace('/\s+/', '', $tester->getDisplay())); |
| 57 | + // $this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay()); |
| 58 | + // } |
| 59 | + |
| 60 | + // public function testDumpSortWithoutValueAndClean() |
| 61 | + // { |
| 62 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]); |
| 63 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort']); |
| 64 | + // $this->assertMatchesRegularExpression("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay())); |
| 65 | + // $this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay()); |
| 66 | + // } |
| 67 | + |
| 68 | + // public function testDumpWrongSortAndClean() |
| 69 | + // { |
| 70 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]); |
| 71 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'test']); |
| 72 | + // $this->assertMatchesRegularExpression('/\[ERROR\] Wrong sort order/', $tester->getDisplay()); |
| 73 | + // } |
| 74 | + |
| 75 | + // public function testDumpMessagesAndCleanInRootDirectory() |
| 76 | + // { |
| 77 | + // $this->fs->remove($this->translationDir); |
| 78 | + // $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true); |
| 79 | + // $this->fs->mkdir($this->translationDir.'/translations'); |
| 80 | + // $this->fs->mkdir($this->translationDir.'/templates'); |
| 81 | + |
| 82 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']], [], null, [$this->translationDir.'/trans'], [$this->translationDir.'/views']); |
| 83 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]); |
| 84 | + // $this->assertMatchesRegularExpression('/foo/', $tester->getDisplay()); |
| 85 | + // $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); |
| 86 | + // } |
| 87 | + |
| 88 | + // public function testDumpTwoMessagesAndClean() |
| 89 | + // { |
| 90 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'bar' => 'bar']]); |
| 91 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]); |
| 92 | + // $this->assertMatchesRegularExpression('/foo/', $tester->getDisplay()); |
| 93 | + // $this->assertMatchesRegularExpression('/bar/', $tester->getDisplay()); |
| 94 | + // $this->assertMatchesRegularExpression('/2 messages were successfully extracted/', $tester->getDisplay()); |
| 95 | + // } |
| 96 | + |
| 97 | + // public function testDumpMessagesForSpecificDomain() |
| 98 | + // { |
| 99 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]); |
| 100 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--domain' => 'mydomain']); |
| 101 | + // $this->assertMatchesRegularExpression('/bar/', $tester->getDisplay()); |
| 102 | + // $this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay()); |
| 103 | + // } |
| 104 | + |
| 105 | + // public function testWriteMessages() |
| 106 | + // { |
| 107 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); |
| 108 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true]); |
| 109 | + // $this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay()); |
| 110 | + // } |
| 111 | + |
| 112 | + // public function testWriteMessagesInRootDirectory() |
| 113 | + // { |
| 114 | + // $this->fs->remove($this->translationDir); |
| 115 | + // $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true); |
| 116 | + // $this->fs->mkdir($this->translationDir.'/translations'); |
| 117 | + // $this->fs->mkdir($this->translationDir.'/templates'); |
| 118 | + |
| 119 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]); |
| 120 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', '--force' => true]); |
| 121 | + // $this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay()); |
| 122 | + // } |
| 123 | + |
| 124 | + // public function testWriteMessagesForSpecificDomain() |
| 125 | + // { |
| 126 | + // $tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]); |
| 127 | + // $tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true, '--domain' => 'mydomain']); |
| 128 | + // $this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay()); |
| 129 | + // } |
| 130 | + |
| 131 | + private function createCommandTester(): CommandTester |
| 132 | + { |
| 133 | + $kernel = $this->createMock(KernelInterface::class); |
| 134 | + |
| 135 | + $container = new Container(); |
| 136 | + |
| 137 | + $kernel |
| 138 | + ->expects($this->any()) |
| 139 | + ->method('getContainer') |
| 140 | + ->willReturn($container); |
| 141 | + |
| 142 | + $dispatcher = new EventDispatcher(); |
| 143 | + // $dispatcher->addListener(); |
| 144 | + |
| 145 | + $dispatchers = $this->createMock(ContainerInterface::class); |
| 146 | + |
| 147 | + $dispatchers |
| 148 | + ->expects($this->any()) |
| 149 | + ->method('has') |
| 150 | + ->willReturn(true); |
| 151 | + |
| 152 | + $dispatchers |
| 153 | + ->expects($this->any()) |
| 154 | + ->method('get') |
| 155 | + ->willReturn(true); |
| 156 | + |
| 157 | + $command = new EventDispatcherDebugCommand($dispatchers); |
| 158 | + |
| 159 | + $application = new Application($kernel); |
| 160 | + $application->add($command); |
| 161 | + |
| 162 | + return new CommandTester($application->find('debug:event-dispatcher')); |
| 163 | + } |
| 164 | +} |
0 commit comments