|
19 | 19 | use Zend\ServiceManager\Factory\InvokableFactory; |
20 | 20 | use Zend\ServiceManager\ServiceManager; |
21 | 21 | use ZendTest\ServiceManager\TestAsset\Baz; |
| 22 | +use ZendTest\ServiceManager\TestAsset\FactoryUsingCreationOptions; |
22 | 23 | use ZendTest\ServiceManager\TestAsset\FooPluginManager; |
23 | 24 | use ZendTest\ServiceManager\TestAsset\InvokableObject; |
24 | 25 | use ZendTest\ServiceManager\TestAsset\MockSelfReturningDelegatorFactory; |
@@ -110,8 +111,9 @@ public function testMutableMethodNeverCalledWithoutCreationOptions() |
110 | 111 | { |
111 | 112 | $mock = 'ZendTest\ServiceManager\TestAsset\CallableWithMutableCreationOptions'; |
112 | 113 | $callable = $this->getMock($mock, ['setCreationOptions']); |
113 | | - $callable->expects($this->never()) |
114 | | - ->method('setCreationOptions'); |
| 114 | + $callable->expects($this->once()) |
| 115 | + ->method('setCreationOptions') |
| 116 | + ->with([]); |
115 | 117 |
|
116 | 118 | $ref = new ReflectionObject($this->pluginManager); |
117 | 119 |
|
@@ -164,7 +166,70 @@ public function testInvokableFactoryNoOptionsResetsCreationOptions() |
164 | 166 | $plugin2 = $pluginManager->get(Baz::class); |
165 | 167 |
|
166 | 168 | $this->assertSame($creationOptions, $plugin1->options); |
167 | | - $this->assertNull($plugin2->options); |
| 169 | + $this->assertEmpty($plugin2->options); |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * @group 205 |
| 174 | + */ |
| 175 | + public function testRetrievingServicesViaFactoryThatUsesCreationOptionsShouldNotRememberServiceOnSubsequentRetrievals() |
| 176 | + { |
| 177 | + /** @var $pluginManager AbstractPluginManager */ |
| 178 | + $pluginManager = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager'); |
| 179 | + $pluginManager->setFactory(Baz::class, FactoryUsingCreationOptions::class); |
| 180 | + $pluginManager->setShared(Baz::class, false); |
| 181 | + $creationOptions = ['key1' => 'value1']; |
| 182 | + $plugin1 = $pluginManager->get(Baz::class, $creationOptions); |
| 183 | + $plugin2 = $pluginManager->get(Baz::class); |
| 184 | + |
| 185 | + $this->assertNotSame($plugin1, $plugin2); |
| 186 | + |
| 187 | + $this->assertSame($creationOptions, $plugin1->options); |
| 188 | + $this->assertEmpty($plugin2->options); |
| 189 | + } |
| 190 | + |
| 191 | + /** |
| 192 | + * @group 205 |
| 193 | + */ |
| 194 | + public function testRetrievingServicesViaFactoryThatUsesCreationOptionsShouldReturnNewInstanceIfOptionsAreProvided() |
| 195 | + { |
| 196 | + /** @var $pluginManager AbstractPluginManager */ |
| 197 | + $pluginManager = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager'); |
| 198 | + $pluginManager->setFactory(Baz::class, FactoryUsingCreationOptions::class); |
| 199 | + $pluginManager->setShared(Baz::class, false); |
| 200 | + $creationOptions = ['key1' => 'value1']; |
| 201 | + $plugin1 = $pluginManager->get(Baz::class); |
| 202 | + $plugin2 = $pluginManager->get(Baz::class, $creationOptions); |
| 203 | + |
| 204 | + $this->assertNotSame($plugin1, $plugin2); |
| 205 | + |
| 206 | + $this->assertEmpty($plugin1->options); |
| 207 | + $this->assertSame($creationOptions, $plugin2->options); |
| 208 | + } |
| 209 | + |
| 210 | + /** |
| 211 | + * @group 205 |
| 212 | + */ |
| 213 | + // @codingStandardsIgnoreStart |
| 214 | + public function testRetrievingServicesViaFactoryThatUsesCreationOptionsShouldReturnNewInstanceEveryTimeOptionsAreProvided() |
| 215 | + { |
| 216 | + // @codingStandardsIgnoreEnd |
| 217 | + /** @var $pluginManager AbstractPluginManager */ |
| 218 | + $pluginManager = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager'); |
| 219 | + $pluginManager->setFactory(Baz::class, FactoryUsingCreationOptions::class); |
| 220 | + $pluginManager->setShared(Baz::class, false); |
| 221 | + $creationOptions = ['key1' => 'value1']; |
| 222 | + $plugin1 = $pluginManager->get(Baz::class, $creationOptions); |
| 223 | + $plugin2 = $pluginManager->get(Baz::class); |
| 224 | + $plugin3 = $pluginManager->get(Baz::class, $creationOptions); |
| 225 | + |
| 226 | + $this->assertNotSame($plugin1, $plugin2); |
| 227 | + $this->assertNotSame($plugin1, $plugin3); |
| 228 | + $this->assertNotSame($plugin2, $plugin3); |
| 229 | + |
| 230 | + $this->assertSame($creationOptions, $plugin1->options); |
| 231 | + $this->assertEmpty($plugin2->options); |
| 232 | + $this->assertSame($creationOptions, $plugin3->options); |
168 | 233 | } |
169 | 234 |
|
170 | 235 | public function testValidatePluginIsCalledWithDelegatorFactoryIfItsAService() |
|
0 commit comments