Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit bcbaa4b

Browse files
committed
Refactor some styles and codes
1 parent 1e272e6 commit bcbaa4b

File tree

5 files changed

+45
-22
lines changed

5 files changed

+45
-22
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/vendor/
2-
/.idea
32
composer.lock
3+
composer.phar

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/4e21093a-cc60-4a75-b7fe-cb29053faf6c/big.png)](https://insight.sensiolabs.com/projects/4e21093a-cc60-4a75-b7fe-cb29053faf6c)
44

5-
<br/>
6-
5+
[![StyleCI](https://styleci.io/repos/59507474/shield?style=flat)](https://styleci.io/repos/59507474)
76
[![Build Status](https://travis-ci.org/findbrok/php-watson-api-bridge.svg?branch=master)](https://travis-ci.org/findbrok/php-watson-api-bridge)
87
[![Latest Stable Version](https://poser.pugx.org/findbrok/php-watson-api-bridge/v/stable)](https://packagist.org/packages/findbrok/php-watson-api-bridge)
98
[![Total Downloads](https://poser.pugx.org/findbrok/php-watson-api-bridge/downloads)](https://packagist.org/packages/findbrok/php-watson-api-bridge)

src/Bridge.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use FindBrok\WatsonBridge\Exceptions\WatsonBridgeException;
66
use GuzzleHttp\Client;
77
use GuzzleHttp\Exception\ClientException;
8+
use GuzzleHttp\Psr7\Response;
89

910
/**
1011
* Class Bridge.
@@ -233,11 +234,11 @@ public function cleanOptions($options = [])
233234
/**
234235
* Failed Request to Watson.
235236
*
236-
* @param \GuzzleHttp\Psr7\Response $response
237+
* @param Response $response
237238
*
238239
* @throws WatsonBridgeException
239240
*/
240-
public function failedRequest($response)
241+
public function failedRequest(Response $response)
241242
{
242243
//Decode Response
243244
$decodedResponse = json_decode($response->getBody()->getContents(), true);

tests/TestBridge.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,6 @@ public function testGetTokenMethodWhenTokenExpiredAndFetchTokenAgain()
266266
$this->deleteTestTokenFile('token-foofoo');
267267
}
268268

269-
/**
270-
* Test a Get request which fails.
271-
*
272-
* @expectedException \FindBrok\WatsonBridge\Exceptions\WatsonBridgeException
273-
}*/
274-
275269
/**
276270
* Test that when the token is expired we refresh the token and try again.
277271
*

tests/TestToken.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,35 @@ public function tearDown()
3939
unlink($this->getTokenStoragePath('token-username.json'));
4040
}
4141

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+
4271
/**
4372
* Return Token Storage Folder.
4473
*
@@ -145,7 +174,7 @@ public function testSaveMethod()
145174
$this->assertFileExists($this->getTokenStoragePath('token-username2.json'));
146175
$this->assertJsonStringEqualsJsonFile($this->getTokenStoragePath('token-username2.json'), collect($payload)->toJson());
147176

148-
unlink($this->getTokenStoragePath('token-username2.json'));
177+
$this->deleteTestTokenFile('token-username2');
149178
}
150179

151180
/**
@@ -155,11 +184,11 @@ public function testSaveMethod()
155184
*/
156185
public function testLoadFromFileMethodAndGetPayLoadMethod()
157186
{
158-
file_put_contents($this->getTokenStoragePath('token-username3.json'), collect([
187+
$this->createTestTokenFile('token-username3', [
159188
'token' => 'sometoken',
160189
'expires_in' => 3600,
161190
'created' => 1463977413,
162-
])->toJson(), LOCK_EX);
191+
]);
163192

164193
$token = new Token('username3');
165194
$this->assertEquals([
@@ -168,7 +197,7 @@ public function testLoadFromFileMethodAndGetPayLoadMethod()
168197
'created' => 1463977413,
169198
], $token->getPayload());
170199

171-
unlink($this->getTokenStoragePath('token-username3.json'));
200+
$this->deleteTestTokenFile('token-username3');
172201
}
173202

174203
/**
@@ -182,16 +211,16 @@ public function testIsValidMethod()
182211
$token2 = new Token('username2');
183212
$this->assertFalse($token2->isValid());
184213

185-
file_put_contents($this->getTokenStoragePath('token-username3.json'), collect([
214+
$this->createTestTokenFile('token-username3', [
186215
'token' => 'sometoken',
187216
'expires_in' => 3600,
188217
'created' => 1463977413,
189-
])->toJson(), LOCK_EX);
218+
]);
190219

191220
$token3 = new Token('username3');
192221
$this->assertFalse($token3->isValid());
193222

194-
unlink($this->getTokenStoragePath('token-username3.json'));
223+
$this->deleteTestTokenFile('token-username3');
195224
}
196225

197226
/**
@@ -201,19 +230,19 @@ public function testIsValidMethod()
201230
*/
202231
public function testGetTokenMethod()
203232
{
204-
file_put_contents($this->getTokenStoragePath('token-username3.json'), collect([
233+
$this->createTestTokenFile('token-username3', [
205234
'token' => 'sometoken',
206235
'expires_in' => 3600,
207236
'created' => Carbon::now()->format('U'),
208-
])->toJson(), LOCK_EX);
237+
]);
209238

210239
$token3 = new Token('username3');
211240
$this->assertEquals('sometoken', $token3->getToken());
212241

213242
$token2 = new Token('username2');
214243
$this->assertNull($token2->getToken());
215244

216-
unlink($this->getTokenStoragePath('token-username3.json'));
245+
$this->deleteTestTokenFile('token-username3');
217246
}
218247

219248
/**
@@ -235,6 +264,6 @@ public function testUpdateTokenMethod()
235264
$this->assertEquals('newToken', $token->getToken());
236265
$this->assertFileExists($this->getTokenStoragePath('token-username3.json'));
237266

238-
unlink($this->getTokenStoragePath('token-username3.json'));
267+
$this->deleteTestTokenFile('token-username3');
239268
}
240269
}

0 commit comments

Comments
 (0)