Completed
Push — develop ( 034857...1b157a )
by Christian
8s
created

PaginationExtensionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Ntb\RestAPI;
4
5
use Object;
6
use SapphireTest;
7
use SS_HTTPRequest;
8
use TestOnly;
9
10
class PaginationExtensionTest extends SapphireTest {
11
12
    private $controller;
13
14
    public function setUp() {
15
        parent::setUp();
16
        PaginationTestController::add_extension('Ntb\RestAPI\PaginationExtension');
17
        $this->controller = new PaginationTestController();
18
    }
19
20
    public function testDefaultLimit() {
21
        $this->assertEquals(20, $this->controller->getLimit(new SS_HTTPRequest("GET", "/")));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\PaginationExtensionTest>.

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
    }
23
24
    public function testDefaultOffset() {
25
        $this->assertEquals(0, $this->controller->getOffset(new SS_HTTPRequest("GET", "/")));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\PaginationExtensionTest>.

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
    }
27
}
28
29
class PaginationTestController extends Object 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...
30
31
    public function getLimit($request) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
32
        return $this->limit($request);
0 ignored issues
show
Documentation Bug introduced by
The method limit does not exist on object<Ntb\RestAPI\PaginationTestController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
33
    }
34
35
    public function getOffset($request) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
        return $this->offset($request);
0 ignored issues
show
Bug introduced by
The method offset() does not exist on Ntb\RestAPI\PaginationTestController. Did you maybe mean getOffset()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37
    }
38
}