|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CSoellinger\SilverStripe\ModelAnnotations\Test\Unit\Util; |
|
4
|
|
|
|
|
5
|
|
|
use CSoellinger\SilverStripe\ModelAnnotations\Util\Util; |
|
6
|
|
|
use Reflection; |
|
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
8
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
9
|
|
|
use SilverStripe\ORM\DataObject; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @internal |
|
13
|
|
|
* |
|
14
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\Util\Util |
|
15
|
|
|
*/ |
|
16
|
|
|
class UtilTest extends SapphireTest |
|
17
|
|
|
{ |
|
18
|
|
|
protected static Util $util; |
|
19
|
|
|
|
|
20
|
|
|
public static function setUpBeforeClass(): void |
|
21
|
|
|
{ |
|
22
|
|
|
parent::setUpBeforeClass(); |
|
23
|
|
|
|
|
24
|
|
|
/** @var Util $util */ |
|
25
|
|
|
$util = Injector::inst()->get(Util::class); |
|
26
|
|
|
|
|
27
|
|
|
self::$util = $util; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\Util\Util::silverStripeToPhpType |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testSilverStripeToPhpType(): void |
|
34
|
|
|
{ |
|
35
|
|
|
self::assertEquals('string', self::$util->silverStripeToPhpType('Varchar')); |
|
36
|
|
|
self::assertEquals('float', self::$util->silverStripeToPhpType('Decimal')); |
|
37
|
|
|
self::assertEquals('bool', self::$util->silverStripeToPhpType('Boolean')); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\Util\Util::fileByFqn |
|
42
|
|
|
*/ |
|
43
|
|
|
public function testFileByFqn(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$classPath = str_replace(BASE_PATH, '', self::$util->fileByFqn(DataObject::class)); |
|
46
|
|
|
|
|
47
|
|
|
self::assertEquals('/vendor/silverstripe/framework/src/ORM/DataObject.php', $classPath); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\Util\Util::fileByFqn |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testFileByFqnFunction(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$functionPath = str_replace(BASE_PATH, '', self::$util->fileByFqn('_t')); |
|
56
|
|
|
|
|
57
|
|
|
self::assertEquals('/vendor/silverstripe/framework/src/includes/functions.php', $functionPath); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\Util\Util::fileByFqn |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testFileByFqnUnknown(): void |
|
64
|
|
|
{ |
|
65
|
|
|
self::assertEquals('', self::$util->fileByFqn('xyz')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\Util\Util::getNamespaceFromFqn |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testGetNamespaceFromFqn(): void |
|
72
|
|
|
{ |
|
73
|
|
|
$namespace = self::$util->getNamespaceFromFqn(self::class); |
|
74
|
|
|
|
|
75
|
|
|
self::assertEquals('CSoellinger\SilverStripe\ModelAnnotations\Test\Unit\Util', $namespace); |
|
76
|
|
|
self::assertEquals('\\', self::$util->getNamespaceFromFqn(Reflection::class)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\Util\Util::getClassesFromNamespace |
|
81
|
|
|
*/ |
|
82
|
|
|
public function testGetClassesFromNamespace(): void |
|
83
|
|
|
{ |
|
84
|
|
|
$namespace = self::$util->getNamespaceFromFqn(self::class); |
|
85
|
|
|
$classes = self::$util->getClassesFromNamespace($namespace); |
|
86
|
|
|
|
|
87
|
|
|
self::assertCount(1, $classes); |
|
88
|
|
|
self::assertEquals($classes[0], self::class); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|