ServiceAuthTest::shouldAddTokenToRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is a part of nekland youtube api package
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\Tests\Http\Auth;
13
14
use Guzzle\Http\Message\Request;
15
use Nekland\YoutubeApi\Http\Auth\ServiceAuth;
16
17
class ServiceAuthTest extends \PHPUnit_Framework_TestCase
18
{
19
    use AuthServiceTrait;
20
21
    /**
22
     * @test
23
     */
24
    public function shouldBeConstructWithOrWithoutClient()
25
    {
26
        $auth = new ServiceAuth();
27
        $this->assertInstanceOf('Nekland\\YoutubeApi\\Http\\Auth\\ServiceAuth', $auth);
28
29
        $auth = new ServiceAuth($this->prophesize('Guzzle\\Http\\ClientInterface')->reveal());
30
        $this->assertInstanceOf('Nekland\\YoutubeApi\\Http\\Auth\\ServiceAuth', $auth);
31
    }
32
33
    /**
34
     * @test
35
     */
36
    public function shouldAddTokenToRequest()
37
    {
38
        $auth = new ServiceAuth($this->getClientMock());
39
        $auth->setOptions(['cert_file' => __DIR__ . '/../../../../test_data/cert.p12', 'email' => 'myemail_for_google_service@googleapi_etc.com']);
40
        $request = new Request('POST', 'http://fake.com');
41
        $auth->auth($request);
42
43
        $this->assertContains('ya29.1.AADHN_WnGjqYiAcnONRLFDOfXia5XZLFO4RSyEhWtQPAvYpgPYiQj89c7UsrAs5_',(string)$request->getHeader('Authorization'));
44
    }
45
}
46