AbstractRequestTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 0
loc 89
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testConstruct() 0 5 1
A testInitializeWithParams() 0 6 1
A testInitializeAfterRequestSent() 0 7 1
A testUsername() 0 5 1
A testPassword() 0 5 1
A testSetParameterAfterRequestSent() 0 7 1
A testGetResponseBeforeRequestSent() 0 5 1
A testGetResponseAfterRequestSent() 0 8 1
A testSend() 0 10 1
1
<?php
2
3
4
namespace IBM\Watson\Common\Message;
5
6
use IBM\Watson\Tests\TestCase;
7
use Mockery as m;
8
9
class AbstractRequestTest extends TestCase
10
{
11
    private $request;
12
13
    public function setUp()
14
    {
15
        $this->request = m::mock('\IBM\Watson\Common\Message\AbstractRequest')->makePartial();
16
        $this->request->initialize();
17
    }
18
19
    public function testConstruct()
20
    {
21
        $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest());
22
        $this->assertSame([], $this->request->getParameters());
23
    }
24
25
    public function testInitializeWithParams()
26
    {
27
        $this->assertSame($this->request, $this->request->initialize(['username' => 'adam', 'password' => '01234']));
0 ignored issues
show
Bug introduced by
The method initialize does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
28
        $this->assertSame('adam', $this->request->getUsername());
0 ignored issues
show
Bug introduced by
The method getUsername does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
29
        $this->assertSame('01234', $this->request->getPassword());
0 ignored issues
show
Bug introduced by
The method getPassword does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
30
    }
31
32
    /**
33
     * @expectedException \IBM\Watson\Common\Exception\RuntimeException
34
     * @expectedExceptionMessage Request cannot be modified after it has been sent!
35
     */
36
    public function testInitializeAfterRequestSent()
37
    {
38
        $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest());
39
        $this->request->send();
40
41
        $this->request->initialize();
42
    }
43
44
    public function testUsername()
45
    {
46
        $this->assertSame($this->request, $this->request->setUsername('adam'));
0 ignored issues
show
Bug introduced by
The method setUsername does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
47
        $this->assertSame('adam', $this->request->getUsername());
0 ignored issues
show
Bug introduced by
The method getUsername does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
48
    }
49
50
    public function testPassword()
51
    {
52
        $this->assertSame($this->request, $this->request->setPassword('01234'));
0 ignored issues
show
Bug introduced by
The method setPassword does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
53
        $this->assertSame('01234', $this->request->getPassword());
0 ignored issues
show
Bug introduced by
The method getPassword does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
54
    }
55
56
    /**
57
     * @expectedException \IBM\Watson\Common\Exception\RuntimeException
58
     * @expectedExceptionMessage Request cannot be modified after it has been sent!
59
     */
60
    public function testSetParameterAfterRequestSent()
61
    {
62
        $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest());
63
        $this->request->send();
64
65
        $this->request->setUsername('adam');
66
    }
67
68
    /**
69
     * @expectedException \IBM\Watson\Common\Exception\RuntimeException
70
     * @expectedExceptionMessage You must call send() before accessing the response!
71
     */
72
    public function testGetResponseBeforeRequestSent()
73
    {
74
        $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest());
75
        $this->request->getResponse();
76
    }
77
78
    public function testGetResponseAfterRequestSent()
79
    {
80
        $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest());
81
        $this->request->send();
82
83
        $response = $this->request->getResponse();
84
        $this->assertInstanceOf('\IBM\Watson\Common\Message\ResponseInterface', $response);
85
    }
86
87
    public function testSend()
88
    {
89
        $response = m::mock('\IBM\Watson\Common\Message\ResponseInterface');
90
        $data = array('request data');
91
92
        $this->request->shouldReceive('getData')->once()->andReturn($data);
93
        $this->request->shouldReceive('sendData')->once()->with($data)->andReturn($response);
94
95
        $this->assertSame($response, $this->request->send());
0 ignored issues
show
Bug introduced by
The method send does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
96
    }
97
}
98
99
// @codingStandardsIgnoreStart
100
class AbstractRequestTest_MockAbstractRequest extends AbstractRequest
101
{
102
    public function getData()
103
    {
104
    }
105
106
    public function sendData($data)
107
    {
108
        $this->response = m::mock('\IBM\Watson\Common\Message\AbstractResponse');
109
    }
110
}
111
// @codingStandardsIgnoreEnd
112