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

Commit

Permalink
Refactor some styles and codes
Browse files Browse the repository at this point in the history
  • Loading branch information
percymamedy committed Jun 6, 2016
1 parent 1e272e6 commit bcbaa4b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/vendor/
/.idea
composer.lock
composer.phar
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

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

<br/>

[![StyleCI](https://styleci.io/repos/59507474/shield?style=flat)](https://styleci.io/repos/59507474)
[![Build Status](https://travis-ci.org/findbrok/php-watson-api-bridge.svg?branch=master)](https://travis-ci.org/findbrok/php-watson-api-bridge)
[![Latest Stable Version](https://poser.pugx.org/findbrok/php-watson-api-bridge/v/stable)](https://packagist.org/packages/findbrok/php-watson-api-bridge)
[![Total Downloads](https://poser.pugx.org/findbrok/php-watson-api-bridge/downloads)](https://packagist.org/packages/findbrok/php-watson-api-bridge)
Expand Down
5 changes: 3 additions & 2 deletions src/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use FindBrok\WatsonBridge\Exceptions\WatsonBridgeException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Response;

/**
* Class Bridge.
Expand Down Expand Up @@ -233,11 +234,11 @@ public function cleanOptions($options = [])
/**
* Failed Request to Watson.
*
* @param \GuzzleHttp\Psr7\Response $response
* @param Response $response
*
* @throws WatsonBridgeException
*/
public function failedRequest($response)
public function failedRequest(Response $response)
{
//Decode Response
$decodedResponse = json_decode($response->getBody()->getContents(), true);
Expand Down
6 changes: 0 additions & 6 deletions tests/TestBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,6 @@ public function testGetTokenMethodWhenTokenExpiredAndFetchTokenAgain()
$this->deleteTestTokenFile('token-foofoo');
}

/**
* Test a Get request which fails.
*
* @expectedException \FindBrok\WatsonBridge\Exceptions\WatsonBridgeException
}*/

/**
* Test that when the token is expired we refresh the token and try again.
*
Expand Down
51 changes: 40 additions & 11 deletions tests/TestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ public function tearDown()
unlink($this->getTokenStoragePath('token-username.json'));
}

/**
* Creates a test token file.
*
* @param string $name
* @param array $data
*
* @return void
*/
public function createTestTokenFile($name = '', $data = [])
{
file_put_contents(
$this->getTokenStoragePath($name.'.json'),
collect($data)->toJson(),
LOCK_EX
);
}

/**
* Delete a test token file.
*
* @param string $name
*
* @return void
*/
public function deleteTestTokenFile($name = '')
{
unlink($this->getTokenStoragePath($name.'.json'));
}

/**
* Return Token Storage Folder.
*
Expand Down Expand Up @@ -145,7 +174,7 @@ public function testSaveMethod()
$this->assertFileExists($this->getTokenStoragePath('token-username2.json'));
$this->assertJsonStringEqualsJsonFile($this->getTokenStoragePath('token-username2.json'), collect($payload)->toJson());

unlink($this->getTokenStoragePath('token-username2.json'));
$this->deleteTestTokenFile('token-username2');
}

/**
Expand All @@ -155,11 +184,11 @@ public function testSaveMethod()
*/
public function testLoadFromFileMethodAndGetPayLoadMethod()
{
file_put_contents($this->getTokenStoragePath('token-username3.json'), collect([
$this->createTestTokenFile('token-username3', [
'token' => 'sometoken',
'expires_in' => 3600,
'created' => 1463977413,
])->toJson(), LOCK_EX);
]);

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

unlink($this->getTokenStoragePath('token-username3.json'));
$this->deleteTestTokenFile('token-username3');
}

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

file_put_contents($this->getTokenStoragePath('token-username3.json'), collect([
$this->createTestTokenFile('token-username3', [
'token' => 'sometoken',
'expires_in' => 3600,
'created' => 1463977413,
])->toJson(), LOCK_EX);
]);

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

unlink($this->getTokenStoragePath('token-username3.json'));
$this->deleteTestTokenFile('token-username3');
}

/**
Expand All @@ -201,19 +230,19 @@ public function testIsValidMethod()
*/
public function testGetTokenMethod()
{
file_put_contents($this->getTokenStoragePath('token-username3.json'), collect([
$this->createTestTokenFile('token-username3', [
'token' => 'sometoken',
'expires_in' => 3600,
'created' => Carbon::now()->format('U'),
])->toJson(), LOCK_EX);
]);

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

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

unlink($this->getTokenStoragePath('token-username3.json'));
$this->deleteTestTokenFile('token-username3');
}

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

unlink($this->getTokenStoragePath('token-username3.json'));
$this->deleteTestTokenFile('token-username3');
}
}

0 comments on commit bcbaa4b

Please sign in to comment.