Passed
Push — master ( 4d9ea0...ff80d7 )
by Anton
02:10
created

ControllerTest::testPayloadAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Framework\Http;
10
11
use Spiral\Framework\HttpTest;
12
use Spiral\Http\Diactoros\StreamFactory;
13
14
class ControllerTest extends HttpTest
15
{
16
    public function testIndexAction()
17
    {
18
        $this->assertSame('Hello, Dave.', (string)$this->get('/index')->getBody());
19
        $this->assertSame('Hello, Antony.', (string)$this->get('/index/Antony')->getBody());
20
    }
21
22
    public function testRouteJson()
23
    {
24
        $this->assertSame('{"action":"route","name":"Dave"}', (string)$this->get('/route')->getBody());
25
    }
26
27
    public function test404()
28
    {
29
        $this->assertSame('404', (string)$this->get('/undefined')->getStatusCode());
30
    }
31
32
    public function testPayloadAction()
33
    {
34
        $factory = new StreamFactory();
35
36
        $response = $this->http->handle($this->request('/payload', 'POST', [], [
37
            'Content-Type' => 'application/json;charset=UTF-8;'
38
        ], [])->withBody($factory->createStream('{"a":"b"}')));
39
40
        $this->assertSame('{"a":"b"}', (string)$response->getBody());
41
    }
42
43
    public function testPayloadActionBad()
44
    {
45
        $factory = new StreamFactory();
46
47
        $response = $this->http->handle($this->request('/payload', 'POST', [], [
48
            'Content-Type' => 'application/json;charset=UTF-8;'
49
        ], [])->withBody($factory->createStream('{"a":"b"')));
50
51
        $this->assertSame(400, $response->getStatusCode());
52
    }
53
54
    public function test500()
55
    {
56
        $this->assertSame('500', (string)$this->get('/error')->getStatusCode());
57
    }
58
}
59