Completed
Pull Request — master (#30)
by Harry
02:53 queued 01:19
created

RequestHeaderMiddlewareTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 26
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testApplyRequest() 0 10 1
A testApplyResponse() 0 4 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 RequestHeaderMiddlewareTest extends UnitTestCase
18
{
19
    public function setUp()
20
    {
21
        $this->request = $this->mockRequest();
0 ignored issues
show
Bug introduced by
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
        $this->response = $this->mockResponse();
0 ignored issues
show
Bug introduced by
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
24
        $this->middleware = new RequestHeaderMiddleware();
0 ignored issues
show
Bug introduced by
The property middleware does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    public function testApplyRequest()
28
    {
29
        $requestA = clone $this->request;
30
        $requestB = clone $requestA;
31
32
        $this->request->shouldReceive('withHeader')->once()->with('Accept-Encoding', 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3')->andReturn($requestA);
33
        $requestA->shouldReceive('withHeader')->once()->with('Content-Type', 'application/json')->andReturn($requestB);
34
35
        $this->assertSame($requestB, $this->middleware->applyRequest($this->request, []));
36
    }
37
38
    public function testApplyResponse()
39
    {
40
        $this->assertSame($this->response, $this->middleware->applyResponse($this->request, $this->response, []));
41
    }
42
}
43