public function setupPluginManager($config = array()) { $services = new ServiceManager(); $services->setService('Config', $config); $metadataMap = $this->getMock('ZF\Hal\Metadata\MetadataMap'); $metadataMap ->expects($this->once()) ->method('getHydratorManager') ->will($this->returnValue(new HydratorPluginManager())); $services->setService('ZF\Hal\MetadataMap', $metadataMap); $this->pluginManager = $this->getMock('Zend\ServiceManager\AbstractPluginManager'); $this->pluginManager ->expects($this->at(1)) ->method('get') ->with('ServerUrl') ->will($this->returnValue(new ServerUrl())); $this->pluginManager ->expects($this->at(2)) ->method('get') ->with('Url') ->will($this->returnValue(new Url())); $this->pluginManager ->expects($this->any()) ->method('getServiceLocator') ->will($this->returnValue($services)); }
public function setup() { parent::setup(); $config = (include 'config/application.config.php'); $config['module_listener_options']['config_static_paths'] = array(getcwd() . '/config/test.config.php'); if (file_exists(__DIR__ . '/config/test.config.php')) { $moduleConfig = (include __DIR__ . '/config/test.config.php'); array_unshift($config['module_listener_options']['config_static_paths'], $moduleConfig); } $this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array())); $this->serviceManager->setService('ApplicationConfig', $config); $this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory'); $moduleManager = $this->serviceManager->get('ModuleManager'); $moduleManager->loadModules(); $this->routes = array(); foreach ($moduleManager->getModules() as $m) { $moduleConfig = (include __DIR__ . '/../../../../' . ucfirst($m) . '/config/module.config.php'); if (isset($moduleConfig['router'])) { foreach ($moduleConfig['router']['routes'] as $key => $name) { $this->routes[$key] = $name; } } } $this->serviceManager->setAllowOverride(true); $this->application = $this->serviceManager->get('Application'); $this->event = new MvcEvent(); $this->event->setTarget($this->application); $this->event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router')); $this->createDatabase(); }
protected function prepare($config) { $services = $this->services = new ServiceManager(); $services->setAllowOverride(true); $services->setService('Config', $config); $connection = $this->getMock('AMQPConnection', array(), array(), '', false); $channel = $this->getMock('AMQPChannel', array(), array(), '', false); $channel->expects($this->any())->method('getPrefetchCount')->will($this->returnValue(10)); $queue = $this->getMock('AMQPQueue', array(), array(), '', false); $queue->expects($this->any())->method('getChannel')->will($this->returnValue($channel)); $queueFactory = $this->getMock('HumusAmqpModule\\QueueFactory'); $queueFactory->expects($this->any())->method('create')->will($this->returnValue($queue)); $connectionManager = $this->getMock('HumusAmqpModule\\PluginManager\\Connection'); $connectionManager->expects($this->any())->method('get')->with('default')->willReturn($connection); $dependentComponent = new ConnectionAbstractServiceFactory(); $this->services->setService('HumusAmqpModule\\PluginManager\\Connection', $cm = new ConnectionPluginManager()); $cm->addAbstractFactory($dependentComponent); $cm->setServiceLocator($this->services); $components = $this->components = new TestAsset\RpcClientAbstractServiceFactory(); $components->setChannelMock($channel); $components->setQueueFactory($queueFactory); $this->services->setService('HumusAmqpModule\\PluginManager\\RpcClient', $rpccm = new RpcClientPluginManager()); $rpccm->addAbstractFactory($components); $rpccm->setServiceLocator($this->services); }
public function testCanCreateViaServiceManager() { $sm = new ServiceManager(['factories' => ['ZfAnnotation\\AnnotationReader' => AnnotationReaderFactory::class, 'ClassParser' => ClassParserFactory::class]]); $sm->setService('EventManager', new EventManager()); $sm->setService('Config', $this->config); $this->assertInstanceOf(ClassParser::class, $sm->get('ClassParser')); }
/** * @test */ public function shouldReturnAListOfBreweries() { $entityManagerMock = $this->getMock('\\Doctrine\\ORM\\EntityManager', array('getRepository'), array(), '', false); $this->sm->setService('doctrine.entitymanager.orm_default', $entityManagerMock); $breweryRepoMock = $this->getMockBuilder('\\Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); // Mock the entity manager to return // a mock brewery repo $entityManagerMock->expects($this->once())->method('getRepository')->with('RestApi\\Model\\Brewery')->will($this->returnValue($breweryRepoMock)); $summitBrewery = new Brewery(); $summitBrewery->setName('Summit Brewery'); $summitBrewery->setCity('St. Paul, MN'); $summitBrewery->setWebsite('www.summitbrewery.com'); $summitEPA = new Beer(); $summitEPA->setName('Summit EPA'); $summitEPA->setStyle('EPA'); $summitEPA->setIbu(45); $summitBrewery->addBeer($summitEPA); $harrietBrewing = new Brewery(); $harrietBrewing->setName('Harriet Brewing'); $harrietBrewing->setCity('Minneapolis, MN'); $harrietBrewing->setWebsite('www.harrietbrewing.com'); // Mock the brewery repo to return our stub data $breweryRepoMock->expects($this->once())->method('findAll')->will($this->returnValue(array($summitBrewery, $harrietBrewing))); // Make GET request to /breweries/ $this->dispatch('/breweries/', 'GET'); $response = $this->getResponse()->getContent(); // Test response is successful $this->assertResponseStatusCode(200); // Test JSON response is serialized brewery data $this->assertJsonStringEqualsJsonString(json_encode(array(array('name' => 'Summit Brewery', 'city' => 'St. Paul, MN', 'website' => 'www.summitbrewery.com', 'beers' => array(array('name' => 'Summit EPA', 'style' => 'EPA', 'ibu' => 45))), array('name' => 'Harriet Brewing', 'city' => 'Minneapolis, MN', 'website' => 'www.harrietbrewing.com'))), $response); }
public function testOnDispatch() { // Create MvcEvent $e = new MvcEvent(); $e->setViewModel(new ViewModel()); $rm = new RouteMatch([]); $rm->setParam('controller', 'Application\\Controller\\Download'); $e->setRouteMatch($rm); $e->setTarget(new DownloadController([])); // Create EntityManager and EntityRepository $moduleDetail = new ModuleList(); $moduleDetail->setModuleDesc('Pretty description'); $repo = $this->prophesize('Doctrine\\ORM\\EntityRepository'); $repo->findOneBy(['moduleName' => 'Application'])->willReturn($moduleDetail); $em = $this->prophesize('Doctrine\\ORM\\EntityManager'); $em->getRepository('Application\\Entity\\ModuleList')->willReturn($repo); $this->sm->setService('Doctrine\\ORM\\EntityManager', $em->reveal()); // Create ViewHelperManager $headTitle = new HeadTitle(); $vhm = new HelperPluginManager(); $vhm->setService('headTitle', $headTitle); $this->sm->setService('ViewHelperManager', $vhm); $this->module->onDispatch($e); $fbMeta = $e->getViewModel()->getVariable('fbMeta'); $this->assertEquals(sprintf('%s-Real Live Learn ZF2', $moduleDetail->getModuleDesc()), $fbMeta['title']); $this->assertEquals(sprintf('%s-', $moduleDetail->getModuleDesc()), $fbMeta['description']); }
public function test_it_injects_an_output_writer() { $this->service_manager->setService('Config', ['migrations' => ['foo' => ['dir' => __DIR__, 'namespace' => 'Foo', 'adapter' => 'fooDb', 'show_log' => true]]]); $factory = new MigrationAbstractFactory(); $instance = $factory->createServiceWithName($this->service_manager, 'migrations.migration.foo', 'asdf'); $this->assertInstanceOf(OutputWriter::class, $instance->getOutputWriter(), "factory should inject a " . OutputWriter::class); }
public function testCreateService() { $this->sm->setService('Matryoshka\\Model\\ModelManager', $this->mm); $this->mm->setServiceLocator($this->sm); $model = $this->factory->createService($this->mm); $this->assertInstanceOf('Matryoshka\\Module\\Controller\\Plugin\\Model', $model); }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ public function setUp() { parent::setUp(); static::$sent = 0; $this->serviceManager = new ServiceManager(); $this->serviceManager->setService('Configuration', $this->dataConfig)->setService('SiteInfo', new SiteInfo($this->dataSiteInfo))->setAlias('Zork\\Db\\SiteInfo', 'SiteInfo')->setFactory('Zork\\Mail\\Service', 'Zork\\Mail\\ServiceFactory'); }
public function testCreateService() { $this->serviceLocator->setService('doctrine.orm_cmd.validate_schema', $this->command); $this->serviceLocator->setService('Request', $this->request); $actual = $this->sut->createService($this->serviceLocator); self::assertInstanceOf(CheckCommand::class, $actual); }
public function setUp() { $addressService = $this->getMockBuilder('Ajasta\\Address\\Service\\AddressService')->disableOriginalConstructor()->getMock(); $this->serviceLocator = new ServiceManager(); $this->serviceLocator->setService('Ajasta\\Address\\Service\\AddressService', $addressService); $this->serviceLocator->setService('Ajasta\\Locale', 'en-US'); }
/** * @expectedException \HumusAmqpModule\Exception\InvalidArgumentException * @expectedExceptionMessage The logger invalid stuff is not configured */ public function testCreateConsumerThrowsExceptionOnInvalidLogger() { $config = $this->services->get('Config'); $config['humus_amqp_module']['rpc_servers']['test-rpc-server']['logger'] = 'invalid stuff'; $this->services->setService('Config', $config); $this->components->createServiceWithName($this->services, 'test-rpc-server', 'test-rpc-server'); }
public function __construct() { $this->config = (include 'config/application.config.php'); $this->sm = new ServiceManager(new Service\ServiceManagerConfig($this->config)); $this->sm->setService('ApplicationConfig', $this->config); $this->sm->get('ModuleManager')->loadModules(); }
public function testWillNotInstantiateConfigWithInvalidNamingStrategyReference() { $config = array('doctrine' => array('configuration' => array('test_default' => array('naming_strategy' => 'test_naming_strategy')))); $this->serviceManager->setService('Config', $config); $this->setExpectedException('Zend\\ServiceManager\\Exception\\InvalidArgumentException'); $this->factory->createService($this->serviceManager); }
public function setup() { parent::setup(); $pathDir = getcwd() . "/"; $config = (include $pathDir . 'config/application.config.php'); $this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array())); $this->serviceManager->setService('ApplicationConfig', $config); $this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory'); $moduleManager = $this->serviceManager->get('ModuleManager'); $moduleManager->loadModules(); $this->routes = array(); $this->modules = $moduleManager->getModules(); foreach ($this->filterModules() as $m) { $moduleConfig = (include $pathDir . 'module/' . ucfirst($m) . '/config/module.config.php'); if (isset($moduleConfig['router'])) { foreach ($moduleConfig['router']['routes'] as $key => $name) { $this->routes[$key] = $name; } } } $this->serviceManager->setAllowOverride(true); $this->application = $this->serviceManager->get('Application'); $this->event = new MvcEvent(); $this->event->setTarget($this->application); $this->event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router')); $this->em = $this->serviceManager->get('Doctrine\\ORM\\EntityManager'); foreach ($this->filterModules() as $m) { $this->createDatabase($m); } }
/** * Prepares the environment before running a test. */ protected function setUp() { date_default_timezone_set('Asia/Shanghai'); vfsStream::setup('Test'); $this->serviceManager = new ServiceManager(new ServiceManagerConfig(array('abstract_factories' => array('Platform\\Log\\LoggerAbstractServiceFactory')))); $this->serviceManager->setService('Config', array('log' => array('test-log' => array('writers' => array(array('name' => 'stream', 'options' => array('stream' => vfsStream::url("Test/%pattern%.log")))))))); }
public function testCreateService() { $this->sm->setService('Matryoshka\\Model\\Object\\ObjectManager', $this->om); $this->pm->setServiceLocator($this->sm); $object = $this->factory->createService($this->pm); $this->assertInstanceOf('Matryoshka\\Module\\Controller\\Plugin\\Object', $object); }
protected function setUp() { // Inicializar Localizador de Serviço $serviceLocator = new ServiceManager(); // Inicialização $form = new Form(); $inputFilter = new InputFilter(); $formSearch = new Form(); $inputFilterSearch = new InputFilter(); $persistence = $this->getMock('Balance\\Model\\Persistence\\PersistenceInterface'); // Formulário $serviceLocator->setService('Balance\\Form\\Form', $form); // Filtro de Dados $serviceLocator->setService('Balance\\InputFilter\\InputFilter', $inputFilter); // Formulário de Pesquisa $serviceLocator->setService('Balance\\Form\\Search\\Form', $formSearch); // Filtro de Dados de Pesquisa $serviceLocator->setService('Balance\\InputFilter\\Search\\InputFilter', $inputFilterSearch); // Persistência $serviceLocator->setService('Balance\\Model\\Persistence\\Model', $persistence); // Gerenciadores $serviceLocator->setService('FormElementManager', $serviceLocator)->setService('InputFilterManager', $serviceLocator)->setService('EventManager', new EventManager()); // Configurar Elemento $serviceLocator->setService('Config', ['balance_manager' => ['factories' => ['Balance\\Model\\Model' => ['factory' => 'Balance\\Model\\AbstractModelFactory', 'params' => ['form' => 'Balance\\Form\\Form', 'input_filter' => 'Balance\\InputFilter\\InputFilter', 'form_search' => 'Balance\\Form\\Search\\Form', 'input_filter_search' => 'Balance\\InputFilter\\Search\\InputFilter', 'persistence' => 'Balance\\Model\\Persistence\\Model']]]]]); // Configurações $this->serviceLocator = $serviceLocator; $this->form = $form; $this->inputFilter = $inputFilter; $this->formSearch = $formSearch; $this->inputFilterSearch = $inputFilterSearch; $this->persistence = $persistence; }
public function setUp() { $addressHydrator = $this->getMockBuilder('Ajasta\\Address\\Hydrator\\AddressHydrator')->disableOriginalConstructor()->getMock(); $hydratorManager = new ServiceManager(); $hydratorManager->setService('Ajasta\\Address\\Hydrator\\AddressHydrator', $addressHydrator); $this->serviceLocator = new ServiceManager(); $this->serviceLocator->setService('HydratorManager', $hydratorManager); }
public function testFactory() { $serviceManager = new ServiceManager(); $serviceManager->setService('HtImg\\ModuleOptions', new ModuleOptions()); $serviceManager->setService('HtImgModule\\Imagine\\Filter\\Loader\\FilterLoaderPluginManager', new FilterLoaderPluginManager()); $factory = new FilterManagerFactory(); $this->assertInstanceOf('HtImgModule\\Imagine\\Filter\\FilterManager', $factory->createService($serviceManager)); }
public function testFactory() { $serviceManager = new ServiceManager(); $factory = new SettingsManagerFactory(); $serviceManager->setService('HtSettingsModule\\Service\\SettingsProvider', $this->getMock('HtSettingsModule\\Service\\SettingsProviderInterface')); $serviceManager->setService('HtSettingsModule\\Service\\SettingsService', $this->getMock('HtSettingsModule\\Service\\SettingsServiceInterface')); $this->assertInstanceOf('HtSettingsModule\\Manager\\SettingsManager', $factory->createService($serviceManager)); }
public function testFactory() { $serviceManager = new ServiceManager(); $serviceManager->setService('zfcuser_module_options', new ModuleOptions()); $serviceManager->setService('zfcuser_user_mapper', new UserMapper()); $factory = new RegisterFormFactory(); $this->assertInstanceOf('ZfcUser\\Form\\Register', $factory->createService($serviceManager)); }
public function testControllerCreated() { $oauthServer = $this->getMockBuilder('OAuth2\\Server')->disableOriginalConstructor()->getMock(); $this->services->setService('ZF\\OAuth2\\Service\\OAuth2Server', $oauthServer); $controller = $this->factory->createService($this->controllers); $this->assertInstanceOf('ZF\\OAuth2\\Controller\\AuthController', $controller); $this->assertEquals(new \ZF\OAuth2\Controller\AuthController($oauthServer), $controller); }
public function testFactory() { $serviceManager = new ServiceManager(); $serviceManager->setService('HtUserRegistration\\UserRegistrationMapper', new UserRegistrationMapper()); $serviceManager->setService('zfcuser_user_mapper', new User()); $factory = new EmailVerificationFactory(); $this->assertInstanceOf('HtUserRegistration\\Authentication\\Adapter\\EmailVerification', $factory->createService($serviceManager)); }
public function testFactory() { $serviceManager = new ServiceManager(); $factory = new JsonSettingsMapperFactory(); $serviceManager->setService('HtSettingsModule\\Options\\ModuleOptions', new ModuleOptions()); $serviceManager->setService('HtSettingsModule\\FileSystemStorage', $this->getMock('League\\Flysystem\\FilesystemInterface')); $this->assertInstanceOf('HtSettingsModule\\Mapper\\FileSystem\\FileSystemMapper', $factory->createService($serviceManager)); }
public function testInvoke() { $sm = new ServiceManager(); $sm->setService(RouterInterface::class, $this->prophesize(RouterInterface::class)->reveal()); $sm->setService(ServerRequestInterface::class, $this->prophesize(ServerRequestInterface::class)->reveal()); $instance = $this->factory->__invoke($sm); $this->assertInstanceOf(RouteAssembler::class, $instance); }
public function testFactory() { $serviceManager = new ServiceManager(); $factory = new NamespaceHydratorProviderFactory(); $serviceManager->setService('HtSettingsModule\\Options\\ModuleOptions', $this->getMock('HtSettingsModule\\Options\\ModuleOptionsInterface')); $serviceManager->setService('HydratorManager', $this->getMock('Zend\\ServiceManager\\ServiceLocatorInterface')); $this->assertInstanceOf('HtSettingsModule\\Service\\NamespaceHydratorProvider', $factory->createService($serviceManager)); }
public function testCreateServiceWithName() { $sm = new ServiceManager(); $sm->setService(Cache::class, new ArrayCache()); $sm->setService('renderer', $this->prophesize(TemplateInterface::class)->reveal()); $service = $this->factory->createServiceWithName($sm, '', Template::class); $this->assertInstanceOf(Template::class, $service); }
/** * @test */ public function createService() { $toggleManager = $this->getMockBuilder('Qandidate\\Toggle\\ToggleManager')->disableOriginalConstructor(); $this->services->setService('ToggleManagerFactory', $toggleManager->getMock()); $context = $this->getMockBuilder('Qandidate\\Toggle\\Context'); $this->services->setService('ToggleFeature\\UserContextFactory', $context->getMock()); $this->assertInstanceOf('Qandidate\\Toggle\\Context', $this->factory->createService($this->services)); }
/** * @return \Zend\ServiceManager\ServiceManager */ public function getServiceLocator() { if (!self::$serviceManager) { self::$serviceManager = new ServiceManager(new ServiceManagerConfig()); self::$serviceManager->setService('ApplicationConfig', []); } return self::$serviceManager; }