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

ControllerAnnotatorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 65.75 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 48
loc 73
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testPageGetsAnnotated() 9 9 1
A tearDown() 0 3 1
A testAnnotateControllerExtension() 11 11 1
A setUp() 8 8 1
A testPageControllerGetsAnnotator() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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