|
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
|
|
|
|