XApiClientBuilderTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 7
c 5
b 0
f 1
lcom 1
cbo 6
dl 0
loc 66
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testSetBaseUrl() 0 10 1
A testSetVersion() 0 7 1
A testSetAuth() 0 8 1
B testSetOAuth() 0 25 3
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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