Test Setup Failed
Push — master ( 553e74...c78a38 )
by Carsten
06:57
created

RequestTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testMissingGetPath() 0 4 1
A testMissingPostPath() 0 4 1
A testMissingPutPath() 0 4 1
A testMissingPatchPath() 0 4 1
A testMissingDeletePath() 0 4 1
A testResponseInstance() 0 5 1
A testBadAuthentication() 0 9 1
A testSuccessfullGetResponse() 0 6 1
A testFailedGetResponse() 0 6 1
1
<?php
2
3
namespace Lenius\Economic\Tests;
4
5
use Lenius\Economic\API\Client;
6
use Lenius\Economic\API\Request;
7
use Lenius\Economic\API\Response;
8
use PHPUnit\Framework\TestCase;
9
10
class RequestTest extends TestCase
11
{
12
    /** @var Request */
13
    protected $request;
14
15
    public function setUp()
16
    {
17
        $client = new Client('demo', 'demo');
18
        $this->request = new Request($client);
19
    }
20
21
    /**
22
     * @expectedException InvalidArgumentException
23
     */
24
    public function testMissingGetPath()
25
    {
26
        $this->request->get('');
27
    }
28
29
    /**
30
     * @expectedException InvalidArgumentException
31
     */
32
    public function testMissingPostPath()
33
    {
34
        $this->request->post('');
35
    }
36
37
    /**
38
     * @expectedException InvalidArgumentException
39
     */
40
    public function testMissingPutPath()
41
    {
42
        $this->request->put('');
43
    }
44
45
    /**
46
     * @expectedException InvalidArgumentException
47
     */
48
    public function testMissingPatchPath()
49
    {
50
        $this->request->patch('');
51
    }
52
53
    /**
54
     * @expectedException InvalidArgumentException
55
     */
56
    public function testMissingDeletePath()
57
    {
58
        $this->request->delete('');
59
    }
60
61
    public function testResponseInstance()
62
    {
63
        $getResponse = $this->request->get('/');
64
        $this->assertTrue(($getResponse instanceof Response));
65
    }
66
67
    public function testBadAuthentication()
68
    {
69
        $client = new Client('foo', 'foo');
70
        $request = new Request($client);
71
72
        $response = $request->get('/units', ['demo' => 'true']);
73
74
        $this->assertEquals(401, $response->httpStatus());
75
    }
76
77
    public function testSuccessfullGetResponse()
78
    {
79
        $response = $this->request->get('/units', ['demo' => 'true']);
80
81
        $this->assertTrue($response->isSuccess());
82
    }
83
84
    public function testFailedGetResponse()
85
    {
86
        $pingResponse = $this->request->get('/notfound');
87
88
        $this->assertFalse($pingResponse->isSuccess());
89
    }
90
}
91