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