-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathDumpEmoticonsCommandTest.php
More file actions
92 lines (81 loc) · 2.9 KB
/
DumpEmoticonsCommandTest.php
File metadata and controls
92 lines (81 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace FM\BbcodeBundle\Tests\Command;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use FM\BbcodeBundle\Command\DumpEmoticonsCommand;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @author Alexandre Quercia <alquerci@email.com>
*/
class DumpEmoticonsCommandTest extends TestCase
{
private $rootDir;
private $webDir;
private $emoticonPath;
private $emoticonFolder;
public function setUp()
{
$this->rootDir = __DIR__.'/..';
$this->webDir = sys_get_temp_dir().'/symfonyFMBbcodeweb';
if (!file_exists($this->webDir)) {
mkdir($this->webDir);
}
$this->emoticonPath = '/emoticons';
$this->emoticonFolder = $this->rootDir.'/../vendor/mjohnson/decoda/emoticons';
}
public function tearDown()
{
if (!is_dir($this->webDir)) {
return;
}
$this->removeDirectory($this->webDir);
}
protected function removeDirectory($directory)
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $path) {
if (preg_match('#[/\\\\]\.\.?$#', $path->__toString())) {
continue;
}
if ($path->isDir()) {
rmdir($path->__toString());
} else {
unlink($path->__toString());
}
}
@rmdir($directory);
}
public function testExecute()
{
$webDir = $this->webDir;
$emoticonPath = $this->emoticonPath;
$rootDir = $this->rootDir;
$emoticonFolder = $this->emoticonFolder;
$container = $this->createMock(ContainerInterface::class);
$container
->expects($this->any())
->method('getParameter')
->withAnyParameters()
->will($this->returnCallback(function ($v) use ($webDir, $emoticonPath, $rootDir, $emoticonFolder) {
switch ($v) {
case 'fm_bbcode.public_path':
return $webDir;
case 'fm_bbcode.emoticon.path':
return $emoticonPath;
case 'fm_bbcode.emoticon.folder':
return $emoticonFolder;
case 'kernel.root_dir':
return $rootDir;
default:
throw new \RuntimeException(sprintf('Unknown parameter "%s".', $v));
}
}))
;
$command = new DumpEmoticonsCommand();
$command->setContainer($container);
$tester = new CommandTester($command);
$tester->execute(array());
$this->assertFileExists($this->webDir.$this->emoticonPath);
$this->assertEquals('Emoticons dumped succesfully'.PHP_EOL, $tester->getDisplay());
}
}