|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the core-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2019 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Tests\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Exception; |
|
15
|
|
|
use InvalidArgumentException; |
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
17
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
|
18
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
19
|
|
|
use WBW\Bundle\CoreBundle\Command\CopySkeletonCommand; |
|
20
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractCommandTestCase; |
|
21
|
|
|
use WBW\Bundle\CoreBundle\Tests\Fixtures\Command\TestCopySkeletonCommand; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Copy skeleton command test. |
|
25
|
|
|
* |
|
26
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
27
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\Command |
|
28
|
|
|
*/ |
|
29
|
|
|
class CopySkeletonCommandTest extends AbstractCommandTestCase { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Tests the displayFooter() method. |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testDisplayFooter(): void { |
|
37
|
|
|
|
|
38
|
|
|
$obj = new TestCopySkeletonCommand(); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertNull($obj->displayFooter($this->style, 0, 1)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Tests the displayFooter() method. |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testDisplayFooterWithExitCode0(): void { |
|
49
|
|
|
|
|
50
|
|
|
$obj = new TestCopySkeletonCommand(); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertNull($obj->displayFooter($this->style, 0, 0)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Tests the displayFooter() method. |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testDisplayFooterWithExitCode1(): void { |
|
61
|
|
|
|
|
62
|
|
|
$obj = new TestCopySkeletonCommand(); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertNull($obj->displayFooter($this->style, 1, 0)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Tests the displayResult() method. |
|
69
|
|
|
* |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testDisplayResult(): void { |
|
73
|
|
|
|
|
74
|
|
|
$obj = new TestCopySkeletonCommand(); |
|
75
|
|
|
|
|
76
|
|
|
$arg = []; |
|
77
|
|
|
$this->assertEquals(0, $obj->displayResult($this->style, $arg)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Tests the displayResult() method. |
|
82
|
|
|
* |
|
83
|
|
|
* @return void |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testDisplayResultWithExitCode(): void { |
|
86
|
|
|
|
|
87
|
|
|
$obj = new TestCopySkeletonCommand(); |
|
88
|
|
|
|
|
89
|
|
|
$arg = [ |
|
90
|
|
|
"WBWCoreBundle" => [ |
|
91
|
|
|
"animate.css-3.5.2.zip" => false, |
|
92
|
|
|
], |
|
93
|
|
|
]; |
|
94
|
|
|
$this->assertEquals(1, $obj->displayResult($this->style, $arg)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Tests the getResourcesDirectory() method. |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
|
|
public function testGetResourcesDirectory(): void { |
|
103
|
|
|
|
|
104
|
|
|
// Set an Helper set mock. |
|
105
|
|
|
$helperSet = $this->getMockBuilder(HelperSet::class)->disableOriginalConstructor()->getMock(); |
|
106
|
|
|
|
|
107
|
|
|
// Set an Application mock. |
|
108
|
|
|
$application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock(); |
|
109
|
|
|
$application->expects($this->any())->method("getHelperSet")->willReturn($helperSet); |
|
110
|
|
|
$application->expects($this->any())->method("getKernel")->willReturn($this->kernel); |
|
111
|
|
|
|
|
112
|
|
|
$obj = new TestCopySkeletonCommand(); |
|
113
|
|
|
$obj->setApplication($application); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
if (40000 <= Kernel::VERSION_ID) { |
|
116
|
|
|
$this->assertRegExp("/\/templates\/bundles$/", $obj->getResourcesDirectory()); |
|
|
|
|
|
|
117
|
|
|
} else { |
|
118
|
|
|
$this->assertRegExp("/\/app\/Resources$/", $obj->getResourcesDirectory()); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Tests the getResourcesDirectory() method. |
|
124
|
|
|
* |
|
125
|
|
|
* @return void |
|
126
|
|
|
*/ |
|
127
|
|
|
public function testGetResourcesDirectoryWithInvalidArgumentException(): void { |
|
128
|
|
|
|
|
129
|
|
|
// Set an Helper set mock. |
|
130
|
|
|
$helperSet = $this->getMockBuilder(HelperSet::class)->disableOriginalConstructor()->getMock(); |
|
131
|
|
|
|
|
132
|
|
|
// Set an Application mock. |
|
133
|
|
|
$application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock(); |
|
134
|
|
|
$application->expects($this->any())->method("getHelperSet")->willReturn($helperSet); |
|
135
|
|
|
|
|
136
|
|
|
$obj = new TestCopySkeletonCommand(); |
|
137
|
|
|
$obj->setApplication($application); |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
try { |
|
140
|
|
|
|
|
141
|
|
|
$obj->getResourcesDirectory(); |
|
142
|
|
|
} catch (Exception $ex) { |
|
143
|
|
|
|
|
144
|
|
|
$this->assertInstanceOf(InvalidArgumentException::class, $ex); |
|
145
|
|
|
$this->assertEquals("The application kernel is null", $ex->getMessage()); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Tests the __construct() method. |
|
151
|
|
|
* |
|
152
|
|
|
* @return void |
|
153
|
|
|
*/ |
|
154
|
|
|
public function test__construct(): void { |
|
155
|
|
|
|
|
156
|
|
|
$this->assertEquals("wbw.core.command.copy_skeleton", CopySkeletonCommand::SERVICE_NAME); |
|
157
|
|
|
|
|
158
|
|
|
$obj = new CopySkeletonCommand(); |
|
159
|
|
|
|
|
160
|
|
|
$this->assertEquals("Copy skeleton under the app/Resources directory", $obj->getDescription()); |
|
161
|
|
|
$this->assertEquals(CopySkeletonCommand::COMMAND_HELP, $obj->getHelp()); |
|
162
|
|
|
$this->assertEquals("wbw:core:copy-skeleton", $obj->getName()); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
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: