本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcherInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcherInterface::expects方法的具体用法?PHP EventDispatcherInterface::expects怎么用?PHP EventDispatcherInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\EventDispatcher\EventDispatcherInterface
的用法示例。
在下文中一共展示了EventDispatcherInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetFields
/**
* @param array $fields
* @param array $configValues
* @param array $expected
*
* @dataProvider fieldsDataProvider
*/
public function testGetFields(array $fields, array $configValues, array $expected)
{
$entity = new \StdClass();
foreach ($fields as $field) {
/** @var ConfigInterface $field */
$fieldId = $field->getId();
/** @var FieldConfigId $fieldId */
$fieldName = $fieldId->getFieldName();
$entity->{$fieldName} = $fieldName;
}
$this->configProvider->expects($this->once())->method('filter')->will($this->returnValue($fields));
$config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
$this->configProvider->expects($this->any())->method('getConfigById')->will($this->returnValue($config));
foreach ($configValues as $key => $configValue) {
$config->expects($this->at($key))->method('get')->will($this->returnCallback(function ($value, $strict, $default) use($configValue) {
if (!is_null($configValue)) {
return $configValue;
}
return $default;
}));
}
$this->dispatcher->expects($this->exactly(sizeof($fields)))->method('dispatch');
$rows = $this->extension->getFields($entity);
$this->assertEquals(json_encode($expected), json_encode($rows));
}
示例2: testFixtureManager
public function testFixtureManager()
{
$this->loader->expects($this->once())->method('load')->will($this->returnValue(new FixtureCollection()));
$this->executor->expects($this->once())->method('execute');
$this->persister->expects($this->once())->method('flush');
$this->eventDispatcher->expects($this->exactly(5))->method('dispatch');
$this->fixtureManager->load(null);
}
示例3: setUpDisplayVariant
/**
* Sets up a display variant plugin for testing.
*
* @param array $configuration
* An array of plugin configuration.
* @param array $definition
* The plugin definition array.
*
* @return \Drupal\block\Plugin\DisplayVariant\BlockPageVariant|\PHPUnit_Framework_MockObject_MockObject
* A mocked display variant plugin.
*/
public function setUpDisplayVariant($configuration = array(), $definition = array())
{
$this->blockRepository = $this->getMock('Drupal\\block\\BlockRepositoryInterface');
$this->blockViewBuilder = $this->getMock('Drupal\\Core\\Entity\\EntityViewBuilderInterface');
$this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$this->dispatcher->expects($this->any())->method('dispatch')->willReturnArgument(1);
return $this->getMockBuilder('Drupal\\block\\Plugin\\DisplayVariant\\BlockPageVariant')->setConstructorArgs(array($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, $this->dispatcher, ['config:block_list']))->setMethods(array('getRegionNames'))->getMock();
}
示例4: testRender
public function testRender()
{
$view = $this->createView();
$view->setTemplateIdentifier('path/to/template.html.twig');
$this->eventDispatcherMock->expects($this->once())->method('dispatch')->with(MVCEvents::PRE_CONTENT_VIEW, $this->isInstanceOf('\\eZ\\Publish\\Core\\MVC\\Symfony\\Event\\PreContentViewEvent'));
$this->templateEngineMock->expects($this->once())->method('render')->with('path/to/template.html.twig', $view->getParameters());
$this->renderer->render($view);
}
示例5: getEventMock
/**
* @return PHPUnit_Framework_MockObject_MockObject|$class
*/
protected function getEventMock($class)
{
if (!isset($this->eventMock)) {
$this->eventMock = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
$this->eventMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->getRequestMock()));
}
return $this->eventMock;
}
示例6: testCreate
public function testCreate()
{
$this->builder->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
$this->factory->expects($this->once())->method('createItem')->with($this->identicalTo($name))->will($this->returnValue($item = $this->createItemMock()));
$this->eventDispatcher->expects($this->once())->method('dispatch')->with($this->identicalTo(MenuBuilderEvents::BUILD), $this->callback(function (MenuBuilderEvent $event) use($item) {
return $event->getFactory() === $this->factory && $event->getItem() === $item;
}));
$this->assertSame($item, $this->builder->create());
}
示例7: testCreateDefaultPluginInstanceWithDefaultPluginInstance
/**
* @covers ::createDefaultPluginInstance
*/
public function testCreateDefaultPluginInstanceWithDefaultPluginInstance()
{
$default_plugin_instance = $this->getMock(PluginInspectionInterface::class);
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(PluginEvents::RESOLVE_DEFAULT_PLUGIN, $this->isInstanceOf(ResolveDefaultPlugin::class))->willReturnCallback(function ($event_name, ResolveDefaultPlugin $event) use($default_plugin_instance) {
$event->setDefaultPluginInstance($default_plugin_instance);
});
$plugin_type = $this->getMock(PluginTypeInterface::class);
$this->assertSame($default_plugin_instance, $this->sut->createDefaultPluginInstance($plugin_type));
}
示例8: setUp
public function setUp()
{
$user = $this->createMock('FOS\\UserBundle\\Model\\UserInterface');
$user->expects($this->once())->method('isEnabled')->willReturn(true);
$response = $this->createMock('Symfony\\Component\\HttpFoundation\\Response');
$request = $this->createMock('Symfony\\Component\\HttpFoundation\\Request');
$this->event = new FilterUserResponseEvent($user, $request, $response);
$this->eventDispatcher = $this->createMock('Symfony\\Component\\EventDispatcher\\EventDispatcher');
$this->eventDispatcher->expects($this->once())->method('dispatch');
$loginManager = $this->createMock('FOS\\UserBundle\\Security\\LoginManagerInterface');
$this->listener = new AuthenticationListener($loginManager, self::FIREWALL_NAME);
}
示例9: testConsume
public function testConsume()
{
$queue = 'foobar';
$message = $this->createMock(MessageInterface::class);
$iterator = new TestIterator([$message]);
$this->backendProvider->expects($this->any())->method('getBackend')->with($queue)->willReturn($this->backend);
$this->backend->expects($this->any())->method('getIterator')->willReturn($iterator);
$this->backend->expects($this->once())->method('handle')->with($message, $this->notificationDispatcher);
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(IterateEvent::EVENT_NAME, new IterateEvent($this->backend->getIterator(), $this->backend, $message));
// the $iterator does not pop elements so we have to make sure ->tick() does not iterate over the same array multiple times
$this->subject->consume($queue, ['stop-when-empty' => true]);
}
示例10: testProcessValidData
public function testProcessValidData()
{
$this->request->setMethod('POST');
$this->form->expects($this->once())->method('setData')->with($this->entity);
$this->form->expects($this->once())->method('submit')->with($this->request);
$this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
$this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em));
$this->em->expects($this->once())->method('persist')->with($this->entity);
$this->em->expects($this->once())->method('flush');
$this->dispatcher->expects($this->once())->method('dispatch')->with($this->equalTo(ChannelSaveEvent::EVENT_NAME), $this->isInstanceOf('OroCRM\\Bundle\\ChannelBundle\\Event\\ChannelSaveEvent'));
$this->assertTrue($this->handler->process($this->entity));
}
示例11: testDispatchFormEvent
public function testDispatchFormEvent()
{
/** @var \PHPUnit_Framework_MockObject_MockObject|FormInterface $form */
$form = $this->getMock('Symfony\\Component\\Form\\FormInterface');
$form->expects($this->once())->method('getName')->will($this->returnValue('form_name'));
$data = [];
$event = new FormProcessEvent($form, $data);
$eventName = 'test_event_name';
$this->eventDispatcher->expects($this->exactly(2))->method('dispatch');
$this->eventDispatcher->expects($this->at(0))->method('dispatch')->with($eventName, $event);
$this->eventDispatcher->expects($this->at(1))->method('dispatch')->with($eventName . '.form_name', $event);
$this->immutableDispatcher->dispatch($eventName, $event);
}
示例12: testHandle
public function testHandle()
{
$this->firewall->expects($this->once())->method('authorize')->with($this->identicalTo($headers = ['X-Hub-Signature' => 'sha1=52b582138706ac0c597c315cfc1a1bf177408a4d']), $this->identicalTo($body = '{"foo":"bar"}'))->will($this->returnValue(true));
$process = $this->createProcessMock();
$this->eventDispatcher->expects($this->once())->method('dispatch')->with($this->identicalTo(WebhookEvents::HOOK), $this->callback(function ($event) use($body, $process) {
if (!$event instanceof WebhookEvent || $event->getPayload() !== json_decode($body, true)) {
return false;
}
$event->addProcess($process);
return true;
}));
$this->processProducer->expects($this->once())->method('publish')->with($this->identicalTo($process));
$this->handler->handle($headers, $body);
}
示例13: testRebuildWithProviderBasedRoutes
/**
* Tests the rebuild with routes provided by a callback.
*
* @see \Drupal\Core\Routing\RouteBuilder::rebuild()
*/
public function testRebuildWithProviderBasedRoutes()
{
$this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE));
$this->yamlDiscovery->expects($this->once())->method('findAll')->will($this->returnValue(array('test_module' => array('route_callbacks' => array('\\Drupal\\Tests\\Core\\Routing\\TestRouteSubscriber::routesFromArray', 'test_module.route_service:routesFromCollection')))));
$container = new ContainerBuilder();
$container->set('test_module.route_service', new TestRouteSubscriber());
$this->controllerResolver->expects($this->any())->method('getControllerFromDefinition')->will($this->returnCallback(function ($controller) use($container) {
$count = substr_count($controller, ':');
if ($count == 1) {
list($service, $method) = explode(':', $controller, 2);
$object = $container->get($service);
} else {
list($class, $method) = explode('::', $controller, 2);
$object = new $class();
}
return array($object, $method);
}));
$route_collection_filled = new RouteCollection();
$route_collection_filled->add('test_route.1', new Route('/test-route/1'));
$route_collection_filled->add('test_route.2', new Route('/test-route/2'));
$route_build_event = new RouteBuildEvent($route_collection_filled);
// Ensure that the alter routes events are fired.
$this->dispatcher->expects($this->at(0))->method('dispatch')->with(RoutingEvents::DYNAMIC, $route_build_event);
$this->dispatcher->expects($this->at(1))->method('dispatch')->with(RoutingEvents::ALTER, $route_build_event);
// Ensure that the routes are set to the dumper and dumped.
$this->dumper->expects($this->at(0))->method('addRoutes')->with($route_collection_filled);
$this->dumper->expects($this->at(1))->method('dump');
$this->assertTrue($this->routeBuilder->rebuild());
}
示例14: testEventDispatching
/**
* @dataProvider eventDataProvider
*
* @param Integration $entity
* @param null|User $newOwner
* @param Integration|null $oldIntegration
* @param bool $expectOwnerSetEvent
* @param bool $expectIntegrationUpdateEvent
*/
public function testEventDispatching($entity, $newOwner, $oldIntegration, $expectOwnerSetEvent, $expectIntegrationUpdateEvent)
{
$this->request->setMethod('POST');
$this->form->expects($this->once())->method('setData')->with($entity)->will($this->returnCallback(function ($entity) use($newOwner) {
$entity->setDefaultUserOwner($newOwner);
}));
$this->form->expects($this->once())->method('submit')->with($this->request);
$this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
$this->em->expects($this->once())->method('persist')->with($entity);
$this->em->expects($this->once())->method('flush');
if ($entity->getId()) {
$this->em->expects($this->once())->method('find')->with('OroIntegrationBundle:Channel', $entity->getId())->will($this->returnValue($oldIntegration));
}
$dispatchCallIndex = 0;
if ($expectOwnerSetEvent) {
$this->eventDispatcher->expects($this->at($dispatchCallIndex++))->method('dispatch')->with($this->equalTo(DefaultOwnerSetEvent::NAME), $this->isInstanceOf('Oro\\Bundle\\IntegrationBundle\\Event\\DefaultOwnerSetEvent'));
}
if ($expectIntegrationUpdateEvent) {
$this->eventDispatcher->expects($this->at($dispatchCallIndex++))->method('dispatch')->with($this->equalTo(IntegrationUpdateEvent::NAME), $this->callback(function ($event) use($entity, $oldIntegration) {
$this->assertInstanceOf('Oro\\Bundle\\IntegrationBundle\\Event\\IntegrationUpdateEvent', $event);
$this->assertSame($entity, $event->getIntegration());
$this->assertEquals($oldIntegration, $event->getOldState());
return true;
}));
} elseif (!$expectOwnerSetEvent) {
$this->eventDispatcher->expects($this->never())->method('dispatch');
}
$this->assertTrue($this->handler->process($entity));
}
示例15: testScheduleSourceProcessOnSourceUnlinked
/**
* Tests that a source is scheduled for processing if it's unlinked.
*/
public function testScheduleSourceProcessOnSourceUnlinked()
{
$this->listener->expects($this->once())->method('isSourceModified')->will($this->returnValue(false));
$this->sourceProcessor->expects($this->once())->method('isLinked')->will($this->returnValue(false));
$this->eventDispatcher->expects($this->once())->method('dispatch')->with($this->equalTo(IoEvents::SOURCE_PROCESS));
$this->listener->onFlush($this->getOnFlushEventArgs(new SourceMock(12345)));
$this->listener->postFlush(new PostFlushEventArgs($this->entityManager));
}