22
33namespace FM \BbcodeBundle \Tests \Command ;
44
5+ use FM \BbcodeBundle \Command \DumpEmoticonsCommand ;
56use PHPUnit \Framework \TestCase ;
67use Symfony \Component \Console \Tester \CommandTester ;
7- use FM \BbcodeBundle \Command \DumpEmoticonsCommand ;
8- use Symfony \Component \DependencyInjection \ContainerInterface ;
98
109/**
1110 * @author Alexandre Quercia <alquerci@email.com>
1211 */
1312class DumpEmoticonsCommandTest extends TestCase
1413{
14+ private $ emoticonFolder ;
15+
16+ private $ emoticonPath ;
17+
1518 private $ rootDir ;
19+
1620 private $ webDir ;
17- private $ emoticonPath ;
18- private $ emoticonFolder ;
1921
2022 public function setUp (): void
2123 {
22- $ this ->rootDir = __DIR__ . '/.. ' ;
23- $ this ->webDir = sys_get_temp_dir (). '/symfonyFMBbcodeweb ' ;
24+ $ this ->rootDir = __DIR__ . '/.. ' ;
25+ $ this ->webDir = sys_get_temp_dir () . '/symfonyFMBbcodeweb ' ;
2426 if (!file_exists ($ this ->webDir )) {
2527 mkdir ($ this ->webDir );
2628 }
27- $ this ->emoticonPath = '/emoticons ' ;
28- $ this ->emoticonFolder = $ this ->rootDir . '/../vendor/mjohnson/decoda/emoticons ' ;
29+ $ this ->emoticonPath = '/emoticons ' ;
30+ $ this ->emoticonFolder = $ this ->rootDir . '/../vendor/mjohnson/decoda/emoticons ' ;
2931 }
3032
3133 public function tearDown (): void
@@ -36,9 +38,23 @@ public function tearDown(): void
3638 $ this ->removeDirectory ($ this ->webDir );
3739 }
3840
41+ public function testExecute (): void
42+ {
43+ $ command = new DumpEmoticonsCommand ($ this ->webDir , $ this ->emoticonPath , $ this ->emoticonFolder );
44+
45+ $ tester = new CommandTester ($ command );
46+ $ tester ->execute ([]);
47+
48+ $ this ->assertFileExists ($ this ->webDir . $ this ->emoticonPath );
49+ $ this ->assertEquals ('Emoticons dumped succesfully ' . PHP_EOL , $ tester ->getDisplay ());
50+ }
51+
3952 protected function removeDirectory ($ directory ): void
4053 {
41- $ iterator = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ directory ), \RecursiveIteratorIterator::CHILD_FIRST );
54+ $ iterator = new \RecursiveIteratorIterator (
55+ new \RecursiveDirectoryIterator ($ directory ),
56+ \RecursiveIteratorIterator::CHILD_FIRST
57+ );
4258 foreach ($ iterator as $ path ) {
4359 if (preg_match ('#[/ \\\\]\.\.?$# ' , $ path ->__toString ())) {
4460 continue ;
@@ -51,42 +67,4 @@ protected function removeDirectory($directory): void
5167 }
5268 @rmdir ($ directory );
5369 }
54-
55- public function testExecute (): void
56- {
57- $ webDir = $ this ->webDir ;
58- $ emoticonPath = $ this ->emoticonPath ;
59- $ rootDir = $ this ->rootDir ;
60- $ emoticonFolder = $ this ->emoticonFolder ;
61-
62- $ container = $ this ->createMock (ContainerInterface::class);
63- $ container
64- ->expects ($ this ->any ())
65- ->method ('getParameter ' )
66- ->withAnyParameters ()
67- ->will ($ this ->returnCallback (function ($ v ) use ($ webDir , $ emoticonPath , $ rootDir , $ emoticonFolder ) {
68- switch ($ v ) {
69- case 'fm_bbcode.public_path ' :
70- return $ webDir ;
71- case 'fm_bbcode.emoticon.path ' :
72- return $ emoticonPath ;
73- case 'fm_bbcode.emoticon.folder ' :
74- return $ emoticonFolder ;
75- case 'kernel.root_dir ' :
76- return $ rootDir ;
77- default :
78- throw new \RuntimeException (sprintf ('Unknown parameter "%s". ' , $ v ));
79- }
80- }))
81- ;
82-
83- $ command = new DumpEmoticonsCommand ();
84- $ command ->setContainer ($ container );
85-
86- $ tester = new CommandTester ($ command );
87- $ tester ->execute (array ());
88-
89- $ this ->assertFileExists ($ this ->webDir .$ this ->emoticonPath );
90- $ this ->assertEquals ('Emoticons dumped succesfully ' .PHP_EOL , $ tester ->getDisplay ());
91- }
9270}
0 commit comments