@@ -39,6 +39,35 @@ public function tearDown()
39
39
unlink ($ this ->getTokenStoragePath ('token-username.json ' ));
40
40
}
41
41
42
+ /**
43
+ * Creates a test token file.
44
+ *
45
+ * @param string $name
46
+ * @param array $data
47
+ *
48
+ * @return void
49
+ */
50
+ public function createTestTokenFile ($ name = '' , $ data = [])
51
+ {
52
+ file_put_contents (
53
+ $ this ->getTokenStoragePath ($ name .'.json ' ),
54
+ collect ($ data )->toJson (),
55
+ LOCK_EX
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Delete a test token file.
61
+ *
62
+ * @param string $name
63
+ *
64
+ * @return void
65
+ */
66
+ public function deleteTestTokenFile ($ name = '' )
67
+ {
68
+ unlink ($ this ->getTokenStoragePath ($ name .'.json ' ));
69
+ }
70
+
42
71
/**
43
72
* Return Token Storage Folder.
44
73
*
@@ -145,7 +174,7 @@ public function testSaveMethod()
145
174
$ this ->assertFileExists ($ this ->getTokenStoragePath ('token-username2.json ' ));
146
175
$ this ->assertJsonStringEqualsJsonFile ($ this ->getTokenStoragePath ('token-username2.json ' ), collect ($ payload )->toJson ());
147
176
148
- unlink ( $ this ->getTokenStoragePath ('token-username2.json ' ) );
177
+ $ this ->deleteTestTokenFile ('token-username2 ' );
149
178
}
150
179
151
180
/**
@@ -155,11 +184,11 @@ public function testSaveMethod()
155
184
*/
156
185
public function testLoadFromFileMethodAndGetPayLoadMethod ()
157
186
{
158
- file_put_contents ( $ this ->getTokenStoragePath ('token-username3.json ' ), collect ( [
187
+ $ this ->createTestTokenFile ('token-username3 ' , [
159
188
'token ' => 'sometoken ' ,
160
189
'expires_in ' => 3600 ,
161
190
'created ' => 1463977413 ,
162
- ])-> toJson (), LOCK_EX ) ;
191
+ ]);
163
192
164
193
$ token = new Token ('username3 ' );
165
194
$ this ->assertEquals ([
@@ -168,7 +197,7 @@ public function testLoadFromFileMethodAndGetPayLoadMethod()
168
197
'created ' => 1463977413 ,
169
198
], $ token ->getPayload ());
170
199
171
- unlink ( $ this ->getTokenStoragePath ('token-username3.json ' ) );
200
+ $ this ->deleteTestTokenFile ('token-username3 ' );
172
201
}
173
202
174
203
/**
@@ -182,16 +211,16 @@ public function testIsValidMethod()
182
211
$ token2 = new Token ('username2 ' );
183
212
$ this ->assertFalse ($ token2 ->isValid ());
184
213
185
- file_put_contents ( $ this ->getTokenStoragePath ('token-username3.json ' ), collect ( [
214
+ $ this ->createTestTokenFile ('token-username3 ' , [
186
215
'token ' => 'sometoken ' ,
187
216
'expires_in ' => 3600 ,
188
217
'created ' => 1463977413 ,
189
- ])-> toJson (), LOCK_EX ) ;
218
+ ]);
190
219
191
220
$ token3 = new Token ('username3 ' );
192
221
$ this ->assertFalse ($ token3 ->isValid ());
193
222
194
- unlink ( $ this ->getTokenStoragePath ('token-username3.json ' ) );
223
+ $ this ->deleteTestTokenFile ('token-username3 ' );
195
224
}
196
225
197
226
/**
@@ -201,19 +230,19 @@ public function testIsValidMethod()
201
230
*/
202
231
public function testGetTokenMethod ()
203
232
{
204
- file_put_contents ( $ this ->getTokenStoragePath ('token-username3.json ' ), collect ( [
233
+ $ this ->createTestTokenFile ('token-username3 ' , [
205
234
'token ' => 'sometoken ' ,
206
235
'expires_in ' => 3600 ,
207
236
'created ' => Carbon::now ()->format ('U ' ),
208
- ])-> toJson (), LOCK_EX ) ;
237
+ ]);
209
238
210
239
$ token3 = new Token ('username3 ' );
211
240
$ this ->assertEquals ('sometoken ' , $ token3 ->getToken ());
212
241
213
242
$ token2 = new Token ('username2 ' );
214
243
$ this ->assertNull ($ token2 ->getToken ());
215
244
216
- unlink ( $ this ->getTokenStoragePath ('token-username3.json ' ) );
245
+ $ this ->deleteTestTokenFile ('token-username3 ' );
217
246
}
218
247
219
248
/**
@@ -235,6 +264,6 @@ public function testUpdateTokenMethod()
235
264
$ this ->assertEquals ('newToken ' , $ token ->getToken ());
236
265
$ this ->assertFileExists ($ this ->getTokenStoragePath ('token-username3.json ' ));
237
266
238
- unlink ( $ this ->getTokenStoragePath ('token-username3.json ' ) );
267
+ $ this ->deleteTestTokenFile ('token-username3 ' );
239
268
}
240
269
}
0 commit comments