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

CKEditorScriptHandlerTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 104
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\Composer;
13
14
use Composer\Composer;
15
use Composer\Config;
16
use Composer\IO\IOInterface;
17
use Composer\Package\Package;
18
use Composer\Script\CommandEvent;
19
use Composer\Script\Event;
20
use Ivory\CKEditorBundle\Composer\CKEditorScriptHandler;
21
use Ivory\CKEditorBundle\Installer\CKEditorInstaller;
22
use Ivory\CKEditorBundle\Tests\AbstractTestCase;
23
24
/**
25
 * @author GeLo <[email protected]>
26
 */
27
class CKEditorScriptHandlerTest extends AbstractTestCase
28
{
29
    /**
30
     * @var string
31
     */
32
    private $path;
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function setUp()
38
    {
39
        $this->path = __DIR__.'/../../src/Resources/public';
40
41
        $this->tearDown();
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function tearDown()
48
    {
49
        if (file_exists($this->path)) {
50
            exec('rm -rf '.$this->path);
51
        }
52
    }
53
54
    public function testInstall()
55
    {
56
        CKEditorScriptHandler::install($this->createEventMock());
57
        $this->assertInstall();
58
    }
59
60
    public function testReinstall()
61
    {
62
        CKEditorScriptHandler::install($this->createEventMock());
63
        $this->assertInstall();
64
65
        CKEditorScriptHandler::install($this->createEventMock());
66
        $this->assertInstall();
67
    }
68
69
    /**
70
     * @return \PHPUnit_Framework_MockObject_MockObject|Event
71
     */
72
    private function createEventMock()
73
    {
74
        $config = $this->createMock(Config::class);
75
        $config
76
            ->expects($this->any())
77
            ->method('get')
78
            ->will($this->returnValueMap([
79
                ['process-timeout', 300],
80
                ['vendor-dir', __DIR__.'/../../vendor'],
81
            ]));
82
83
        $package = $this->getMockBuilder(Package::class)
84
            ->disableOriginalConstructor()
85
            ->getMock();
86
87
        $package
88
            ->expects($this->any())
89
            ->method('getExtra')
90
            ->will($this->returnValue([
91
                'ckeditor-clear' => CKEditorInstaller::CLEAR_DROP,
92
                'symfony-bin-dir' => __DIR__.'/../Fixtures',
93
                'symfony-var-dir' => __DIR__.'/../Fixtures',
94
            ]));
95
96
        $composer = $this->createMock(Composer::class);
97
        $composer
98
            ->expects($this->any())
99
            ->method('getConfig')
100
            ->will($this->returnValue($config));
101
102
        $composer
103
            ->expects($this->any())
104
            ->method('getPackage')
105
            ->will($this->returnValue($package));
106
107
        $io = $this->createMock(IOInterface::class);
108
109
        $event = $this->getMockBuilder(class_exists(CommandEvent::class) ? CommandEvent::class : Event::class)
110
            ->disableOriginalConstructor()
111
            ->getMock();
112
113
        $event
114
            ->expects($this->any())
115
            ->method('getComposer')
116
            ->will($this->returnValue($composer));
117
118
        $event
119
            ->expects($this->any())
120
            ->method('getIO')
121
            ->will($this->returnValue($io));
122
123
        return $event;
124
    }
125
126
    private function assertInstall()
127
    {
128
        $this->assertFileExists($this->path.'/ckeditor.js');
129
    }
130
}
131