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

AnnotateChangedDBSpecsTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testManuallyCommentedTagsWillNotBeRemoved() 0 11 1
A testNonSupportedTagsWillNotBeTouched() 0 6 1
A testChangedDBSpecifications() 0 6 1
A setUp() 0 9 1
A tearDown() 0 3 1
1
<?php
2
3
namespace SilverLeague\IDEAnnotator\Tests;
4
5
use PHPUnit_Framework_TestCase;
6
use SilverLeague\IDEAnnotator\AnnotateClassInfo;
7
use SilverLeague\IDEAnnotator\AnnotatePermissionChecker;
8
use SilverLeague\IDEAnnotator\DataObjectAnnotator;
9
use SilverStripe\Core\Injector\Injector;
10
use SilverStripe\Core\Config\Config;
11
use SilverStripe\Dev\SapphireTest;
12
use SilverStripe\Control\Director;
13
14
/**
15
 * This test should fail, if a DB property is removed from
16
 * a class, but the property itself still exists after generation
17
 *
18
 * @mixin PHPUnit_Framework_TestCase
19
 */
20
class AnnotateChangedDBSpecsTest 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
    protected $annotator;
26
27
    /**
28
     * @var AnnotatePermissionChecker
29
     */
30
    protected $permissionChecker;
31
32
    /**
33
     * Setup Defaults
34
     */
35
    public function setUp()
36
    {
37
        parent::setUp();
38
        Config::modify()->set(Director::class, 'environment_type', 'dev');
39
        Config::modify()->set(DataObjectAnnotator::class, 'enabled', true);
40
        Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', ['ideannotator']);
41
        Config::modify()->merge(TeamChanged::class, 'extensions', [Team_Extension::class]);
2 ignored issues
show
Bug introduced by
The type SilverLeague\IDEAnnotator\Tests\TeamChanged 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...
Bug introduced by
The type SilverLeague\IDEAnnotator\Tests\Team_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...
42
43
        $this->annotator = Injector::inst()->get(MockDataObjectAnnotator::class);
44
    }
45
46
    public function testChangedDBSpecifications()
47
    {
48
        $classInfo = new AnnotateClassInfo(TeamChanged::class);
49
        $filePath = $classInfo->getClassFilePath();
50
        $content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), TeamChanged::class);
51
        $this->assertNotContains('VisitCount', $content);
52
    }
53
54
    public function testNonSupportedTagsWillNotBeTouched()
55
    {
56
        $classInfo = new AnnotateClassInfo(TeamChanged::class);
57
        $filePath = $classInfo->getClassFilePath();
58
        $content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), TeamChanged::class);
59
        $this->assertContains('Simon', $content);
60
    }
61
62
    public function testManuallyCommentedTagsWillNotBeRemoved()
63
    {
64
        Config::modify()->set(TeamChanged::class, 'extensions', [Team_Extension::class]);
65
66
        $classInfo = new AnnotateClassInfo(TeamChanged::class);
67
        $filePath = $classInfo->getClassFilePath();
68
        $content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), TeamChanged::class);
69
70
        $this->assertContains('The Team Name', $content);
71
        $this->assertContains('This adds extra methods', $content);
72
        $this->assertContains('This is the Boss', $content);
73
    }
74
75
    public function tearDown()
76
    {
77
        parent::tearDown();
78
    }
79
}
80