Skip to content

Commit f179472

Browse files
committed
use correct sf version
1 parent 0e6f40e commit f179472

File tree

4 files changed

+58
-59
lines changed

4 files changed

+58
-59
lines changed

Tests/Command/DumpEmoticonsCommandTest.php

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@
22

33
namespace FM\BbcodeBundle\Tests\Command;
44

5+
use FM\BbcodeBundle\Command\DumpEmoticonsCommand;
56
use PHPUnit\Framework\TestCase;
67
use 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
*/
1312
class 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
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"symfony/config": "^4.4|^5.3",
2121
"symfony/console": "^4.4|^5.3",
2222
"symfony/dependency-injection": "^4.4|^5.3",
23-
"symfony/framework-bundle": "~3.2|~4.0",
24-
"symfony/http-foundation": "~3.2|~4.0",
23+
"symfony/framework-bundle": "^4.4|^5.3",
24+
"symfony/http-foundation": "^4.4|^5.3",
2525
"symfony/http-kernel": "^4.4|^5.3",
2626
"symfony/process": "^4.4|^5.3",
2727
"symfony/templating": "^4.4|^5.3",

src/Command/DumpEmoticonsCommand.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace FM\BbcodeBundle\Command;
44

5-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
5+
use Symfony\Component\Console\Command\Command;
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Input\InputOption;
88
use Symfony\Component\Console\Output\OutputInterface;
@@ -12,19 +12,38 @@
1212
* @copyright 2013 Al Ganiev
1313
* @license http://www.opensource.org/licenses/mit-license.php MIT License
1414
*/
15-
class DumpEmoticonsCommand extends ContainerAwareCommand
15+
class DumpEmoticonsCommand extends Command
1616
{
17+
/** @var string */
18+
private $emoticonFolder;
19+
20+
/** @var string */
21+
private $emoticonPath;
22+
23+
/** @var string */
24+
private $publicPath;
25+
26+
public function __construct(string $publicPath, string $emoticonPath, string $emoticonFolder)
27+
{
28+
$this->publicPath = $publicPath;
29+
$this->emoticonPath = $emoticonPath;
30+
$this->emoticonFolder = $emoticonFolder;
31+
32+
parent::__construct();
33+
}
34+
1735
/**
1836
* @see Command
1937
*/
2038
protected function configure()
2139
{
22-
$this
23-
->setName('bbcode:dump')
40+
$this->setName('bbcode:dump')
2441
->setDescription('Dumps the emoticons to their configured folder')
2542
->addOption('emoticons-folder', null, InputOption::VALUE_OPTIONAL);
2643
}
2744

45+
46+
2847
/**
2948
* @param InputInterface $input
3049
* @param OutputInterface $output
@@ -35,17 +54,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
3554
{
3655
$webFolder = sprintf(
3756
'%s%s',
38-
$this->getContainer()
39-
->getParameter('fm_bbcode.public_path'),
40-
$this->getContainer()
41-
->getParameter('fm_bbcode.emoticon.path')
57+
$this->publicPath,
58+
$this->emoticonPath
4259
);
4360
@mkdir($webFolder);
4461

4562
$emoticonsFolder = $input->getOption('emoticons-folder');
4663
if (!$emoticonsFolder) {
47-
$emoticonsFolder = $this->getContainer()
48-
->getParameter('fm_bbcode.emoticon.folder');
64+
$emoticonsFolder = $this->emoticonFolder;
4965
}
5066

5167
if (!file_exists($emoticonsFolder) && !is_dir($emoticonsFolder)) {

src/Resources/config/bbcode.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<argument key="default_locale">%kernel.default_locale%</argument>
3131
</argument>
3232
</service>
33+
<service id="FM\BbcodeBundle\Command\DumpEmoticonsCommand">
34+
<argument type="string" id="publicPath">%fm_bbcode.public_path%</argument>
35+
<argument type="string" id="emoticonPath">%fm_bbcode.emoticon.path%</argument>
36+
<argument type="string" id="emoticonFolder">%fm_bbcode.emoticon.folder%%</argument>
37+
</service>
3338
</services>
3439

3540
</container>

0 commit comments

Comments
 (0)