XApiClientTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 20
Bugs 1 Features 2
Metric Value
wmc 9
c 20
b 1
f 2
lcom 1
cbo 1
dl 0
loc 108
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testGetRequestHandler() 0 4 1
A testGetSerializerRegistry() 0 4 1
A testGetStatementsApi() 0 7 1
A testGetStateApi() 0 7 1
A testGetActivityProfileApi() 0 7 1
A testGetAgentProfileApi() 0 7 1
A createRequestHandlerMock() 0 4 1
B createSerializerRegistryMock() 0 30 1
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
namespace Xabbuh\XApi\Client\Tests;
13
14
use Xabbuh\XApi\Client\Request\HandlerInterface;
15
use Xabbuh\XApi\Client\XApiClient;
16
use Xabbuh\XApi\Serializer\SerializerRegistryInterface;
17
18
/**
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
class XApiClientTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var HandlerInterface|\PHPUnit_Framework_MockObject_MockObject
25
     */
26
    private $requestHandler;
27
28
    /**
29
     * @var SerializerRegistryInterface|\PHPUnit_Framework_MockObject_MockObject
30
     */
31
    private $serializerRegistry;
32
33
    /**
34
     * @var XApiClient
35
     */
36
    private $client;
37
38
    protected function setUp()
39
    {
40
        $this->requestHandler = $this->createRequestHandlerMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createRequestHandlerMock() can also be of type object<Xabbuh\XApi\Clien...quest\HandlerInterface>. However, the property $requestHandler is declared as type object<PHPUnit_Framework_MockObject_MockObject>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
41
        $this->serializerRegistry = $this->createSerializerRegistryMock();
42
        $this->client = new XApiClient($this->requestHandler, $this->serializerRegistry, '1.0.1');
43
    }
44
45
    public function testGetRequestHandler()
46
    {
47
        $this->assertSame($this->requestHandler, $this->client->getRequestHandler());
48
    }
49
50
    public function testGetSerializerRegistry()
51
    {
52
        $this->assertSame($this->serializerRegistry, $this->client->getSerializerRegistry());
53
    }
54
55
    public function testGetStatementsApi()
56
    {
57
        $this->assertInstanceOf(
58
            'Xabbuh\XApi\Client\Api\StatementsApiClientInterface',
59
            $this->client->getStatementsApiClient()
60
        );
61
    }
62
63
    public function testGetStateApi()
64
    {
65
        $this->assertInstanceOf(
66
            'Xabbuh\XApi\Client\Api\StateApiClientInterface',
67
            $this->client->getStateApiClient()
68
        );
69
    }
70
71
    public function testGetActivityProfileApi()
72
    {
73
        $this->assertInstanceOf(
74
            'Xabbuh\XApi\Client\Api\ActivityProfileApiClientInterface',
75
            $this->client->getActivityProfileApiClient()
76
        );
77
    }
78
79
    public function testGetAgentProfileApi()
80
    {
81
        $this->assertInstanceOf(
82
            'Xabbuh\XApi\Client\Api\AgentProfileApiClientInterface',
83
            $this->client->getAgentProfileApiClient()
84
        );
85
    }
86
87
    /**
88
     * @return HandlerInterface|\PHPUnit_Framework_MockObject_MockObject
89
     */
90
    private function createRequestHandlerMock()
91
    {
92
        return $this->getMock('\Xabbuh\XApi\Client\Request\HandlerInterface');
93
    }
94
95
    /**
96
     * @return SerializerRegistryInterface|\PHPUnit_Framework_MockObject_MockObject
97
     */
98
    private function createSerializerRegistryMock()
99
    {
100
        $serializerRegistry = $this->getMock('\Xabbuh\XApi\Serializer\SerializerRegistryInterface');
101
102
        $statementSerializer = $this->getMock('\Xabbuh\XApi\Serializer\StatementSerializerInterface');
103
        $serializerRegistry
104
            ->expects($this->any())
105
            ->method('getStatementSerializer')
106
            ->will($this->returnValue($statementSerializer));
107
108
        $statementResultSerializer = $this->getMock('\Xabbuh\XApi\Serializer\StatementResultSerializerInterface');
109
        $serializerRegistry
110
            ->expects($this->any())
111
            ->method('getStatementResultSerializer')
112
            ->will($this->returnValue($statementResultSerializer));
113
114
        $actorSerializer = $this->getMock('\Xabbuh\XApi\Serializer\ActorSerializerInterface');
115
        $serializerRegistry
116
            ->expects($this->any())
117
            ->method('getActorSerializer')
118
            ->will($this->returnValue($actorSerializer));
119
120
        $documentDataSerializer = $this->getMock('\Xabbuh\XApi\Serializer\DocumentDataSerializerInterface');
121
        $serializerRegistry
122
            ->expects($this->any())
123
            ->method('getDocumentDataSerializer')
124
            ->will($this->returnValue($documentDataSerializer));
125
126
        return $serializerRegistry;
127
    }
128
}
129