1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\IDEAnnotator\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
6
|
|
|
use SilverLeague\IDEAnnotator\DataObjectAnnotator; |
7
|
|
|
use SilverLeague\IDEAnnotator\Helpers\AnnotateClassInfo; |
8
|
|
|
use SilverLeague\IDEAnnotator\Helpers\AnnotatePermissionChecker; |
9
|
|
|
use SilverStripe\Control\Director; |
10
|
|
|
use SilverStripe\Core\Config\Config; |
11
|
|
|
use SilverStripe\Core\Injector\Injector; |
12
|
|
|
use SilverStripe\Dev\SapphireTest; |
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
|
|
|
public function testChangedDBSpecifications() |
33
|
|
|
{ |
34
|
|
|
$classInfo = new AnnotateClassInfo(TeamChanged::class); |
35
|
|
|
$filePath = $classInfo->getClassFilePath(); |
36
|
|
|
$content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), TeamChanged::class); |
37
|
|
|
$this->assertStringNotContainsString('VisitCount', $content); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testNonSupportedTagsWillNotBeTouched() |
41
|
|
|
{ |
42
|
|
|
$classInfo = new AnnotateClassInfo(TeamChanged::class); |
43
|
|
|
$filePath = $classInfo->getClassFilePath(); |
44
|
|
|
$content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), TeamChanged::class); |
45
|
|
|
$this->assertStringContainsString('Simon', $content); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testManuallyCommentedTagsWillNotBeRemoved() |
49
|
|
|
{ |
50
|
|
|
Config::modify()->set(TeamChanged::class, 'extensions', [Team_Extension::class]); |
51
|
|
|
|
52
|
|
|
$classInfo = new AnnotateClassInfo(TeamChanged::class); |
53
|
|
|
$filePath = $classInfo->getClassFilePath(); |
54
|
|
|
$content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), TeamChanged::class); |
55
|
|
|
|
56
|
|
|
$this->assertStringContainsString('The Team Name', $content); |
57
|
|
|
$this->assertStringContainsString('This adds extra methods', $content); |
58
|
|
|
$this->assertStringContainsString('This is the Boss', $content); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function tearDown(): void |
62
|
|
|
{ |
63
|
|
|
parent::tearDown(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Setup Defaults |
68
|
|
|
*/ |
69
|
|
|
protected function setUp(): void |
70
|
|
|
{ |
71
|
|
|
parent::setUp(); |
72
|
|
|
Config::modify()->set(Director::class, 'environment_type', 'dev'); |
73
|
|
|
Config::modify()->set(DataObjectAnnotator::class, 'enabled', true); |
74
|
|
|
Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', ['ideannotator']); |
75
|
|
|
Config::modify()->merge(TeamChanged::class, 'extensions', [Team_Extension::class]); |
76
|
|
|
|
77
|
|
|
$this->annotator = Injector::inst()->get(MockDataObjectAnnotator::class); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|