Completed
Pull Request — master (#40)
by Marko
198:30 queued 133:26
created

CKEditorScriptHandlerTest::createEventMock()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 53
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 9.5797
c 0
b 0
f 0
cc 2
eloc 40
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 FOS\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 FOS\CKEditorBundle\Composer\CKEditorScriptHandler;
21
use FOS\CKEditorBundle\Installer\CKEditorInstaller;
22
use FOS\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());
0 ignored issues
show
Bug introduced by
It seems like $this->createEventMock() targeting FOS\CKEditorBundle\Tests...Test::createEventMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\CKEditorBundle\Compo...criptHandler::install() does only seem to accept object<Composer\Script\Event>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
57
        $this->assertInstall();
58
    }
59
60
    public function testReinstall()
61
    {
62
        CKEditorScriptHandler::install($this->createEventMock());
0 ignored issues
show
Bug introduced by
It seems like $this->createEventMock() targeting FOS\CKEditorBundle\Tests...Test::createEventMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\CKEditorBundle\Compo...criptHandler::install() does only seem to accept object<Composer\Script\Event>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
63
        $this->assertInstall();
64
65
        CKEditorScriptHandler::install($this->createEventMock());
0 ignored issues
show
Bug introduced by
It seems like $this->createEventMock() targeting FOS\CKEditorBundle\Tests...Test::createEventMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\CKEditorBundle\Compo...criptHandler::install() does only seem to accept object<Composer\Script\Event>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
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