diff --git a/lib/Payplug/Authentication.php b/lib/Payplug/Authentication.php index 8e45b80..8bbcf7e 100644 --- a/lib/Payplug/Authentication.php +++ b/lib/Payplug/Authentication.php @@ -166,7 +166,7 @@ public static function generateJWT($client_id = '', $client_secret = '') return array(); } - $response['httpResponse']['expires_date'] = time() + $response['httpResponse']['expires_in']; + $response['httpResponse']['expires_date'] = time() + $response['httpResponse']['expires_in'] - 30; return $response; } catch (Exception $e) { diff --git a/tests/unit_tests/AuthenticationTest.php b/tests/unit_tests/AuthenticationTest.php index 1c2c499..44261f2 100644 --- a/tests/unit_tests/AuthenticationTest.php +++ b/tests/unit_tests/AuthenticationTest.php @@ -39,18 +39,21 @@ protected function setUpTwice() public function testGetKeysByLogin() { - $email = 'test@fakemail.com'; - $password = 'passwordIsOverrated'; - $response = array( - 'secret_keys' => array( - 'test' => 'sk_test_everythingIsUnderControl', - 'live' => 'sk_live_allYourBasesAreBelongToUs', + $email = 'test@example.com'; + $password = 'password_example'; + $expected_response = array( + 'httpResponse' => array( + 'secret_keys' => array( + 'test' => 'test_key_example', + 'live' => 'live_key_example', + ) ), + 'httpStatus' => 201, ); $this->_requestMock ->expects($this->once()) ->method('exec') - ->will($this->returnValue(json_encode($response))); + ->will($this->returnValue(json_encode($expected_response['httpResponse']))); $this->_requestMock ->expects($this->any()) @@ -64,10 +67,7 @@ public function testGetKeysByLogin() })); $authentication = Authentication::getKeysByLogin($email, $password); - - $this->assertEquals(201, $authentication['httpStatus']); - $this->assertEquals('sk_test_everythingIsUnderControl', $authentication['httpResponse']['secret_keys']['test']); - $this->assertEquals('sk_live_allYourBasesAreBelongToUs', $authentication['httpResponse']['secret_keys']['live']); + $this->assertSame($expected_response, $authentication); } public function testGetAccount() @@ -189,7 +189,7 @@ public function testGetPermissionsWithoutSecretKey() public function testPublishableKeys() { $response = array( - 'publishable_key' => 'pk_test_everythingIsUnderControl' + 'publishable_key' => 'test_pk_example' ); $this->_requestMock @@ -211,7 +211,7 @@ public function testPublishableKeys() $publishable_keys = Authentication::getPublishableKeys($this->_configuration); $this->assertEquals(200, $publishable_keys['httpStatus']); - $this->assertEquals('pk_test_everythingIsUnderControl', $publishable_keys['httpResponse']['publishable_key']); + $this->assertEquals('test_pk_example', $publishable_keys['httpResponse']['publishable_key']); } /** @@ -336,7 +336,7 @@ public function testGenerateJWTWhenSuccessResponse() 'expires_in' => 300, 'scope' => 'sandbox', 'token_type' => 'bearer', - 'expires_date' => time() + 300 + 'expires_date' => time() + 270 ); $this->_requestMock