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
|
|
|
|