1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\EasyExtendsBundle\Tests\Bundle; |
15
|
|
|
|
16
|
|
|
// Unfortunately phpunit cannot mock a class in chosen namespace. |
17
|
|
|
// Therefore mocks are stored in Fixtures/bundle1 directory and required here. |
18
|
|
|
require_once __DIR__.'/Fixtures/bundle1/SonataAcmeBundle.php'; |
19
|
|
|
require_once __DIR__.'/Fixtures/bundle1/SonataNotExtendableBundle.php'; |
20
|
|
|
require_once __DIR__.'/Fixtures/bundle1/SymfonyNotExtendableBundle.php'; |
21
|
|
|
require_once __DIR__.'/Fixtures/bundle1/LongNamespaceBundle.php'; |
22
|
|
|
require_once __DIR__.'/Fixtures/bundle1/AcmeBundle.php'; |
23
|
|
|
|
24
|
|
|
use PHPUnit\Framework\TestCase; |
25
|
|
|
use Sonata\EasyExtendsBundle\Bundle\BundleMetadata; |
26
|
|
|
use Sonata\EasyExtendsBundle\Bundle\OdmMetadata; |
27
|
|
|
use Sonata\EasyExtendsBundle\Bundle\OrmMetadata; |
28
|
|
|
|
29
|
|
|
class BundleMetadataTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
public function testBundleMetadata(): void |
32
|
|
|
{ |
33
|
|
|
$bundle = new \Sonata\AcmeBundle\SonataAcmeBundle(); |
34
|
|
|
|
35
|
|
|
$bundleMetadata = new BundleMetadata($bundle, [ |
36
|
|
|
'application_dir' => 'app/Application/:vendor', |
37
|
|
|
'namespace' => 'Application\\:vendor', |
38
|
|
|
'namespace_prefix' => '', |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$this->assertTrue($bundleMetadata->isExtendable()); |
42
|
|
|
$this->assertTrue($bundleMetadata->isValid()); |
43
|
|
|
$this->assertSame('SonataAcmeBundle', $bundleMetadata->getName()); |
44
|
|
|
$this->assertSame('Sonata', $bundleMetadata->getVendor()); |
45
|
|
|
$this->assertSame('Sonata\AcmeBundle', $bundleMetadata->getNamespace()); |
46
|
|
|
$this->assertSame('app/Application/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory()); |
47
|
|
|
$this->assertSame('Application\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace()); |
48
|
|
|
$this->assertInstanceOf(OrmMetadata::class, $bundleMetadata->getOrmMetadata()); |
49
|
|
|
$this->assertInstanceOf(OdmMetadata::class, $bundleMetadata->getOdmMetadata()); |
50
|
|
|
$this->assertSame($bundle, $bundleMetadata->getBundle()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testCustomNamespace(): void |
54
|
|
|
{ |
55
|
|
|
$bundle = new \Sonata\AcmeBundle\SonataAcmeBundle(); |
56
|
|
|
|
57
|
|
|
$bundleMetadata = new BundleMetadata($bundle, [ |
58
|
|
|
'application_dir' => 'app/Custom/:vendor', |
59
|
|
|
'namespace' => 'Custom\\:vendor', |
60
|
|
|
'namespace_prefix' => '', |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
$this->assertSame('app/Custom/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory()); |
64
|
|
|
$this->assertSame('Custom\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testApplicationNotExtendableBundle(): void |
68
|
|
|
{ |
69
|
|
|
$bundle = new \Application\Sonata\NotExtendableBundle(); |
70
|
|
|
|
71
|
|
|
$bundleMetadata = new BundleMetadata($bundle, [ |
72
|
|
|
'application_dir' => 'Application', |
73
|
|
|
'namespace' => 'Application', |
74
|
|
|
'namespace_prefix' => '', |
75
|
|
|
]); |
76
|
|
|
|
77
|
|
|
$this->assertFalse($bundleMetadata->isValid()); |
78
|
|
|
$this->assertFalse($bundleMetadata->isExtendable()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testSymfonyNotExtendableBundle(): void |
82
|
|
|
{ |
83
|
|
|
$bundle = new \Symfony\Bundle\NotExtendableBundle(); |
84
|
|
|
|
85
|
|
|
$bundleMetadata = new BundleMetadata($bundle, [ |
86
|
|
|
'application_dir' => 'Application', |
87
|
|
|
'namespace' => 'Application', |
88
|
|
|
'namespace_prefix' => '', |
89
|
|
|
]); |
90
|
|
|
|
91
|
|
|
$this->assertFalse($bundleMetadata->isValid()); |
92
|
|
|
$this->assertFalse($bundleMetadata->isExtendable()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testBundleNamespace(): void |
96
|
|
|
{ |
97
|
|
|
$bundle = new \Sonata\Bundle\AcmeBundle\LongNamespaceBundle(); |
98
|
|
|
|
99
|
|
|
$bundleMetadata = new BundleMetadata($bundle, [ |
100
|
|
|
'application_dir' => 'Application', |
101
|
|
|
'namespace' => 'Application', |
102
|
|
|
'namespace_prefix' => '', |
103
|
|
|
]); |
104
|
|
|
|
105
|
|
|
$this->assertFalse($bundleMetadata->isValid()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testBundleName(): void |
109
|
|
|
{ |
110
|
|
|
$bundle = new \Sonata\AcmeBundle\AcmeBundle(); |
111
|
|
|
|
112
|
|
|
$bundleMetadata = new BundleMetadata($bundle, [ |
113
|
|
|
'application_dir' => 'Application', |
114
|
|
|
'namespace' => 'Application', |
115
|
|
|
'namespace_prefix' => '', |
116
|
|
|
]); |
117
|
|
|
|
118
|
|
|
$this->assertFalse($bundleMetadata->isValid()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testWithNamespacePrefix(): void |
122
|
|
|
{ |
123
|
|
|
$bundle = new \Sonata\AcmeBundle\SonataAcmeBundle(); |
124
|
|
|
|
125
|
|
|
$bundleMetadata = new BundleMetadata($bundle, [ |
126
|
|
|
'application_dir' => 'src/Application/:vendor', |
127
|
|
|
'namespace' => 'Application\\:vendor', |
128
|
|
|
'namespace_prefix' => 'App\\', |
129
|
|
|
]); |
130
|
|
|
|
131
|
|
|
$this->assertSame('SonataAcmeBundle', $bundleMetadata->getName()); |
132
|
|
|
$this->assertSame('Sonata', $bundleMetadata->getVendor()); |
133
|
|
|
$this->assertSame('Application', $bundleMetadata->getApplication()); |
134
|
|
|
$this->assertSame('Sonata\AcmeBundle', $bundleMetadata->getNamespace()); |
135
|
|
|
$this->assertSame('src/Application/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory()); |
136
|
|
|
$this->assertSame('App\Application\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace()); |
137
|
|
|
$this->assertSame($bundle, $bundleMetadata->getBundle()); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|