1 | <?php |
||
18 | class SonataMediaExtensionTest extends \PHPUnit_Framework_TestCase |
||
19 | { |
||
20 | /** |
||
21 | * @var SonataMediaExtension |
||
22 | */ |
||
23 | private $extension; |
||
24 | |||
25 | /** |
||
26 | * Root name of the configuration. |
||
27 | * |
||
28 | * @var ContainerBuilder |
||
29 | */ |
||
30 | private $container; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function setUp() |
||
45 | |||
46 | public function testLoadWithDefaultAndCustomCategoryManager() |
||
47 | { |
||
48 | $container = $this->getContainer( |
||
49 | array(array( |
||
50 | 'class' => array('category' => '\stdClass'), |
||
51 | 'category_manager' => 'dummy.service.name', |
||
52 | ))); |
||
53 | |||
54 | $this->assertTrue($container->hasAlias('sonata.media.manager.category')); |
||
55 | $this->assertSame($container->getAlias('sonata.media.manager.category')->__toString(), 'dummy.service.name'); |
||
56 | } |
||
57 | |||
58 | public function testLoadWithForceDisableTrueAndWithCategoryManager() |
||
59 | { |
||
60 | $container = $this->getContainer( |
||
61 | array(array( |
||
62 | 'class' => array('category' => '\stdClass'), |
||
63 | 'category_manager' => 'dummy.service.name', |
||
64 | 'force_disable_category' => true, |
||
65 | ))); |
||
66 | |||
67 | $this->assertFalse($container->hasDefinition('sonata.media.manager.category')); |
||
68 | } |
||
69 | |||
70 | public function testLoadWithDefaultAndClassificationBundleEnable() |
||
71 | { |
||
72 | $container = $this->getContainer(); |
||
73 | $this->assertTrue($container->hasAlias('sonata.media.manager.category')); |
||
74 | $this->assertSame($container->getDefinition('sonata.media.manager.category.default')->getClass(), 'Sonata\MediaBundle\Model\CategoryManager'); |
||
75 | } |
||
76 | |||
77 | public function testLoadWithDefaultAndClassificationBundleEnableAndForceDisableCategory() |
||
78 | { |
||
79 | $container = $this->getContainer(array(array('force_disable_category' => true))); |
||
80 | |||
81 | $this->assertFalse($container->hasDefinition('sonata.media.manager.category')); |
||
82 | } |
||
83 | |||
84 | public function testLoadWithDefaultAndClassificationBundleEnableAndCustomCategoryManager() |
||
85 | { |
||
86 | $container = $this->getContainer( |
||
87 | array(array( |
||
88 | 'class' => array('category' => '\stdClass'), |
||
89 | 'category_manager' => 'dummy.service.name', |
||
90 | ))); |
||
91 | |||
92 | $this->assertTrue($container->hasAlias('sonata.media.manager.category')); |
||
93 | $this->assertSame($container->getAlias('sonata.media.manager.category')->__toString(), 'dummy.service.name'); |
||
94 | } |
||
95 | |||
96 | public function testDefaultAdapter() |
||
97 | { |
||
98 | $this->assertTrue($this->container->hasAlias('sonata.media.adapter.image.default')); |
||
99 | $this->assertEquals('sonata.media.adapter.image.gd', $this->container->getAlias('sonata.media.adapter.image.default')); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param string $serviceId |
||
104 | * @param string $extension |
||
105 | * @param string $type |
||
106 | * |
||
107 | * @dataProvider dataAdapter |
||
108 | */ |
||
109 | public function testAdapter($serviceId, $extension, $type) |
||
110 | { |
||
111 | $this->assertTrue($this->container->has($serviceId)); |
||
112 | |||
113 | if (extension_loaded($extension)) { |
||
114 | $this->isInstanceOf($type, $this->container->get($serviceId)); |
||
|
|||
115 | } |
||
116 | } |
||
117 | |||
118 | public function dataAdapter() |
||
119 | { |
||
120 | return array( |
||
121 | array('sonata.media.adapter.image.gd', 'gd', 'Imagine\\Gd\\Imagine'), |
||
122 | array('sonata.media.adapter.image.gmagick', 'gmagick', 'Imagine\\Gmagick\\Imagine'), |
||
123 | array('sonata.media.adapter.image.imagick', 'imagick', 'Imagine\\Imagick\\Imagine'), |
||
124 | ); |
||
125 | } |
||
126 | |||
127 | public function testDefaultResizer() |
||
128 | { |
||
129 | $this->assertTrue($this->container->hasAlias('sonata.media.resizer.default')); |
||
130 | $this->assertEquals('sonata.media.resizer.simple', $this->container->getAlias('sonata.media.resizer.default')); |
||
131 | if (extension_loaded('gd')) { |
||
132 | $this->isInstanceOf('Sonata\\MediaBundle\\Resizer\\SimpleResizer', $this->container->get('sonata.media.resizer.default')); |
||
133 | } |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @param $serviceId |
||
138 | * @param $type |
||
139 | * |
||
140 | * @dataProvider dataResizer |
||
141 | */ |
||
142 | public function testResizer($serviceId, $type) |
||
143 | { |
||
144 | $this->assertTrue($this->container->has($serviceId)); |
||
145 | if (extension_loaded('gd')) { |
||
146 | $this->isInstanceOf($type, $this->container->get($serviceId)); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | public function dataResizer() |
||
151 | { |
||
152 | return array( |
||
153 | array('sonata.media.resizer.simple', 'Sonata\\MediaBundle\\Resizer\\SimpleResizer'), |
||
154 | array('sonata.media.resizer.square', 'Sonata\\MediaBundle\\Resizer\\SquareResizer'), |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @return SonataMediaExtension |
||
160 | */ |
||
161 | protected function getExtension() |
||
165 | |||
166 | /** |
||
167 | * @return array |
||
168 | */ |
||
169 | protected function getConfigs() |
||
203 | |||
204 | private function getContainer(array $config = array()) |
||
232 | } |
||
233 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.