ResponsiveImageTestCase   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 16
lcom 2
cbo 6
dl 0
loc 87
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A bootSymfony() 0 7 1
A createDirectory() 0 6 2
B deleteDirectory() 0 19 5
A runCommand() 0 21 2
A getService() 0 10 2
A getParameters() 0 13 4
1
<?php
2
/**
3
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\Tests;
12
13
use Symfony\Component\Console\Application;
14
use Symfony\Component\Console\Input\ArrayInput;
15
use Symfony\Component\Console\Output\NullOutput;
16
use Symfony\Component\Yaml\Yaml;
17
18
class ResponsiveImageTestCase extends \PHPUnit_Framework_TestCase
19
{
20
    protected $testKernel;
21
    protected $parameters = [];
22
23
    protected function bootSymfony()
24
    {
25
        require_once __DIR__ . '/AppKernel.php';
26
27
        $this->testKernel = new \AppKernel('test', true);
28
        $this->testKernel->boot();
29
    }
30
31
    protected function createDirectory($directory)
32
    {
33
        if (!file_exists($directory)) {
34
            mkdir($directory, 0777, true);
35
        }
36
    }
37
38
    protected function deleteDirectory($directory)
39
    {
40
        if (!is_dir($directory)) {
41
            throw new \InvalidArgumentException("$directory must be a directory");
42
        }
43
        if (substr($directory, strlen($directory) - 1, 1) != '/') {
44
            $directory .= '/';
45
        }
46
        $files = glob($directory . '*', GLOB_MARK);
47
        foreach ($files as $file) {
48
            if (is_dir($file)) {
49
                self::deleteDirectory($file);
50
            }
51
            else {
52
                unlink($file);
53
            }
54
        }
55
        rmdir($directory);
56
    }
57
58
    protected function runCommand($name, $options = [])
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60
        if (empty($this->testKernel)) {
61
            $this->bootSymfony();
62
        }
63
64
        $application = new Application($this->testKernel);
0 ignored issues
show
Documentation introduced by
$this->testKernel is of type object<AppKernel>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
        $application->setAutoExit(false);
66
67
        $output = new NullOutput();
68
        $input  = new ArrayInput(
69
            [
70
                'name' => $name,
71
            ]
72
        );
73
        $input->setInteractive(false);
74
75
        $exitCode = $application->run($input, $output);
76
77
        return $exitCode;
78
    }
79
80
    protected function getService($serviceName)
81
    {
82
        if (empty($this->testKernel)) {
83
            $this->bootSymfony();
84
        }
85
86
        $container = $this->testKernel->getContainer();
87
88
        return $container->get($serviceName);
89
    }
90
91
    protected function getParameters($key = '')
92
    {
93
        if (empty($this->parameters)) {
94
            $path             = __DIR__ . '/config_test.yml';
95
            $this->parameters = Yaml::parse(file_get_contents($path));
96
        }
97
98
        if (empty($key)) {
99
            return $this->parameters;
100
        }
101
102
        return empty($this->parameters[$key]) ? [] : $this->parameters[$key];
103
    }
104
}