Code Duplication    Length = 39-41 lines in 2 locations

tests/GrantType/JwtBearerTest.php 1 location

@@ 9-47 (lines=39) @@
6
use Sainsburys\Guzzle\Oauth2\Tests\TestBase;
7
use SplFileObject;
8
9
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

tests/GrantType/PasswordCredentialsTest.php 1 location

@@ 8-48 (lines=41) @@
5
use Sainsburys\Guzzle\Oauth2\GrantType\PasswordCredentials;
6
use Sainsburys\Guzzle\Oauth2\Tests\TestBase;
7
8
class PasswordCredentialsTest extends TestBase
9
{
10
    public function testMissingParentConfigException()
11
    {
12
        $this->setExpectedException('\\InvalidArgumentException', 'The config is missing the following key: "client_id"');
13
        new PasswordCredentials($this->createClient());
14
    }
15
16
    public function testMissingUsernameConfigException()
17
    {
18
        $this->setExpectedException('\\InvalidArgumentException', 'The config is missing the following key: "username"');
19
        new PasswordCredentials($this->createClient(), [
20
            'client_id' => 'testClient',
21
            'client_secret' => 'clientSecret',
22
        ]);
23
    }
24
25
    public function testMissingPasswordConfigException()
26
    {
27
        $this->setExpectedException('\\InvalidArgumentException', 'The config is missing the following key: "password"');
28
        new PasswordCredentials($this->createClient(), [
29
            'client_id' => 'testClient',
30
            'client_secret' => 'clientSecret',
31
            'username' => 'validUsername',
32
        ]);
33
    }
34
35
    public function testValidPasswordGetsToken()
36
    {
37
        $grantType = new PasswordCredentials($this->createClient(), [
38
            'client_id' => 'testClient',
39
            'client_secret' => 'clientSecret',
40
            'username' => 'validUsername',
41
            'password' => 'validPassword',
42
        ]);
43
44
        $token = $grantType->getToken();
45
        $this->assertNotEmpty($token->getToken());
46
        $this->assertTrue($token->getExpires()->getTimestamp() > time());
47
    }
48
}
49