*/ class BaseProvidersServiceFactoryTest extends PHPUnit_Framework_TestCase { /** * @covers \BjyAuthorize\Service\BaseProvidersServiceFactory::createService */ public function testCreateService() { $factory = $this->getMockForAbstractClass('BjyAuthorize\\Service\\BaseProvidersServiceFactory'); $serviceLocator = $this->getMock('Zend\\ServiceManager\\ServiceLocatorInterface'); $foo = $this->getMock('BjyAuthorize\\Provider\\Resource\\ProviderInterface'); $bar = $this->getMock('BjyAuthorize\\Provider\\Resource\\ProviderInterface'); $config = array( 'providers' => array( 'foo' => array(), 'bar' => array(), __NAMESPACE__ . '\\MockProvider' => array('option' => 'value'), ), ); $serviceLocator ->expects($this->any()) ->method('has') ->will($this->returnCallback(function ($serviceName) { return in_array($serviceName, array('foo', 'bar'), true); })); $serviceLocator ->expects($this->any()) ->method('get') ->will($this->returnCallback(function ($serviceName) use ($foo, $bar, $config) { if ('BjyAuthorize\\Config' === $serviceName) { return $config; } if ('foo' === $serviceName) { return $foo; } return $bar; })); $providers = $factory->createService($serviceLocator); $this->assertCount(3, $providers); $this->assertContains($foo, $providers); $this->assertContains($bar, $providers); $invokableProvider = array_filter( $providers, function ($item) { return $item instanceof MockProvider; } ); $this->assertCount(1, $invokableProvider); /* @var $invokableGuard \BjyAuthorizeTest\Service\MockProvider */ $invokableProvider = array_shift($invokableProvider); $this->assertInstanceOf(__NAMESPACE__ . '\\MockProvider', $invokableProvider); $this->assertSame(array('option' => 'value'), $invokableProvider->options); $this->assertSame($serviceLocator, $invokableProvider->serviceLocator); } }