Completed
Push — master ( 993045...a7faa2 )
by Christian
05:28 queued 02:54
created

NestedTestController::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * @author Christian Blank <[email protected]>
5
 */
6
class NestedResourceRestControllerTest extends RestTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
8
    public function setUp() {
9
        parent::setUp();
10
        Config::inst()->update('Director', 'rules', [
11
            'v/1/RestTestRoute/$ID/Nested/$OtherID' => 'NestedTestController',
12
        ]);
13
    }
14
15 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...
16
        $id = 'Foo';
17
        $result = $this->makeApiRequest("RestTestRoute/$id/Nested");
18
        $this->assertTrue(array_key_exists('message', $result));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<NestedResourceRestControllerTest>.

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...
19
        $this->assertEquals('Test GET', $result['message']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<NestedResourceRestControllerTest>.

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

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
    }
22
23
    public function testNotProvidedID() {
24
        $this->makeApiRequest("RestTestRoute//Nested", ['code' => 404]);
25
    }
26
27
28 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...
29
        $id = 'Bar';
30
        $result = $this->makeApiRequest("RestTestRoute/$id/Nested", ['method' => 'DELETE']);
31
        $this->assertTrue(array_key_exists('message', $result));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<NestedResourceRestControllerTest>.

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...
32
        $this->assertEquals('Test DELETE', $result['message']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<NestedResourceRestControllerTest>.

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

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
37
class NestedTestController extends NestedResourceRestController implements TestOnly {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
38
39
    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...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
40
        'delete' => true,
41
        'get' => true
42
    ];
43
44
    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...
45
        return ['message' => 'Test GET', 'resource' => $resource];
46
    }
47
48
    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...
49
        return ['message' => 'Test DELETE', 'resource' => $resource];
50
    }
51
52
    protected function getRootResource($id) {
53
        return ['id' => $id];
54
    }
55
}
56