Failed Conditions
Pull Request — master (#25)
by Chad
02:50
created

RequestTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A construct() 0 12 1
A constructWithInvalidParameters() 0 4 1
A badData() 0 15 1
1
<?php
2
namespace Chadicus\Marvel\Api;
3
4
/**
5
 * Unit tests for the Request class.
6
 *
7
 * @coversDefaultClass \Chadicus\Marvel\Api\Request
8
 */
9
final class RequestTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * Verify basic functionality of the request object.
13
     *
14
     * @test
15
     * @covers ::__construct
16
     * @covers ::getUrl
17
     * @covers ::getBody
18
     * @covers ::getMethod
19
     * @covers ::getHeaders
20
     *
21
     * @return void
22
     */
23
    public function construct()
24
    {
25
        $url = 'a url';
26
        $method = 'a method';
27
        $body = ['some' => 'data'];
28
        $headers = ['key' => 'value'];
29
        $request = new Request($url, $method, $headers, $body);
30
        $this->assertSame($url, $request->getUrl());
31
        $this->assertSame($method, $request->getMethod());
32
        $this->assertSame($headers, $request->getHeaders());
33
        $this->assertSame($body, $request->getBody());
34
    }
35
36
    /**
37
     * Verify invalid constructor parameters cause exceptions.
38
     *
39
     * @param mixed $url     The url of the request.
40
     * @param mixed $method  The http method of the request.
41
     * @param array $headers The headers of the request.
42
     * @param array $body    The body of the request.
43
     *
44
     * @test
45
     * @covers ::__construct
46
     * @dataProvider badData
47
     * @expectedException \InvalidArgumentException
48
     *
49
     * @return void
50
     */
51
    public function constructWithInvalidParameters($url, $method, array $headers = [], array $body = [])
52
    {
53
        new Request($url, $method, $headers, $body);
54
    }
55
56
    /**
57
     * Provides data for __construct test.
58
     *
59
     * @return array
60
     */
61
    public function badData()
62
    {
63
        return [
64
            // url checks
65
            'url is null' => [null, 'method', [], []],
66
            'url is whitespace' => [" \n ", 'method', [], []],
67
            'url is empty' => ['', 'method', [], []],
68
            'url is not a string' => [1, 'method', [], []],
69
            // method checks
70
            'method is null' => ['url', null, [], []],
71
            'method is whitespace' => ['url', " \n ", [], []],
72
            'method is empty' => ['url', '', [], []],
73
            'method is not a string' => ['url', 1, [], []],
74
        ];
75
    }
76
}
77