1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use Xabbuh\XApi\Client\XApiClientBuilder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Christian Flothmann <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class XApiClientBuilderTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var XApiClientBuilder |
21
|
|
|
*/ |
22
|
|
|
private $builder; |
23
|
|
|
|
24
|
|
|
protected function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->builder = new XApiClientBuilder(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testSetBaseUrl() |
30
|
|
|
{ |
31
|
|
|
$this->builder->setBaseUrl('http://www.example.com'); |
32
|
|
|
$xApiClient = $this->builder->build(); |
33
|
|
|
/** @var \Xabbuh\XApi\Client\Request\Handler $requestHandler */ |
34
|
|
|
$requestHandler = $xApiClient->getRequestHandler(); |
35
|
|
|
$httpClient = $requestHandler->getHttpClient(); |
36
|
|
|
|
37
|
|
|
$this->assertEquals('http://www.example.com', $httpClient->getBaseUrl()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testSetVersion() |
41
|
|
|
{ |
42
|
|
|
$this->builder->setVersion('1.0.0'); |
43
|
|
|
$xApiClient = $this->builder->build(); |
44
|
|
|
|
45
|
|
|
$this->assertEquals('1.0.0', $xApiClient->getVersion()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testSetAuth() |
49
|
|
|
{ |
50
|
|
|
$this->builder->setAuth('foo', 'bar'); |
51
|
|
|
$xApiClient = $this->builder->build(); |
52
|
|
|
|
53
|
|
|
$this->assertEquals('foo', $xApiClient->getRequestHandler()->getUsername()); |
54
|
|
|
$this->assertEquals('bar', $xApiClient->getRequestHandler()->getPassword()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testSetOAuth() |
58
|
|
|
{ |
59
|
|
|
/** @var \Xabbuh\XApi\Client\XApiClient $xApiClient */ |
60
|
|
|
$xApiClient = $this->builder |
61
|
|
|
->setOAuthCredentials( |
62
|
|
|
'consumer-key', |
63
|
|
|
'consumer-secret', |
64
|
|
|
'token', |
65
|
|
|
'token-secret' |
66
|
|
|
) |
67
|
|
|
->build(); |
68
|
|
|
/** @var \Xabbuh\XApi\Client\Request\Handler $requestHandler */ |
69
|
|
|
$requestHandler = $xApiClient->getRequestHandler(); |
70
|
|
|
$httpClient = $requestHandler->getHttpClient(); |
71
|
|
|
$listeners = $httpClient->getEventDispatcher() |
72
|
|
|
->getListeners('request.before_send'); |
73
|
|
|
|
74
|
|
|
foreach ($listeners as $index => $listener) { |
75
|
|
|
if (!$listener[0] instanceof \Guzzle\Plugin\Oauth\OauthPlugin) { |
76
|
|
|
unset($listeners[$index]); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->assertCount(1, $listeners); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.