1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2019 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic, Inc. |
||
6 | * |
||
7 | * @link https://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace MauticPlugin\MauticCitrixBundle\Tests\EventListener; |
||
13 | |||
14 | use Mautic\PluginBundle\Event\PluginIntegrationRequestEvent; |
||
15 | use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; |
||
16 | use Mautic\PluginBundle\PluginEvents; |
||
17 | use MauticPlugin\MauticCitrixBundle\EventListener\IntegrationRequestSubscriber; |
||
18 | use PHPUnit\Framework\TestCase; |
||
19 | |||
20 | class IntegrationRequestSubscriberTest extends TestCase |
||
21 | { |
||
22 | /** @var PluginIntegrationRequestEvent */ |
||
23 | protected $event; |
||
24 | |||
25 | /** @var IntegrationRequestSubscriber */ |
||
26 | protected $subscriber; |
||
27 | |||
28 | protected function setUp(): void |
||
29 | { |
||
30 | $this->subscriber = $this->getMockBuilder(IntegrationRequestSubscriber::class) |
||
0 ignored issues
–
show
|
|||
31 | ->disableOriginalConstructor() |
||
32 | ->setMethodsExcept(['getParameters', 'getAuthorization']) |
||
33 | ->getMock(); |
||
34 | |||
35 | $integration = $this->getMockBuilder(UnifiedIntegrationInterface::class) |
||
36 | ->disableOriginalConstructor() |
||
37 | ->getMock(); |
||
38 | |||
39 | $this->event = new PluginIntegrationRequestEvent($integration, '\'oauth/v2/token\'', null, null, null, null, null); |
||
40 | } |
||
41 | |||
42 | public function testGetSubscribedEventsMethod() |
||
43 | { |
||
44 | $this->assertSame(IntegrationRequestSubscriber::getSubscribedEvents(), [ |
||
45 | PluginEvents::PLUGIN_ON_INTEGRATION_REQUEST => [ |
||
46 | 'getParameters', |
||
47 | 0, |
||
48 | ], |
||
49 | ]); |
||
50 | } |
||
51 | |||
52 | public function testExceptionOnEmptyClientId() |
||
53 | { |
||
54 | $this->expectException(\Exception::class); |
||
55 | $this->expectExceptionMessage('No client ID given.'); |
||
56 | |||
57 | $this->event->setParameters([ |
||
58 | 'client_secret' => 'abc', |
||
59 | ]); |
||
60 | |||
61 | $this->subscriber->getParameters($this->event); |
||
62 | } |
||
63 | |||
64 | public function testExceptionOnEmptyClientSecret() |
||
65 | { |
||
66 | $this->expectException(\Exception::class); |
||
67 | $this->expectExceptionMessage('No client secret given.'); |
||
68 | |||
69 | $this->event->setParameters([ |
||
70 | 'client_id' => 'abc', |
||
71 | ]); |
||
72 | |||
73 | $this->subscriber->getParameters($this->event); |
||
74 | } |
||
75 | |||
76 | public function testExceptionOnEmptyParameters() |
||
77 | { |
||
78 | $this->expectException(\Exception::class); |
||
79 | |||
80 | $this->event->setParameters([]); |
||
81 | |||
82 | $this->subscriber->getParameters($this->event); |
||
83 | } |
||
84 | |||
85 | public function testNoExceptionOnCorrectParameters() |
||
86 | { |
||
87 | $this->event->setParameters([ |
||
88 | 'client_id' => 'abc', |
||
89 | 'client_secret' => 'def', |
||
90 | ]); |
||
91 | |||
92 | $this->subscriber->getParameters($this->event); |
||
93 | $this->addToAssertionCount(1); |
||
94 | } |
||
95 | |||
96 | public function testHeaders() |
||
97 | { |
||
98 | $this->event->setParameters([ |
||
99 | 'client_id' => 'abc', |
||
100 | 'client_secret' => 'def', |
||
101 | ]); |
||
102 | |||
103 | $this->subscriber->getParameters($this->event); |
||
104 | |||
105 | $this->assertSame($this->event->getHeaders(), [ |
||
106 | 'Authorization' => 'Basic YWJjOmRlZg==', |
||
107 | 'Content-Type' => 'application/x-www-form-urlencoded', |
||
108 | ]); |
||
109 | } |
||
110 | } |
||
111 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..