ResponseFactoryMiddlewareTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testApplyRequest() 0 3 1
A testApplyResponse() 0 6 1
A setUp() 0 7 1
1
<?php
2
/*
3
 * This file is part of Guzzle HTTP JSON-RPC
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE
11
 * @link http://github.com/graze/guzzle-jsonrpc
12
 */
13
namespace Graze\GuzzleHttp\JsonRpc\Middleware;
14
15
use Graze\GuzzleHttp\JsonRpc\Test\UnitTestCase;
16
17
class ResponseFactoryMiddlewareTest extends UnitTestCase
18
{
19
    public function setUp()
20
    {
21
        $this->request = $this->mockRequest();
0 ignored issues
show
Bug Best Practice introduced by
The property request does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
        $this->response = $this->mockResponse();
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
        $this->factory = $this->mockMessageFactory();
0 ignored issues
show
Bug Best Practice introduced by
The property factory does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
25
        $this->middleware = new ResponseFactoryMiddleware($this->factory);
0 ignored issues
show
Bug Best Practice introduced by
The property middleware does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
$this->factory of type Mockery\MockInterface is incompatible with the type Graze\GuzzleHttp\JsonRpc...MessageFactoryInterface expected by parameter $factory of Graze\GuzzleHttp\JsonRpc...ddleware::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        $this->middleware = new ResponseFactoryMiddleware(/** @scrutinizer ignore-type */ $this->factory);
Loading history...
26
    }
27
28
    public function testApplyRequest()
29
    {
30
        $this->assertSame($this->request, $this->middleware->applyRequest($this->request, []));
31
    }
32
33
    public function testApplyResponse()
34
    {
35
        $newResponse = clone $this->response;
36
        $this->factory->shouldReceive('fromResponse')->once()->with($this->response)->andReturn($newResponse);
37
38
        $this->assertSame($newResponse, $this->middleware->applyResponse($this->request, $this->response, []));
39
    }
40
}
41