本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::expects方法的具体用法?PHP ContainerBuilder::expects怎么用?PHP ContainerBuilder::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProcessUndefinedServers
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);
}
示例2: testProcessWithoutParameter
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);
}
示例3: testServiceExistsWithTaggedServices
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);
}
示例4: testProcess
/**
* @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);
}
示例5: testProcessNoTagged
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);
}
示例6: testServiceExistsWithTaggedServices
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);
}
示例7: testProcess
/**
* @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());
}
示例8: testProcessWithLazyRegistry
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);
}
示例9: testProcessWithoutAlias
/**
* @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);
}
示例10: testProcess
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);
}
示例11: testProcess
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);
}
示例12: setMockContainerService
/**
* 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);
}
示例13: setContainerConfig
/**
* 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;
}
}));
}
示例14: testWhenManagerMappingIsEmpty
/**
* 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);
}
示例15: testBuild
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);
}