Completed
Pull Request — master (#47)
by Maximilian
392:42 queued 327:39
created

CKEditorInstallerCommandTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 71
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\CKEditorBundle\Tests\Command;
13
14
use Ivory\CKEditorBundle\Command\CKEditorInstallerCommand;
15
use Ivory\CKEditorBundle\Installer\CKEditorInstaller;
16
use Ivory\CKEditorBundle\Tests\AbstractTestCase;
17
use Symfony\Component\Console\Application;
18
use Symfony\Component\Console\Tester\CommandTester;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class CKEditorInstallerCommandTest extends AbstractTestCase
24
{
25
    /**
26
     * @var Application
27
     */
28
    private $application;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function setUp()
34
    {
35
        $this->application = new Application();
36
        $this->application->addCommands([new CKEditorInstallerCommand()]);
37
38
        $this->tearDown();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function tearDown()
45
    {
46
        if (file_exists($path = __DIR__.'/../../Resources/public')) {
47
            exec('rm -rf '.$path);
48
        }
49
    }
50
51
    /**
52
     * @group installation
53
     */
54
    public function testInstall()
55
    {
56
        $command = $this->application->find('ckeditor:install');
57
58
        $tester = new CommandTester($command);
59
        $tester->execute(['command' => $command->getName()]);
60
61
        $this->assertInstall($tester);
62
    }
63
64
    /**
65
     * @group installation
66
     */
67
    public function testReinstall()
68
    {
69
        if (!method_exists(CommandTester::class, 'setInputs')) {
70
            $this->markTestSkipped();
71
        }
72
73
        $command = $this->application->find('ckeditor:install');
74
75
        $tester1 = new CommandTester($command);
76
        $tester1->execute($input = ['command' => $command->getName()]);
77
78
        $tester2 = new CommandTester($command);
79
        $tester2->setInputs([CKEditorInstaller::CLEAR_DROP]);
80
        $tester2->execute($input);
81
82
        $this->assertInstall($tester1);
83
        $this->assertInstall($tester2);
84
    }
85
86
    /**
87
     * @param CommandTester $tester
88
     */
89
    private function assertInstall(CommandTester $tester)
90
    {
91
        $this->assertContains('[OK] - CKEditor has been successfully installed...', $tester->getDisplay());
92
    }
93
}
94