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

AnnotatableTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
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\Director;
10
use SilverStripe\Control\HTTPRequest;
11
use SilverStripe\Core\Environment;
12
use SilverStripe\Core\Injector\Injector;
13
use SilverStripe\Dev\SapphireTest;
14
15
class AnnotatableTest extends SapphireTest
16
{
17
18
    /**
19
     * @var Annotatable
20
     */
21
    protected $extension;
22
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
        $this->extension = Injector::inst()->get(Annotatable::class);
27
        $this->extension->setOwner(Controller::create());
28
    }
29
    public function testSetUp()
30
    {
31
        $this->extension->setUp();
32
        $this->assertInstanceOf(DataObjectAnnotator::class, $this->extension->getAnnotator());
33
        $this->assertInstanceOf(AnnotatePermissionChecker::class, $this->extension->getPermissionChecker());
34
    }
35
36
    public function testOutput()
37
    {
38
        $this->extension->displayMessage('Hello world');
39
        $this->expectOutputString("\nHello world\n\n");
40
    }
41
42
    public function testDisplayEndMessage()
43
    {
44
        $this->extension->displayMessage('Hello world', true, true);
45
        $this->expectOutputString("\nHELLO WORLD\n\n");
46
    }
47
48
    public function testDisplayHeaderMessage()
49
    {
50
        $this->extension->displayMessage('Hello world', true);
51
        $this->expectOutputString("\nHELLO WORLD\n\n");
52
    }
53
54
    public function testAfterCallActionHandlerRequestBlock()
55
    {
56
        $request = new HTTPRequest('GET', '/dev/build', ['skipannotation' => true]);
57
        $this->extension->getOwner()->setRequest($request);
58
59
        $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...
60
    }
61
62
    public function testAfterCallActionHandlerConfigBlock()
63
    {
64
        DataObjectAnnotator::config()->set('enabled', false);
65
66
        $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...
67
    }
68
    public function testAfterCallActionHandlerDevBlock()
69
    {
70
        Environment::setEnv('SS_ENVIRONMENT_TYPE', 'Live');
71
72
        $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...
73
    }
74
}
75