NestedTestController::getRootResource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Ntb\RestAPI;
4
5
/**
6
 * @author Christian Blank <[email protected]>
7
 */
8
class NestedResourceRestControllerTest extends RestTest {
9
10
    public function setUp() {
11
        parent::setUp();
12
        \Config::inst()->update('Director', 'rules', [
13
            'v/1/RestTestRoute/$ID/Nested/$OtherID' => 'Ntb\RestAPI\NestedTestController',
14
        ]);
15
    }
16
17 View Code Duplication
    public function testControllerGET() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
        $id = 'Foo';
19
        $result = $this->makeApiRequest("RestTestRoute/$id/Nested");
20
        $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\Neste...urceRestControllerTest>.

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...
21
        $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\Neste...urceRestControllerTest>.

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...
22
        $this->assertEquals($id, $result['resource']['id']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\Neste...urceRestControllerTest>.

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...
23
    }
24
25
    public function testNotProvidedID() {
26
        $this->makeApiRequest("RestTestRoute//Nested", ['code' => 404]);
27
    }
28
29
30 View Code Duplication
    public function testControllerDELETE() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
        $id = 'Bar';
32
        $result = $this->makeApiRequest("RestTestRoute/$id/Nested", ['method' => 'DELETE']);
33
        $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\Neste...urceRestControllerTest>.

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
        $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\Neste...urceRestControllerTest>.

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...
35
        $this->assertEquals($id, $result['resource']['id']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\Neste...urceRestControllerTest>.

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...
36
    }
37
}
38
39
class NestedTestController extends NestedResourceRestController implements \TestOnly {
40
41
    private static $allowed_actions = [
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...
42
        'delete' => true,
43
        'get' => true
44
    ];
45
46
    public function get($request, $resource) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
        return ['message' => 'Test GET', 'resource' => $resource];
48
    }
49
50
    public function delete($request, $resource) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
        return ['message' => 'Test DELETE', 'resource' => $resource];
52
    }
53
54
    protected function getRootResource($id) {
55
        return ['id' => $id];
56
    }
57
}
58