Completed
Push — develop ( b68cde...86f0dd )
by Adam
57s queued 52s
created

getProtectedHttpRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace IBM\Watson\Common\Tests;
4
5
use IBM\Watson\Common\AbstractService;
6
use IBM\Watson\Common\Message\AbstractRequest;
7
use Mockery as m;
8
9
class AbstractServiceTest extends \PHPUnit_Framework_TestCase
10
{
11
    private $service;
12
13
    public function setUp()
14
    {
15
        $this->service = m::mock('\IBM\Watson\Common\AbstractService')->makePartial();
16
        $this->service->initialize();
17
    }
18
19
    public function testConstruct()
20
    {
21
        $this->service = new AbstractServiceTest_MockAbstractService;
22
        $this->assertInstanceOf('\GuzzleHttp\Client', $this->service->getProtectedHttpClient());
23
        $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Request', $this->service->getProtectedHttpRequest());
24
        $this->assertSame(['username' => '', 'password' => ''], $this->service->getDefaultParameters());
25
    }
26
27
    public function testInitializeDefault()
28
    {
29
        $defaults = [
30
            'username' => 'adam',
31
            'password' => ['01234', '56789']
32
        ];
33
34
        $this->service->shouldReceive('getDefaultParameters')->once()
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<IBM\Watson\Common...st_MockAbstractService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
            ->andReturn($defaults);
36
37
        $this->service->initialize();
38
39
        $expected = [
40
            'username' => 'adam',
41
            'password' => '01234'
42
        ];
43
44
        $this->assertSame($expected, $this->service->getParameters());
45
    }
46
47
    public function testUsername()
48
    {
49
        $this->assertSame($this->service, $this->service->setUsername('adam'));
50
        $this->assertSame('adam', $this->service->getUsername());
51
    }
52
53
    public function testPassword()
54
    {
55
        $this->assertSame($this->service, $this->service->setPassword('01234'));
56
        $this->assertSame('01234', $this->service->getPassword());
57
    }
58
59
    public function testCreateRequest()
60
    {
61
        $this->service = new AbstractServiceTest_MockAbstractService;
62
        $request = $this->service->callCreateRequest(
63
            '\IBM\Watson\Common\Tests\AbstractServiceTest_MockAbstractRequest',
64
            ['username' => 'adam', 'password' => '01234']
65
        );
66
67
        $this->assertSame(['username' => 'adam', 'password' => '01234'], $request->getParameters());
68
    }
69
}
70
71
class AbstractServiceTest_MockAbstractService extends AbstractService
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
72
{
73
    public function getName()
74
    {
75
        return 'Mock Service';
76
    }
77
78
    public function getProtectedHttpClient()
79
    {
80
        return $this->httpClient;
81
    }
82
83
    public function getProtectedHttpRequest()
84
    {
85
        return $this->httpRequest;
86
    }
87
88
    public function callCreateRequest($class, array $parameters)
89
    {
90
        return $this->createRequest($class, $parameters);
91
    }
92
}
93
94
class AbstractServiceTest_MockAbstractRequest extends AbstractRequest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
95
{
96
    public function getData()
97
    {
98
    }
99
    public function sendData($data)
100
    {
101
    }
102
}
103