testItAddsATokenToTheRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is a part of YoutubeApi package.
4
 *
5
 * (c) Nekland <[email protected]>
6
 *
7
 * For the full license, take a look to the LICENSE file
8
 * on the root directory of this project
9
 */
10
11
namespace Nekland\Tests\Http\Auth;
12
13
14
use Guzzle\Http\ClientInterface;
15
use Guzzle\Http\Message\Request;
16
use Nekland\YoutubeApi\Http\Auth\JsonFileServiceAuth;
17
18
class JsonFileServiceAuthTest extends \PHPUnit_Framework_TestCase
19
{
20
    use AuthServiceTrait;
21
22
    public function testItConstructWithOrWithoutClient()
23
    {
24
        $auth = new JsonFileServiceAuth();
25
        $this->assertInstanceOf(JsonFileServiceAuth::class, $auth);
26
27
        $auth = new JsonFileServiceAuth($this->prophesize(ClientInterface::class)->reveal());
28
        $this->assertInstanceOf(JsonFileServiceAuth::class, $auth);
29
    }
30
31
    public function testItAddsATokenToTheRequest()
32
    {
33
        $auth = new JsonFileServiceAuth($this->getClientMock());
34
35
        // This file is a fake, of course.
36
        $file = __DIR__ . '/../../../../test_data/given_by_google.json';
37
38
        $auth->setOptions(['json_file' => $file]);
39
        $request = new Request('POST', 'http://fake.com');
40
        $auth->auth($request);
41
42
        $this->assertContains('ya29.1.AADHN_WnGjqYiAcnONRLFDOfXia5XZLFO4RSyEhWtQPAvYpgPYiQj89c7UsrAs5_',(string)$request->getHeader('Authorization'));
43
    }
44
45
    /**
46
     * @expectedException \Nekland\YoutubeApi\Exception\MissingOptionException
47
     */
48
    public function testItThrowsExceptionIfOptionMissing()
49
    {
50
        $auth = new JsonFileServiceAuth($this->prophesize(ClientInterface::class)->reveal());
51
        $request = new Request('POST', 'http://fake.com');
52
        $auth->auth($request);
53
    }
54
}
55