1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
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
|
|
|
namespace Symfony\Component\DependencyInjection\Tests\Compiler; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Sonata\MediaBundle\DependencyInjection\Compiler\AddProviderCompilerPass; |
16
|
|
|
use Sonata\MediaBundle\DependencyInjection\SonataMediaExtension; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
|
19
|
|
|
class AddProviderCompilerPassTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
public function testProcess() |
22
|
|
|
{ |
23
|
|
|
// Create ContainerBuilder and set up basic sonata_media config with formats |
24
|
|
|
$container = new ContainerBuilder(); |
25
|
|
|
$extension = new SonataMediaExtension(); |
26
|
|
|
$container->registerExtension($extension); |
27
|
|
|
$container->loadFromExtension( |
28
|
|
|
$extension->getAlias(), |
29
|
|
|
[ |
30
|
|
|
'db_driver' => 'doctrine_orm', |
31
|
|
|
'default_context' => 'default', |
32
|
|
|
'providers' => [ |
33
|
|
|
'image' => [ |
34
|
|
|
'filesystem' => 'foo_filesystem', |
35
|
|
|
], |
36
|
|
|
], |
37
|
|
|
'contexts' => [ |
38
|
|
|
'default' => [ |
39
|
|
|
'providers' => [ |
40
|
|
|
'foo_provider', |
41
|
|
|
], |
42
|
|
|
'formats' => '%foo_formats%', |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
// Define 'foo_formats' parameter, parameter reference in 'sonata_media' config should resolve to this value. |
49
|
|
|
$container->setParameter('foo_formats', [ |
50
|
|
|
'foo_format' => [ |
51
|
|
|
'width' => 350, |
52
|
|
|
'height' => 200, |
53
|
|
|
'quality' => 70, |
54
|
|
|
], |
55
|
|
|
]); |
56
|
|
|
|
57
|
|
|
// Register parameters and services needed by compiler pass |
58
|
|
|
$container->setParameter('sonata.media.admin_format', [ |
59
|
|
|
'width' => 200, |
60
|
|
|
'height' => false, |
61
|
|
|
'quality' => 90, |
62
|
|
|
]); |
63
|
|
|
$container |
64
|
|
|
->register('foo_filesystem') |
65
|
|
|
->setPublic(false); |
66
|
|
|
$container |
67
|
|
|
->register('foo_provider') |
68
|
|
|
->setPublic(false); |
69
|
|
|
$container |
70
|
|
|
->register('sonata.media.pool') |
71
|
|
|
->setPublic(false); |
72
|
|
|
|
73
|
|
|
(new AddProviderCompilerPass())->process($container); |
74
|
|
|
|
75
|
|
|
// 'foo_provider' should have 1 'addFormat' method call with correctly resolved config values. |
76
|
|
|
$calls = $container->getDefinition('foo_provider')->getMethodCalls(); |
77
|
|
|
$callFound = false; |
78
|
|
|
$expectedCall = [ |
79
|
|
|
'default_foo_format', |
80
|
|
|
[ |
81
|
|
|
'width' => 350, |
82
|
|
|
'height' => 200, |
83
|
|
|
'quality' => 70, |
84
|
|
|
'format' => 'jpg', |
85
|
|
|
'constraint' => true, |
86
|
|
|
], |
87
|
|
|
]; |
88
|
|
|
foreach ($calls as $call) { |
89
|
|
|
if ('addFormat' === $call[0]) { |
90
|
|
|
$callFound = true; |
91
|
|
|
$this->assertSame( |
92
|
|
|
$expectedCall, |
93
|
|
|
$call[1], |
94
|
|
|
'Format config of "foo_provider" doesn\'t match the expected config.' |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
$this->assertTrue( |
99
|
|
|
$callFound, |
100
|
|
|
'Expected "addFormat" method call on "foo_provider" service was not registered.' |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|