@@ -70,6 +70,11 @@ public function setUp()
70
70
);
71
71
}
72
72
73
+ /**
74
+ * @param string $status
75
+ *
76
+ * @return array
77
+ */
73
78
private function getIntegrationUserData ($ status )
74
79
{
75
80
return [
@@ -83,6 +88,9 @@ private function getIntegrationUserData($status)
83
88
];
84
89
}
85
90
91
+ /**
92
+ * @return void
93
+ */
86
94
public function testActivateIntegrationSuccess ()
87
95
{
88
96
$ this ->integrationServiceMock ->expects ($ this ->once ())
@@ -125,7 +133,13 @@ public function testActivateIntegrationFailureNoSuchEntity()
125
133
$ this ->integrationManager ->activateIntegration ();
126
134
}
127
135
128
- public function testGetTokenNewIntegration ()
136
+ /**
137
+ * @dataProvider integrationIdDataProvider
138
+ *
139
+ * @param int|null $integrationId If null integration is absent.
140
+ * @return void
141
+ */
142
+ public function testGetTokenNewIntegration ($ integrationId )
129
143
{
130
144
$ this ->configMock ->expects ($ this ->atLeastOnce ())
131
145
->method ('getConfigDataValue ' )
@@ -140,7 +154,14 @@ public function testGetTokenNewIntegration()
140
154
->willReturn (100500 );
141
155
$ this ->integrationMock ->expects ($ this ->once ())
142
156
->method ('getId ' )
143
- ->willReturn (1 );
157
+ ->willReturn ($ integrationId );
158
+ if (!$ integrationId ) {
159
+ $ this ->integrationServiceMock
160
+ ->expects ($ this ->once ())
161
+ ->method ('create ' )
162
+ ->with ($ this ->getIntegrationUserData (Integration::STATUS_INACTIVE ))
163
+ ->willReturn ($ this ->integrationMock );
164
+ }
144
165
$ this ->oauthServiceMock ->expects ($ this ->at (0 ))
145
166
->method ('getAccessToken ' )
146
167
->with (100500 )
@@ -156,7 +177,13 @@ public function testGetTokenNewIntegration()
156
177
$ this ->assertEquals ('IntegrationToken ' , $ this ->integrationManager ->generateToken ());
157
178
}
158
179
159
- public function testGetTokenExistingIntegration ()
180
+ /**
181
+ * @dataProvider integrationIdDataProvider
182
+ *
183
+ * @param int|null $integrationId If null integration is absent.
184
+ * @return void
185
+ */
186
+ public function testGetTokenExistingIntegration ($ integrationId )
160
187
{
161
188
$ this ->configMock ->expects ($ this ->atLeastOnce ())
162
189
->method ('getConfigDataValue ' )
@@ -171,7 +198,14 @@ public function testGetTokenExistingIntegration()
171
198
->willReturn (100500 );
172
199
$ this ->integrationMock ->expects ($ this ->once ())
173
200
->method ('getId ' )
174
- ->willReturn (1 );
201
+ ->willReturn ($ integrationId );
202
+ if (!$ integrationId ) {
203
+ $ this ->integrationServiceMock
204
+ ->expects ($ this ->once ())
205
+ ->method ('create ' )
206
+ ->with ($ this ->getIntegrationUserData (Integration::STATUS_INACTIVE ))
207
+ ->willReturn ($ this ->integrationMock );
208
+ }
175
209
$ this ->oauthServiceMock ->expects ($ this ->once ())
176
210
->method ('getAccessToken ' )
177
211
->with (100500 )
@@ -180,4 +214,15 @@ public function testGetTokenExistingIntegration()
180
214
->method ('createAccessToken ' );
181
215
$ this ->assertEquals ('IntegrationToken ' , $ this ->integrationManager ->generateToken ());
182
216
}
217
+
218
+ /**
219
+ * @return array
220
+ */
221
+ public function integrationIdDataProvider ()
222
+ {
223
+ return [
224
+ [1 ],
225
+ [null ],
226
+ ];
227
+ }
183
228
}
0 commit comments