1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the smsmode-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\SmsModeBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
15
|
|
|
use Throwable; |
16
|
|
|
use WBW\Bundle\SmsModeBundle\Controller\DefaultController; |
17
|
|
|
use WBW\Bundle\SmsModeBundle\DependencyInjection\Configuration; |
18
|
|
|
use WBW\Bundle\SmsModeBundle\DependencyInjection\WBWSmsModeExtension; |
19
|
|
|
use WBW\Bundle\SmsModeBundle\EventListener\DefaultEventListener; |
20
|
|
|
use WBW\Bundle\SmsModeBundle\Tests\AbstractTestCase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* sMsmode extension test. |
24
|
|
|
* |
25
|
|
|
* @author webeweb <https://github.com/webeweb> |
26
|
|
|
* @package WBW\Bundle\SmsModeBundle\Tests\DependencyInjection |
27
|
|
|
*/ |
28
|
|
|
class WBWSmsModeExtensionTest extends AbstractTestCase { |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Configs. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private $configs; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritDoc} |
39
|
|
|
*/ |
40
|
|
|
protected function setUp(): void { |
41
|
|
|
parent::setUp(); |
42
|
|
|
|
43
|
|
|
// Set a configs array mock. |
44
|
|
|
$this->configs = [ |
45
|
|
|
WBWSmsModeExtension::EXTENSION_ALIAS => [ |
46
|
|
|
"authentication" => [ |
47
|
|
|
"access_token" => null, |
48
|
|
|
"pseudo" => null, |
49
|
|
|
"pass" => null, |
50
|
|
|
], |
51
|
|
|
"event_listeners" => true, |
52
|
|
|
], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Test getAlias() |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function testGetAlias(): void { |
62
|
|
|
|
63
|
|
|
$obj = new WBWSmsModeExtension(); |
64
|
|
|
|
65
|
|
|
$this->assertEquals(WBWSmsModeExtension::EXTENSION_ALIAS, $obj->getAlias()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Test getConfiguration() |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
public function testGetConfiguration(): void { |
74
|
|
|
|
75
|
|
|
$obj = new WBWSmsModeExtension(); |
76
|
|
|
|
77
|
|
|
$this->assertInstanceOf(Configuration::class, $obj->getConfiguration([], $this->containerBuilder)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Test load() |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
85
|
|
|
*/ |
86
|
|
|
public function testLoad(): void { |
87
|
|
|
|
88
|
|
|
$obj = new WBWSmsModeExtension(); |
89
|
|
|
|
90
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
|
|
|
|
91
|
|
|
|
92
|
|
|
// Controllers |
93
|
|
|
$this->assertInstanceOf(DefaultController::class, $this->containerBuilder->get(DefaultController::SERVICE_NAME)); |
94
|
|
|
|
95
|
|
|
// Event listeners |
96
|
|
|
$this->assertInstanceOf(DefaultEventListener::class, $this->containerBuilder->get(DefaultEventListener::SERVICE_NAME)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Test load() |
101
|
|
|
* |
102
|
|
|
* @return void |
103
|
|
|
*/ |
104
|
|
|
public function testLoadWithoutEventListeners(): void { |
105
|
|
|
|
106
|
|
|
// Set the configs mock. |
107
|
|
|
$this->configs[WBWSmsModeExtension::EXTENSION_ALIAS]["event_listeners"] = false; |
108
|
|
|
|
109
|
|
|
$obj = new WBWSmsModeExtension(); |
110
|
|
|
|
111
|
|
|
$this->assertNull($obj->load($this->configs, $this->containerBuilder)); |
|
|
|
|
112
|
|
|
|
113
|
|
|
try { |
114
|
|
|
|
115
|
|
|
$this->containerBuilder->get(DefaultEventListener::SERVICE_NAME); |
116
|
|
|
} catch (Throwable $ex) { |
117
|
|
|
|
118
|
|
|
$this->assertInstanceOf(ServiceNotFoundException::class, $ex); |
119
|
|
|
$this->assertStringContainsString(DefaultEventListener::SERVICE_NAME, $ex->getMessage()); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Test __construct() |
125
|
|
|
* |
126
|
|
|
* @return void |
127
|
|
|
*/ |
128
|
|
|
public function test__construct(): void { |
129
|
|
|
|
130
|
|
|
$this->assertEquals("wbw_smsmode", WBWSmsModeExtension::EXTENSION_ALIAS); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.