|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class NamespaceHelperTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var NamespaceHelper |
|
11
|
|
|
*/ |
|
12
|
|
|
private static $helper; |
|
13
|
|
|
|
|
14
|
|
|
public static function setupBeforeClass() |
|
15
|
|
|
{ |
|
16
|
|
|
self::$helper = new NamespaceHelper(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testCropSuffix() |
|
20
|
|
|
{ |
|
21
|
|
|
$fqn = 'FooBar'; |
|
22
|
|
|
$suffix = 'Bar'; |
|
23
|
|
|
$expected = 'Foo'; |
|
24
|
|
|
$actual = self::$helper->cropSuffix($fqn, $suffix); |
|
25
|
|
|
$this->assertSame($expected, $actual); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testCropSuffixWhereSuffixNotInThere() |
|
29
|
|
|
{ |
|
30
|
|
|
$fqn = 'FooBar'; |
|
31
|
|
|
$suffix = 'Cheese'; |
|
32
|
|
|
$expected = 'FooBar'; |
|
33
|
|
|
$actual = self::$helper->cropSuffix($fqn, $suffix); |
|
34
|
|
|
$this->assertSame($expected, $actual); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGetObjectShortName() |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
$expectedToObjects = [ |
|
41
|
|
|
'NamespaceHelperTest' => $this, |
|
42
|
|
|
'NamespaceHelper' => self::$helper, |
|
43
|
|
|
]; |
|
44
|
|
|
$actual = []; |
|
45
|
|
|
foreach ($expectedToObjects as $object) { |
|
46
|
|
|
$actual[self::$helper->getObjectShortName($object)] = $object; |
|
47
|
|
|
} |
|
48
|
|
|
$this->assertSame($expectedToObjects, $actual); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testGetObjectFqn() |
|
52
|
|
|
{ |
|
53
|
|
|
|
|
54
|
|
|
$expectedToObjects = [ |
|
55
|
|
|
\get_class($this) => $this, |
|
56
|
|
|
\get_class(self::$helper) => self::$helper, |
|
57
|
|
|
]; |
|
58
|
|
|
$actual = []; |
|
59
|
|
|
foreach ($expectedToObjects as $object) { |
|
60
|
|
|
$actual[self::$helper->getObjectFqn($object)] = $object; |
|
61
|
|
|
} |
|
62
|
|
|
$this->assertSame($expectedToObjects, $actual); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testGetClassShortName() |
|
66
|
|
|
{ |
|
67
|
|
|
$expectedToFqns = [ |
|
68
|
|
|
'NamespaceHelperTest' => \get_class($this), |
|
69
|
|
|
'Cheese' => '\\Super\\Cheese', |
|
70
|
|
|
]; |
|
71
|
|
|
$actual = []; |
|
72
|
|
|
foreach ($expectedToFqns as $fqn) { |
|
73
|
|
|
$actual[self::$helper->getClassShortName($fqn)] = $fqn; |
|
74
|
|
|
} |
|
75
|
|
|
$this->assertSame($expectedToFqns, $actual); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|