Completed
Pull Request — master (#98)
by Robbie
01:50
created

testPageControllerGetsAnnotator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 15
loc 15
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
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);
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);
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);
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