Passed
Pull Request — master (#107)
by Simon
01:33
created

testAfterCallActionHandlerDevBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverLeague\IDEAnnotator\Tests;
4
5
use SilverLeague\IDEAnnotator\DataObjectAnnotator;
6
use SilverLeague\IDEAnnotator\Extensions\Annotatable;
7
use SilverLeague\IDEAnnotator\Helpers\AnnotatePermissionChecker;
8
use SilverStripe\Control\Controller;
9
use SilverStripe\Control\HTTPRequest;
10
use SilverStripe\Core\Environment;
11
use SilverStripe\Core\Injector\Injector;
12
use SilverStripe\Dev\SapphireTest;
13
14
class AnnotatableTest extends SapphireTest
15
{
16
17
    /**
18
     * @var Annotatable
19
     */
20
    protected $extension;
21
22
    protected function setUp()
23
    {
24
        parent::setUp();
25
        $this->extension = Injector::inst()->get(Annotatable::class);
26
        $this->extension->setOwner(Controller::create());
27
    }
28
29
    public function testOutput()
30
    {
31
        $this->extension->displayMessage('Hello world');
32
        $this->expectOutputString("\nHello world\n\n");
33
    }
34
35
    public function testSetUp()
36
    {
37
        $this->extension->setUp();
38
        $this->assertInstanceOf(DataObjectAnnotator::class, $this->extension->getAnnotator());
39
        $this->assertInstanceOf(AnnotatePermissionChecker::class, $this->extension->getPermissionChecker());
40
    }
41
42
    public function testAfterCallActionHandlerRequestBlock()
43
    {
44
        $request = new HTTPRequest('GET', '/dev/build', ['skipannotation' => true]);
45
        $this->extension->getOwner()->setRequest($request);
46
47
        $this->assertNull($this->extension->afterCallActionHandler());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->extension->afterCallActionHandler() targeting SilverLeague\IDEAnnotato...fterCallActionHandler() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
48
    }
49
50
    public function testAfterCallActionHandlerConfigBlock()
51
    {
52
        DataObjectAnnotator::config()->set('enabled', false);
53
54
        $this->assertNull($this->extension->afterCallActionHandler());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->extension->afterCallActionHandler() targeting SilverLeague\IDEAnnotato...fterCallActionHandler() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
55
    }
56
57
    public function testAfterCallActionHandlerDevBlock()
58
    {
59
        Environment::setEnv('SS_ENVIRONMENT_TYPE', 'Live');
60
61
        $this->assertNull($this->extension->afterCallActionHandler());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->extension->afterCallActionHandler() targeting SilverLeague\IDEAnnotato...fterCallActionHandler() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
62
    }
63
}
64