|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\ResourceBundle\Tests\DependencyInjection\Compiler; |
|
15
|
|
|
|
|
16
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
|
17
|
|
|
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterResourcesPass; |
|
18
|
|
|
use Sylius\Component\Resource\Model\ResourceInterface; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
21
|
|
|
|
|
22
|
|
|
class RegisterResourcesPassTest extends AbstractCompilerPassTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @test |
|
26
|
|
|
*/ |
|
27
|
|
|
public function it_adds_method_call_to_resource_registry_if_resources_exist() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->setDefinition('sylius.resource_registry', new Definition()); |
|
30
|
|
|
|
|
31
|
|
|
$this->setParameter( |
|
32
|
|
|
'sylius.resources', |
|
33
|
|
|
[ |
|
34
|
|
|
'app.book' => ['classes' => ['model' => BookClass::class]], |
|
35
|
|
|
'app.author' => ['classes' => ['model' => AuthorClass::class]], |
|
36
|
|
|
] |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$this->compile(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
42
|
|
|
'sylius.resource_registry', |
|
43
|
|
|
'addFromAliasAndConfiguration', |
|
44
|
|
|
['app.book', ['classes' => ['model' => BookClass::class]]] |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
48
|
|
|
'sylius.resource_registry', |
|
49
|
|
|
'addFromAliasAndConfiguration', |
|
50
|
|
|
['app.author', ['classes' => ['model' => AuthorClass::class]]] |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
|
58
|
|
|
{ |
|
59
|
|
|
$container->addCompilerPass(new RegisterResourcesPass()); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
class AbstractResource implements ResourceInterface |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
public function getId() |
|
66
|
|
|
{ |
|
67
|
|
|
return; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
class BookClass extends AbstractResource |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
} |
|
73
|
|
|
class AuthorClass extends AbstractResource |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
} |
|
76
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.