1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sainsburys\Guzzle\Oauth2\Tests\GrantType; |
4
|
|
|
|
5
|
|
|
use Sainsburys\Guzzle\Oauth2\GrantType\JwtBearer; |
6
|
|
|
use Sainsburys\Guzzle\Oauth2\Tests\TestBase; |
7
|
|
|
use SplFileObject; |
8
|
|
|
|
9
|
|
View Code Duplication |
class JwtBearerTest extends TestBase |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
public function testMissingParentConfigException() |
12
|
|
|
{ |
13
|
|
|
$this->setExpectedException('\\InvalidArgumentException', 'The config is missing the following key: "client_id"'); |
14
|
|
|
new JwtBearer($this->createClient()); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testMissingConfigException() |
18
|
|
|
{ |
19
|
|
|
$this->setExpectedException('\\InvalidArgumentException', 'The config is missing the following key: "private_key"'); |
20
|
|
|
new JwtBearer($this->createClient(), [ |
21
|
|
|
'client_id' => 'testClient', |
22
|
|
|
'client_secret' => 'clientSecret' |
23
|
|
|
]); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testPrivateKeyNotSplFileObject() |
27
|
|
|
{ |
28
|
|
|
$this->setExpectedException('\\InvalidArgumentException', 'private_key needs to be instance of SplFileObject'); |
29
|
|
|
new JwtBearer($this->createClient(), [ |
30
|
|
|
'client_id' => 'testClient', |
31
|
|
|
'client_secret' => 'clientSecret', |
32
|
|
|
'private_key' => 'INVALID' |
33
|
|
|
]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testValidRequestGetsToken() |
37
|
|
|
{ |
38
|
|
|
$grantType = new JwtBearer($this->createClient(), [ |
39
|
|
|
'client_id' => 'testClient', |
40
|
|
|
'client_secret' => 'clientSecret', |
41
|
|
|
'private_key' => new SplFileObject(__DIR__ . '/../private.key') |
42
|
|
|
]); |
43
|
|
|
$token = $grantType->getToken(); |
44
|
|
|
$this->assertNotEmpty($token->getToken()); |
45
|
|
|
$this->assertTrue($token->getExpires()->getTimestamp() > time()); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.