/** * @dataProvider getServiceOfVariousTypes * * @param $service */ public function testAbstractFactoriesCanReturnAnyTypeButNull($service) { $abstractFactory = $this->getMock('Zend\\ServiceManager\\AbstractFactoryInterface'); $abstractFactory->expects($this->any())->method('canCreateServiceWithName')->with($this->serviceManager, 'something', 'something')->will($this->returnValue(true)); $abstractFactory->expects($this->any())->method('createServiceWithName')->with($this->serviceManager, 'something', 'something')->will($this->returnValue($service)); $this->serviceManager->addAbstractFactory($abstractFactory); if ($service === null) { try { $this->serviceManager->get('something'); $this->fail('ServiceManager::get() successfully returned null'); } catch (\Exception $e) { $this->assertInstanceOf('Zend\\ServiceManager\\Exception\\ServiceNotCreatedException', $e); } } else { $this->assertSame($service, $this->serviceManager->get('something')); } }