BaseRestControllerTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ntb\RestAPI;
4
5
use Config;
6
7
/**
8
 * Tests for the base rest controller.
9
 *
10
 * @todo: test different serializers, pagination and error handling
11
 * @author Christian Blank <[email protected]>
12
 */
13
class BaseRestControllerTest extends RestTest {
14
15
    public function setUp() {
16
        parent::setUp();
17
        Config::inst()->update('Director', 'rules', [
18
            'v/1/RestTestRoute/$ID/$OtherID' => 'Ntb\RestAPI\TestController',
19
        ]);
20
    }
21
22
    public function testControllerGET() {
23
        $result = $this->makeApiRequest('RestTestRoute');
24
25
        $this->assertTrue(array_key_exists('message', $result));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
        $this->assertEquals('Test GET', $result['message']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
    }
28
29
    public function testControllerDELETE() {
30
        $result = $this->makeApiRequest('RestTestRoute', ['method' => 'DELETE']);
31
32
        $this->assertTrue(array_key_exists('message', $result));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
        $this->assertEquals('Test DELETE', $result['message']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
    }
35
36
    public function testControllerPOST() {
37
        $result = $this->makeApiRequest('RestTestRoute', ['method' => 'POST']);
38
39
        $this->assertTrue(array_key_exists('message', $result));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        $this->assertEquals('Test POST', $result['message']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
    }
42
43
    public function testControllerPUT() {
44
        $result = $this->makeApiRequest('RestTestRoute', ['method' => 'PUT']);
45
46
        $this->assertTrue(array_key_exists('message', $result));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
        $this->assertEquals('Test PUT', $result['message']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
    }
49
50
    public function testControllerHEAD() {
51
        $result = $this->makeApiRequest('RestTestRoute', ['method' => 'HEAD']);
52
        $this->assertEquals(null, $result);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
    }
54
55
    public function testControllerPATCH() {
56
        $result = $this->makeApiRequest('RestTestRoute', ['method' => 'PATCH']);
57
58
        $this->assertTrue(array_key_exists('message', $result));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
        $this->assertEquals('Test PATCH', $result['message']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\BaseRestControllerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
    }
61
}
62
63
class TestController extends BaseRestController implements \TestOnly {
64
65
    private static $allowed_actions = array (
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
66
        'post' => true,
67
        'delete' => true,
68
        'get' => true,
69
        'put' => true,
70
        'patch' => true
71
    );
72
73
    public function get() {
74
        return ['message' => 'Test GET'];
75
    }
76
77
    public function post() {
78
        return ['message' => 'Test POST'];
79
    }
80
81
    public function put() {
82
        return ['message' => 'Test PUT'];
83
    }
84
85
    public function delete() {
86
        return ['message' => 'Test DELETE'];
87
    }
88
89
    public function patch() {
90
        return ['message' => 'Test PATCH'];
91
    }
92
}
93