Passed
Pull Request — master (#98)
by Robbie
01:42
created

testChangedDBSpecifications()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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