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 = []) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
if (empty($this->testKernel)) { |
61
|
|
|
$this->bootSymfony(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$application = new Application($this->testKernel); |
|
|
|
|
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
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.