|
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\AdminBundle\Tests\DependencyInjection\Compiler; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Sonata\AdminBundle\DependencyInjection\Compiler\ModelManagerCompilerPass; |
|
18
|
|
|
use Sonata\AdminBundle\Maker\AdminMaker; |
|
19
|
|
|
use Sonata\AdminBundle\Tests\App\Model\ModelManager; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Gaurav Singh Faujdar <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
final class ModelManagerCompilerPassTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
public function testProcess(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$adminMaker = new Definition(AdminMaker::class); |
|
31
|
|
|
$adminMaker->setArguments([ |
|
32
|
|
|
'', |
|
33
|
|
|
[], |
|
34
|
|
|
]); |
|
35
|
|
|
|
|
36
|
|
|
$containerBuilder = new ContainerBuilder(); |
|
37
|
|
|
$containerBuilder->setDefinition('sonata.admin.maker', $adminMaker); |
|
38
|
|
|
$containerBuilder->setParameter('kernel.bundles', ['MakerBundle' => 'MakerBundle']); |
|
39
|
|
|
|
|
40
|
|
|
$compilerPass = new ModelManagerCompilerPass(); |
|
41
|
|
|
$compilerPass->process($containerBuilder); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertCount(0, $adminMaker->getArgument(1)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testProcessWithTaggedManagerDefinition(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$adminMaker = new Definition(AdminMaker::class); |
|
49
|
|
|
$adminMaker->setArguments([ |
|
50
|
|
|
'', |
|
51
|
|
|
[], |
|
52
|
|
|
]); |
|
53
|
|
|
$containerBuilder = new ContainerBuilder(); |
|
54
|
|
|
$containerBuilder->setParameter('kernel.bundles', ['MakerBundle' => 'MakerBundle']); |
|
55
|
|
|
$containerBuilder->setDefinition('sonata.admin.maker', $adminMaker); |
|
56
|
|
|
|
|
57
|
|
|
$managerDefinition = new Definition(ModelManager::class); |
|
58
|
|
|
$managerDefinition->addTag(ModelManagerCompilerPass::MANAGER_TAG); |
|
59
|
|
|
|
|
60
|
|
|
$containerBuilder->setDefinition('sonata.admin.manager.test', $managerDefinition); |
|
61
|
|
|
|
|
62
|
|
|
$compilerPass = new ModelManagerCompilerPass(); |
|
63
|
|
|
$compilerPass->process($containerBuilder); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertCount(1, $adminMaker->getArgument(1)); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|