Passed
Branch master (608a5d)
by Simon
01:54
created

testAnnotateControllerExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 11
loc 11
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace SilverLeague\IDEAnnotator\Tests;
4
5
use PHPUnit_Framework_TestCase;
6
use SilverLeague\IDEAnnotator\AnnotateClassInfo;
7
use SilverStripe\Core\Injector\Injector;
8
use SilverStripe\Core\Config\Config;
9
use SilverLeague\IDEAnnotator\AnnotatePermissionChecker;
10
use SilverLeague\IDEAnnotator\DataObjectAnnotator;
11
use SilverStripe\Dev\SapphireTest;
12
13
/**
14
 * Class DataObjectAnnotatorTest
15
 *
16
 * Several tests to make sure the Annotator does it's job correctly
17
 *
18
 * @mixin PHPUnit_Framework_TestCase
19
 */
20
class ControllerAnnotatorTest extends SapphireTest
21
{
22
    /**
23
     * @var MockDataObjectAnnotator
1 ignored issue
show
Bug introduced by
The type SilverLeague\IDEAnnotato...MockDataObjectAnnotator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
     */
25
    private $annotator;
26
27
    /**
28
     * @var AnnotatePermissionChecker $permissionChecker
29
     */
30
    private $permissionChecker;
31
32
    /**
33
     * Setup Defaults
34
     */
35 View Code Duplication
    public function setUp()
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...
36
    {
37
        parent::setUp();
38
        Config::modify()->set(DataObjectAnnotator::class, 'enabled', true);
39
        Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', ['ideannotator']);
40
41
        $this->annotator = Injector::inst()->get(MockDataObjectAnnotator::class);
42
        $this->permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class);
43
    }
44
45 View Code Duplication
    public function testPageGetsAnnotated()
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...
46
    {
47
        $classInfo = new AnnotateClassInfo(AnnotatorPageTest::class);
1 ignored issue
show
Bug introduced by
The type SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
48
        $filePath = $classInfo->getClassFilePath();
49
50
        $content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), AnnotatorPageTest::class);
51
52
        $this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest', $content);
53
        $this->assertContains('@property string $SubTitle', $content);
54
    }
55
56 View Code Duplication
    public function testPageControllerGetsAnnotator()
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...
57
    {
58
        $classInfo = new AnnotateClassInfo(AnnotatorPageTestController::class);
1 ignored issue
show
Bug introduced by
The type SilverLeague\IDEAnnotato...tatorPageTestController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
        $filePath = $classInfo->getClassFilePath();
60
61
        $content = $this->annotator->getGeneratedFileContent(
62
            file_get_contents($filePath),
63
            AnnotatorPageTestController::class
64
        );
65
66
        $this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTestController', $content);
67
        $this->assertContains('@property \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest dataRecord', $content);
68
        $this->assertContains('@method \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest data()', $content);
69
        $this->assertContains('@mixin \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest', $content);
70
        $this->assertContains('@mixin \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest_Extension', $content);
71
    }
72
73
    /**
74
     * Test the generation of annotations for an Extension
75
     */
76 View Code Duplication
    public function testAnnotateControllerExtension()
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...
77
    {
78
        $classInfo = new AnnotateClassInfo(AnnotatorPageTest_Extension::class);
1 ignored issue
show
Bug introduced by
The type SilverLeague\IDEAnnotato...tatorPageTest_Extension was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
79
        $filePath = $classInfo->getClassFilePath();
80
        $original = file_get_contents($filePath);
81
        $annotated = $this->annotator->getGeneratedFileContent($original, AnnotatorPageTest_Extension::class);
82
83
        $this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest_Extension', $annotated);
84
        $this->assertContains(
85
            '@property \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTestController|\SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest_Extension $owner',
86
            $annotated
87
        );
88
    }
89
90
    public function tearDown()
91
    {
92
        parent::tearDown();
93
    }
94
}
95