public function testProcessUndefinedServers() { $this->containerMock->expects($this->at(0))->method('hasParameter')->with('cache.redis.servers')->will($this->returnValue(false)); $this->containerMock->expects($this->never())->method('getParameterBag'); $compiler = new RedisCompiler(); $compiler->process($this->containerMock); }
public function testProcessWithoutParameter() { $this->container->expects($this->once())->method('hasDefinition')->willReturn(true); $this->container->expects($this->never())->method('getDefinition'); $this->container->expects($this->once())->method('hasParameter')->willReturn(false); $this->container->expects($this->never())->method('getParameter'); $this->compiler->process($this->container); }
public function testServiceExistsWithTaggedServices() { $this->container->expects($this->once())->method('hasDefinition')->with($this->equalTo(EntityFieldHandlerPass::HANDLER_PROCESSOR_SERVICE))->will($this->returnValue(true)); $this->container->expects($this->once())->method('findTaggedServiceIds')->with($this->equalTo(EntityFieldHandlerPass::TAG))->will($this->returnValue(['service' => ['class' => '\\stdClass']])); $definition = $this->getMock('Symfony\\Component\\DependencyInjection\\Definition'); $this->container->expects($this->once())->method('getDefinition')->with($this->equalTo(EntityFieldHandlerPass::HANDLER_PROCESSOR_SERVICE))->will($this->returnValue($definition)); $definition->expects($this->once())->method('addMethodCall')->with($this->isType('string'), $this->isType('array')); $this->compilerPass->process($this->container); }
/** * @dataProvider processDataProvider * @param bool $hasParameter * @param array $expectedParameter * @param array $parameterValue */ public function testProcess($hasParameter, array $expectedParameter, $parameterValue) { $this->container->expects($this->once())->method('hasParameter')->willReturn($hasParameter); if ($hasParameter) { $this->container->expects($this->once())->method('getParameter')->willReturn($parameterValue); } $this->container->expects($this->once())->method('setParameter')->with($this->isType('string'), $this->equalTo($expectedParameter)); $this->compiler->process($this->container); }
public function testProcessNoTagged() { $definition = $this->getMock('Symfony\\Component\\DependencyInjection\\Definition'); $definition->expects($this->never())->method('addMethodCall'); $this->containerBuilder->expects($this->once())->method('has')->with(OwnershipTreeProvidersPass::CHAIN_SERVICE_ID)->willReturn(true); $this->containerBuilder->expects($this->once())->method('getDefinition')->with(OwnershipTreeProvidersPass::CHAIN_SERVICE_ID)->willReturn($definition); $this->containerBuilder->expects($this->once())->method('findTaggedServiceIds')->with(OwnershipTreeProvidersPass::TAG_NAME)->willReturn([]); $this->compilerPass->process($this->containerBuilder); }
public function testServiceExistsWithTaggedServices() { $this->container->expects($this->once())->method('hasDefinition')->with($this->equalTo(InlineEditColumnOptionsGuesserPass::INLINE_EDIT_COLUMN_OPTIONS_GUESSER_SERVICE))->will($this->returnValue(true)); $this->container->expects($this->once())->method('findTaggedServiceIds')->with($this->equalTo(InlineEditColumnOptionsGuesserPass::TAG))->will($this->returnValue(['service' => ['class' => '\\stdClass']])); $definition = $this->getMock('Symfony\\Component\\DependencyInjection\\Definition'); $this->container->expects($this->once())->method('getDefinition')->with($this->equalTo(InlineEditColumnOptionsGuesserPass::INLINE_EDIT_COLUMN_OPTIONS_GUESSER_SERVICE))->will($this->returnValue($definition)); $definition->expects($this->once())->method('addMethodCall')->with($this->isType('string'), $this->isType('array')); $this->compilerPass->process($this->container); }
/** * @param bool $hasConnectionParameter * @param bool $hasExcludedParameter * @param mixed $connectionParameter * @param mixed $excludedParameter * @param array $tags * * @dataProvider dataProvider */ public function testProcess($hasConnectionParameter, $hasExcludedParameter, $connectionParameter, $excludedParameter, array $tags = []) { $this->container->expects($this->any())->method('hasParameter')->willReturnOnConsecutiveCalls($hasConnectionParameter, $hasExcludedParameter); $this->container->expects($this->any())->method('getParameter')->willReturnOnConsecutiveCalls($connectionParameter, $excludedParameter); $this->container->expects($this->any())->method('findTaggedServiceIds')->willReturn(['id' => ['event' => ['tag1' => []]]]); $definition = new Definition(); $this->container->expects($this->any())->method('getDefinition')->willReturn($definition); $this->compiler->process($this->container); $this->assertEquals($tags, $definition->getTags()); }
public function testProcessWithLazyRegistry() { $this->container->expects($this->once())->method('findTaggedServiceIds')->with($this->identicalTo($tag = 'lug.registry'))->will($this->returnValue([$service = 'my.registry' => []])); $this->container->expects($this->once())->method('getDefinition')->with($this->identicalTo($service))->will($this->returnValue($definition = $this->createDefinitionMock())); $definition->expects($this->once())->method('getClass')->will($this->returnValue(LazyServiceRegistry::class)); $definition->expects($this->never())->method('clearTag'); $definition->expects($this->never())->method('removeMethodCall')->with('offsetSet'); $this->container->expects($this->never())->method('setDefinition'); $this->compiler->process($this->container); }
/** * @expectedException * @expectedExceptionMessage */ public function testProcessWithoutAlias() { $definition = $this->getMock('Symfony\\Component\\DependencyInjection\\Definition'); $definition->expects($this->never())->method('addMethodCall'); $this->container->expects($this->once())->method('has')->with($this->chainServiceId)->willReturn(true); $this->container->expects($this->once())->method('getDefinition')->with($this->chainServiceId)->willReturn($definition); $this->container->expects($this->once())->method('findTaggedServiceIds')->with($this->tagName)->willReturn(['provider1' => [['class' => 'Test\\Class1']]]); $this->setExpectedException('\\InvalidArgumentException', 'Tag ' . $this->tagName . ' alias is missing for provider1 service'); $this->compilerPass->process($this->container); }
public function testProcess() { $registryDefinition = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Definition')->getMock(); $registryDefinition->expects($this->at(0))->method('addMethodCall')->with($this->equalTo('addType'), $this->equalTo([new Reference('service1')])); $registryDefinition->expects($this->at(1))->method('addMethodCall')->with($this->equalTo('addType'), $this->equalTo([new Reference('service2')])); $service1Definition = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Definition')->getMock(); $service1Definition->expects($this->once())->method('setPublic')->with(false); $service2Definition = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Definition')->getMock(); $service2Definition->expects($this->once())->method('setPublic')->with(false); $serviceIds = ['service1' => [], 'service2' => []]; $this->container->expects($this->once())->method('hasDefinition')->with($this->equalTo('orob2b_attribute.attribute_type.registry'))->will($this->returnValue(true)); $this->container->expects($this->exactly(3))->method('getDefinition')->will($this->returnValueMap([['orob2b_attribute.attribute_type.registry', $registryDefinition], ['service1', $service1Definition], ['service2', $service2Definition]])); $this->container->expects($this->once())->method('findTaggedServiceIds')->with($this->equalTo('orob2b_attribute.attribute_type'))->will($this->returnValue($serviceIds)); $compilerPass = new AttributeProviderPass(); $compilerPass->process($this->container); }
public function testProcess() { $that = $this; foreach (array_keys($this->chains) as $i => $chain_name) { $services = [$i + 1 => [], $i + 2 => []]; $definition = $this->getMock('\\Symfony\\Component\\DependencyInjection\\Definition'); $this->container->expects($this->at($i * 3))->method('has')->with($chain_name)->will($this->returnValue(true)); $this->container->expects($this->at($i * 3 + 1))->method('findDefinition')->with($chain_name)->will($this->returnValue($definition)); $this->container->expects($this->at($i * 3 + 2))->method('findTaggedServiceIds')->will($this->returnValue($services))->with($this->chains[$chain_name]); foreach (array_keys($services) as $j => $id) { $definition->expects($this->at($j))->method('addMethodCall')->will($this->returnCallback(function ($method, $reference) use($that, $id) { $that->assertInternalType('array', $reference); $that->assertInstanceOf('\\Symfony\\Component\\DependencyInjection\\Reference', $reference[0]); $that->assertEquals($id, (string) $reference[0]); }))->with('addPlugin'); } } $this->compiler->process($this->container); }
/** * Sets up a mock expectation for the container get() method. * * @param string $service_name * The service name to expect for the get() method. * @param mixed $return * The value to return from the mocked container get() method. */ protected function setMockContainerService($service_name, $return = NULL) { $expects = $this->container->expects($this->once())->method('get')->with($service_name); if (isset($return)) { $expects->will($this->returnValue($return)); } else { $expects->will($this->returnValue(TRUE)); } \Drupal::setContainer($this->container); }
/** * Configure container mock. * * @param array $managers Tagged filter managers. * @param array $filters Tagged filters. */ protected function setContainerConfig($managers, $filters) { $this->container->expects($this->any())->method('findTaggedServiceIds')->with($this->anything())->will($this->returnCallback(function ($parameter) use($managers, $filters) { switch ($parameter) { case 'es.filter_manager': return $managers; case 'ongr_filter_manager.filter': return $filters; default: return null; } })); }
/** * Check when Manager Mapping is empty. */ public function testWhenManagerMappingIsEmpty() { $expectedConnections = ['default' => ['hosts' => ['127.0.0.1:9200'], 'index_name' => 'ongr-elasticsearch-bundle-test', 'settings' => ['refresh_interval' => -1, 'number_of_replicas' => 0]]]; $expectedManagers = ['default' => ['connection' => 'default', 'debug' => true, 'readonly' => false, 'mappings' => []]]; $kernelBundles = []; $this->container->expects($this->any())->method('getParameter')->with($this->anything())->will($this->returnCallback(function ($parameters) use($expectedConnections, $expectedManagers, $kernelBundles) { switch ($parameters) { case 'es.connections': return $expectedConnections; case 'es.managers': return $expectedManagers; case 'kernel.bundles': return $expectedManagers; default: return null; } })); $compilerPass = new MappingPass(); $compilerPass->process($this->container); }
public function testBuild() { $this->containerMock->expects($this->once())->method('addCompilerPass')->with($this->isInstanceOf('Igniter\\ElastiCacheBundle\\DependencyInjection\\Compiler\\RedisCompiler')); $compiler = new IgniterElastiCacheBundle(); $compiler->build($this->containerMock); }