Completed
Push — develop ( 86f0dd...f71342 )
by Adam
12s
created

AbstractRequestTest_MockAbstractRequest::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
4
namespace IBM\Watson\Common\Tests\Message;
5
6
use GuzzleHttp\Client;
7
use IBM\Watson\Common\Message\AbstractRequest;
8
use Mockery as m;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class AbstractRequestTest extends \PHPUnit_Framework_TestCase
12
{
13
    protected $request;
14
15
    public function setUp()
16
    {
17
        $this->request = m::mock('\IBM\Watson\Common\Message\AbstractRequest')->makePartial();
18
        $this->request->initialize();
19
    }
20
21
    public function testConstruct()
22
    {
23
        $this->request = new AbstractRequestTest_MockAbstractRequest(new Client(), new Request());
24
        $this->assertSame([], $this->request->getParameters());
25
    }
26
27
    public function testInitializeWithParameters()
28
    {
29
        $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\Tests\...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
        $this->assertSame('adam', $this->request->getUsername());
0 ignored issues
show
Bug introduced by
The method getUsername does only exist in IBM\Watson\Common\Tests\...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...
31
        $this->assertSame('01234', $this->request->getPassword());
0 ignored issues
show
Bug introduced by
The method getPassword does only exist in IBM\Watson\Common\Tests\...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...
32
    }
33
34
    public function testGetData()
35
    {
36
        $data = ['username' => 'adam', 'password' => '01234'];
37
        $this->request->initialize($data);
0 ignored issues
show
Bug introduced by
The method initialize does only exist in IBM\Watson\Common\Tests\...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...
38
39
        $this->assertSame($data, $this->request->getData());
0 ignored issues
show
Bug introduced by
The method getData does only exist in IBM\Watson\Common\Tests\...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...
40
    }
41
42
    /**
43
     * @expectedException \IBM\Watson\Common\Exception\RuntimeException
44
     * @expectedExceptionMessage Request cannot be modified after it has been sent!
45
     */
46
    public function testInitializeAfterRequestSent()
47
    {
48
        $this->request = new AbstractRequestTest_MockAbstractRequest(new Client(), new Request());
49
        $this->request->send();
50
51
        $this->request->initialize();
52
    }
53
54
    /**
55
     * @expectedException \IBM\Watson\Common\Exception\RuntimeException
56
     * @expectedExceptionMessage Request cannot be modified after it has been sent!
57
     */
58
    public function testSetParameterAfterRequestSent()
59
    {
60
        $this->request = new AbstractRequestTest_MockAbstractRequest(new Client(), new Request());
61
        $this->request->send();
62
63
        $this->request->setUsername('adam');
64
    }
65
66
    /**
67
     * @expectedException \IBM\Watson\Common\Exception\RuntimeException
68
     * @expectedExceptionMessage You must call send() before accessing the Response!
69
     */
70
    public function testGetResponseBeforeRequestSent()
71
    {
72
        $this->request = new AbstractRequestTest_MockAbstractRequest(new Client(), new Request());
73
        $this->request->getResponse();
74
    }
75
76
    public function testGetResponseAfterRequestSent()
77
    {
78
        $this->request = new AbstractRequestTest_MockAbstractRequest(new Client(), new Request());
79
        $this->request->send();
80
81
        $response = $this->request->getResponse();
82
        $this->assertInstanceOf('\IBM\Watson\Common\Message\ResponseInterface', $response);
83
    }
84
}
85
86
class AbstractRequestTest_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...
87
{
88
    public function sendData($data)
89
    {
90
        $this->response = m::mock('\IBM\Watson\Common\Message\AbstractResponse');
91
    }
92
}
93