public addSubscriber ( Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber ) | ||
$subscriber | Symfony\Component\EventDispatcher\EventSubscriberInterface |
/** * @test */ function shouldCustomizeParameterNames() { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new MockPaginationSubscriber()); // pagination view $dispatcher->addSubscriber(new ArraySubscriber()); $p = new Paginator($dispatcher); $items = array('first', 'second'); $view = $p->paginate($items, 1, 10); // test default names first $this->assertEquals('page', $view->getPaginatorOption('pageParameterName')); $this->assertEquals('sort', $view->getPaginatorOption('sortFieldParameterName')); $this->assertEquals('direction', $view->getPaginatorOption('sortDirectionParameterName')); $this->assertTrue($view->getPaginatorOption('distinct')); $this->assertNull($view->getPaginatorOption('sortFieldWhitelist')); // now customize $options = array('pageParameterName' => 'p', 'sortFieldParameterName' => 's', 'sortDirectionParameterName' => 'd', 'distinct' => false, 'sortFieldWhitelist' => array('a.f', 'a.d')); $view = $p->paginate($items, 1, 10, $options); $this->assertEquals('p', $view->getPaginatorOption('pageParameterName')); $this->assertEquals('s', $view->getPaginatorOption('sortFieldParameterName')); $this->assertEquals('d', $view->getPaginatorOption('sortDirectionParameterName')); $this->assertFalse($view->getPaginatorOption('distinct')); $this->assertEquals(array('a.f', 'a.d'), $view->getPaginatorOption('sortFieldWhitelist')); // change default paginator options $p->setDefaultPaginatorOptions(array('pageParameterName' => 'pg', 'sortFieldParameterName' => 'srt', 'sortDirectionParameterName' => 'dir')); $view = $p->paginate($items, 1, 10); $this->assertEquals('pg', $view->getPaginatorOption('pageParameterName')); $this->assertEquals('srt', $view->getPaginatorOption('sortFieldParameterName')); $this->assertEquals('dir', $view->getPaginatorOption('sortDirectionParameterName')); $this->assertTrue($view->getPaginatorOption('distinct')); }
public function registerSubscribers() { // required $this->dispatcher->addSubscriber(new Subscriber\GracefulTermination()); $this->dispatcher->addSubscriber(new Subscriber\ErrorHandler()); $this->dispatcher->addSubscriber(new Subscriber\Bootstrap()); $this->dispatcher->addSubscriber(new Subscriber\Module()); $this->dispatcher->addSubscriber(new Subscriber\BeforeAfterTest()); // optional if (!$this->options['no-rebuild']) { $this->dispatcher->addSubscriber(new Subscriber\AutoRebuild()); } if (!$this->options['silent']) { $this->dispatcher->addSubscriber(new Subscriber\Console($this->options)); } if ($this->options['fail-fast']) { $this->dispatcher->addSubscriber(new Subscriber\FailFast()); } if ($this->options['coverage']) { $this->dispatcher->addSubscriber(new Coverage\Subscriber\Local($this->options)); $this->dispatcher->addSubscriber(new Coverage\Subscriber\LocalServer($this->options)); $this->dispatcher->addSubscriber(new Coverage\Subscriber\RemoteServer($this->options)); $this->dispatcher->addSubscriber(new Coverage\Subscriber\Printer($this->options)); } // extensions foreach ($this->extensions as $subscriber) { $this->dispatcher->addSubscriber($subscriber); } }
/** * @return EventDispatcher */ protected function getEventDispatcher() { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new EventListener\ErrorLogSubscriber()); $dispatcher->addSubscriber(new EventListener\FailureSubscriber($this->getQueueFactory())); return $dispatcher; }
protected function execute(InputInterface $input, OutputInterface $output) { $codeLocation = $input->getArgument('code-location'); $codeDestination = $input->getOption('code-destination'); $createNamespace = $input->getOption('create-namespace'); $offset = $input->getOption('offset'); $length = $input->getOption('length'); $classyfile = new ClassyFile(); $dispatcher = new EventDispatcher(); if ($input->getOption('constants-to-upper')) { $plugin = new ConstantNamesToUpper(); $dispatcher->addSubscriber($plugin); } if ($input->getOption('psr-fix')) { $plugin = new PhpCsFixer($input, $output); $dispatcher->addSubscriber($plugin); } if ($input->getOption('remove-top-comment')) { $classyfile->setTemplate(new BasicClassTemplate(''), 'getTemplate'); } $classyfile->setEventDispatcher($dispatcher); if ($createNamespace) { $classyfile->generateClassFiles($codeDestination, $codeLocation, $offset, $length); } else { $classyfile->generateClassFiles($codeDestination, $codeLocation); } }
/** * @test */ function shouldSortSimpleDoctrineQuery() { $em = $this->getMockSqliteEntityManager(); $this->populate($em); $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new PaginationSubscriber()); $dispatcher->addSubscriber(new Sortable()); $p = new Paginator($dispatcher); $_GET['sort'] = 'a.title'; $_GET['direction'] = 'asc'; $this->startQueryLog(); $query = $this->em->createQuery('SELECT a FROM Test\\Fixture\\Entity\\Article a'); $view = $p->paginate($query, 1, 10); $items = $view->getItems(); $this->assertEquals(4, count($items)); $this->assertEquals('autumn', $items[0]->getTitle()); $this->assertEquals('spring', $items[1]->getTitle()); $this->assertEquals('summer', $items[2]->getTitle()); $this->assertEquals('winter', $items[3]->getTitle()); $_GET['direction'] = 'desc'; $view = $p->paginate($query, 1, 10); $items = $view->getItems(); $this->assertEquals(4, count($items)); $this->assertEquals('winter', $items[0]->getTitle()); $this->assertEquals('summer', $items[1]->getTitle()); $this->assertEquals('spring', $items[2]->getTitle()); $this->assertEquals('autumn', $items[3]->getTitle()); $this->assertEquals(6, $this->queryAnalyzer->getNumExecutedQueries()); $executed = $this->queryAnalyzer->getExecutedQueries(); $this->assertEquals('SELECT DISTINCT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title ASC LIMIT 10 OFFSET 0', $executed[1]); $this->assertEquals('SELECT DISTINCT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title DESC LIMIT 10 OFFSET 0', $executed[4]); }
public function __construct($name, array $params = []) { $app = $this; $locator = new FileLocator(); $this->routesFileLoader = new YamlFileLoader($locator); $this['context'] = function () { return new RequestContext(); }; $this['matcher'] = function () { return new UrlMatcher($this['routes'], $this['context']); }; $this['resolver'] = function () { return new ControllerResolver($this); }; $this['dispatcher'] = function () use($app) { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new RouterListener($app['matcher'])); $dispatcher->addSubscriber(new ResponseListener($app['charset'])); return $dispatcher; }; $this['kernel'] = function () use($app) { return new HttpKernel($app['dispatcher'], $app['resolver']); }; // $this['request.http_port'] = 80; // $this['request.https_port'] = 443; $this['charset'] = 'UTF-8'; parent::__construct($name, null, $params); $this->setApp($this); }
public function __construct(EventSubscriberInterface $subscriber, MatcherInterface $matcher) { $this->proxied = $subscriber; $this->matcher = $matcher; $this->dispatcher = new EventDispatcher(); $this->dispatcher->addSubscriber($subscriber); }
function get_event_dispatcher() { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new EventListener\ErrorLogSubscriber()); $dispatcher->addSubscriber(new EventListener\FailureSubscriber(get_queue_factory())); return $dispatcher; }
/** * @test */ function shouldSortSimpleDoctrineQuery() { $this->populate(); $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new PaginationSubscriber()); $dispatcher->addSubscriber(new Sortable()); $p = new Paginator($dispatcher); $_GET['sort'] = 'title'; $_GET['direction'] = 'asc'; $qb = $this->dm->createQueryBuilder('Test\\Fixture\\Document\\Article'); $query = $qb->getQuery(); $view = $p->paginate($query, 1, 10); $items = array_values($view->getItems()); $this->assertEquals(4, count($items)); $this->assertEquals('autumn', $items[0]->getTitle()); $this->assertEquals('spring', $items[1]->getTitle()); $this->assertEquals('summer', $items[2]->getTitle()); $this->assertEquals('winter', $items[3]->getTitle()); $_GET['direction'] = 'desc'; $view = $p->paginate($query, 1, 10); $items = array_values($view->getItems()); $this->assertEquals(4, count($items)); $this->assertEquals('winter', $items[0]->getTitle()); $this->assertEquals('summer', $items[1]->getTitle()); $this->assertEquals('spring', $items[2]->getTitle()); $this->assertEquals('autumn', $items[3]->getTitle()); }
public static function getDispatcher() { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new RouterListener(new UrlMatcher(self::getRoutes(), new RequestContext()))); $dispatcher->addSubscriber(new KernelExceptionSubscriber()); return $dispatcher; }
/** @test */ public function it_converts_exception_to_json() { $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); $resolver->expects($this->once())->method('getController')->will($this->returnValue(function () { throw new NotFoundHttpException(); })); $resolver->expects($this->once())->method('getArguments')->will($this->returnValue([])); $logger = $this->getMock('Psr\\Log\\LoggerInterface'); $logger->expects($this->once())->method('error'); $dispatcher = new EventDispatcher(); $httpKernel = new HttpKernel($dispatcher, $resolver); $kernel = new KernelForTest('test', true); $kernel->boot(); $kernel->getContainer()->set('http_kernel', $httpKernel); $dispatcher->addSubscriber(new RequestFormatNegotiationListener()); $dispatcher->addSubscriber(new RequestFormatValidationListener()); $dispatcher->addSubscriber(new ResponseConversionListener()); $dispatcher->addSubscriber(new ExceptionConversionListener($logger)); $request = Request::create('/exception', 'GET', [], [], [], ['HTTP_ACCEPT' => 'application/json']); $request->attributes->set('_format', 'json'); $response = $kernel->handle($request)->prepare($request); $this->assertSame(404, $response->getStatusCode()); $this->assertSame('application/vnd.error+json', $response->headers->get('Content-Type')); $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'Not Found']), $response->getContent()); }
public function setUp() { $this->requestStack = new RequestStack(); $request = new Request(); $this->requestStack->push($request); $this->session = new Session(new MockArraySessionStorage()); $request->setSession($this->session); $this->dispatcher = new EventDispatcher(); $translator = new Translator($this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface')); $token = new TokenProvider($this->requestStack, $translator, 'test'); $this->dispatcher->addSubscriber(new \Thelia\Action\Cart($this->requestStack, $token)); $this->session->setSessionCart(null); $request->setSession($this->session); /** @var \Thelia\Action\Cart cartAction */ $this->cartAction = new \Thelia\Action\Cart($this->requestStack, new TokenProvider($this->requestStack, $translator, 'baba au rhum')); $this->dispatcherNull = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', array(), array(), '', true, true, true, false); $this->dispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($type, $event) { if ($type == TheliaEvents::CART_RESTORE_CURRENT) { $this->cartAction->restoreCurrentCart($event, null, $this->dispatcher); } elseif ($type == TheliaEvents::CART_CREATE_NEW) { $this->cartAction->createEmptyCart($event, null, $this->dispatcher); } })); }
/** * Verifies that permissions are changed. */ public function testChangePermissionsForCommittedSqon() { chmod($this->path, 0644); $this->dispatcher->addSubscriber(new ChmodSubscriber(0755)); $this->dispatcher->dispatch(AfterCommitEvent::NAME, new AfterCommitEvent($this->sqon)); clearstatcache(true, $this->path); self::assertEquals('755', substr(sprintf('%o', fileperms($this->path)), -3, 3), 'The file permissions were not set.'); }
public function setUp() { $this->message = Message::create('lussuti.lus'); $this->ed = new EventDispatcher(); $this->output = $this->getMock('Symfony\\Component\\Console\\Output\\ConsoleOutputInterface'); $subscriber = new ConsoleOutputSubscriber($this->output); $this->ed->addSubscriber($subscriber); }
/** * @test */ public function installShouldCreateCacheDir() { $src = self::$fixturesDirectory . '/config'; $configuration = $this->createConfig($src); $this->eventDispatcher->addSubscriber(new CacheCreateListener($this->bower)); $this->bower->install($configuration); $this->assertFileExists($this->target . '/cache'); }
/** * @test * @expectedException RuntimeException * @expectedExceptionMessage One of listeners must count and slice given target */ function testArrayShouldNotBeHandled() { $array = array('results' => array(0 => array('city' => 'Lyon', 'market' => 'E'), 1 => array('city' => 'Paris', 'market' => 'G')), 'nbTotalResults' => 2); $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new SolariumQuerySubscriber()); $dispatcher->addSubscriber(new MockPaginationSubscriber()); $p = new Paginator($dispatcher); $p->paginate($array, 1, 10); }
/** * Application constructor. */ public function __construct() { parent::__construct('quickstrap', '1.0'); $this->eventDispatcher = new EventDispatcher(); $this->eventDispatcher->addSubscriber(new ComposerSetupSubscriber()); $this->eventDispatcher->addSubscriber(new CwdSubscriber()); $this->setDispatcher($this->eventDispatcher); $this->getDefinition()->addOption(new InputOption('project-path', null, InputOption::VALUE_OPTIONAL, 'The path to the project', getcwd())); }
/** * @test * @expectedException RuntimeException * @expectedExceptionMessage One of listeners must count and slice given target */ function testArrayShouldNotBeHandled() { $array = array(1 => 'foo', 2 => 'bar'); $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new SolariumQuerySubscriber()); $dispatcher->addSubscriber(new MockPaginationSubscriber()); $p = new Paginator($dispatcher); $p->paginate($array, 1, 10); }
protected function registerSubscribers() { $helperSet = $this->getHelperSet(); $this->dispatcher->addSubscriber(new TableSubscriber()); $this->dispatcher->addSubscriber(new GitDirectorySubscriber($helperSet->get('git'))); $this->dispatcher->addSubscriber(new GitRepoSubscriber($this, $helperSet->get('git'), $helperSet->get('git_config'), $helperSet->get('gush_style'))); $this->dispatcher->addSubscriber(new CoreInitSubscriber($this, $helperSet->get('git'), $helperSet->get('git_config'), $helperSet->get('gush_style'))); $this->dispatcher->addSubscriber(new TemplateSubscriber($helperSet->get('template'))); $this->dispatcher->addSubscriber(new CommandEndSubscriber($helperSet->get('filesystem'), $helperSet->get('git'))); }
/** * @test */ public function canReturnEarlyResponse() { $eventDispatcher = new EventDispatcher(); $eventDispatcher->addSubscriber(new FakeCacheSubscriber()); $eventDispatcher->addSubscriber(new RequestSubscriber()); $requestEvent = new RequestEvent(new Request('/', '1337')); $eventDispatcher->dispatch(TmdbEvents::REQUEST, $requestEvent); $response = $requestEvent->getResponse(); $this->assertEquals(301, $response->getCode()); }
protected function initDispatcher() { $this['dispatcher'] = function ($container) { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new RouterListener($container['url-matcher'], null, $container['logger.logger'])); $dispatcher->addSubscriber(new LocaleListener($container['locale'])); $dispatcher->addSubscriber(new NamelessListener($container['session.session'], $container['benchmark'], $container['logger.logger'])); $dispatcher->addSubscriber(new ResponseListener('UTF-8')); return $dispatcher; }; }
private function __construct($routes) { $this->routeCollection = $routes; $this->request = Request::createFromGlobals(); $this->requestContext = new RequestContext(); $this->matcher = new UrlMatcher($routes, $this->requestContext->fromRequest($this->getRequest())); $this->dispatcher = new Dispatcher(); $this->dispatcher->addSubscriber(new RouterListener($this->matcher, new RequestStack())); $this->dispatcher->addSubscriber(new KernelExceptionListener()); $this->dispatcher->addSubscriber(new ResponseListener('UTF-8')); }
/** * @test */ function shouldGiveCustomParametersToPaginationView() { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new CustomParameterSubscriber()); $dispatcher->addSubscriber(new MockPaginationSubscriber()); // pagination view $p = new Paginator($dispatcher); $items = array('first', 'second'); $view = $p->paginate($items, 1, 10); $this->assertEquals('val', $view->getCustomParameter('test')); $this->assertNull($view->getCustomParameter('nonExisting')); }
public function __construct($BaseUrl = '') { AutoLoader::getNamespaceAutoLoader('Symfony\\Component', __DIR__ . '/../../../Vendor/'); AutoLoader::getNamespaceAutoLoader('Symfony\\Component', __DIR__ . '/../../../../../Core/HttpKernel/Vendor/'); $this->SymfonyRouteCollection = new RouteCollection(); $this->SymfonyRequestContext = new RequestContext(); $this->SymfonyRequestContext->setBaseUrl($BaseUrl); $this->SymfonyUrlMatcher = new UrlMatcher($this->SymfonyRouteCollection, $this->SymfonyRequestContext); $this->SymfonyEventDispatcher = new EventDispatcher(); $this->SymfonyEventDispatcher->addSubscriber(new RouterListener($this->SymfonyUrlMatcher)); $this->SymfonyHttpKernel = new HttpKernel($this->SymfonyEventDispatcher, new ControllerResolver()); }
/** * Create HTTP kernel * * @return HttpKernel\HttpKernel */ public function createHttpKernel(Request $request) { $context = new Routing\RequestContext(); $context->fromRequest($request); $matcher = new Routing\Matcher\UrlMatcher($this->routes, $context); $errorHandler = array(new ErrorController(), 'exception'); $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new HttpKernel\EventListener\ExceptionListener($errorHandler)); $dispatcher->addSubscriber(new HttpKernel\EventListener\RouterListener($matcher)); $dispatcher->addSubscriber(new HttpKernel\EventListener\ResponseListener('UTF-8')); $resolver = new HttpKernel\Controller\ControllerResolver(); return new HttpKernel\HttpKernel($dispatcher, $resolver); }
protected function initExtensions() { if (!$this->extensionsInitialized) { foreach ($this->getExtensions() as $extension) { $this->attributes = array_merge_recursive($this->attributes, $extension->getAttributes()); $this->nodes = array_merge_recursive($this->nodes, $extension->getNodes()); foreach ($extension->getSubscribers() as $subscriber) { $this->dispatcher->addSubscriber($subscriber); } } $this->extensionsInitialized = true; } }
protected function setUp() { parent::setUp(); $this->dispatcher = new EventDispatcher(); $this->sut = new CwdSubscriber(); $this->dispatcher->addSubscriber($this->sut); $this->projectPath = sys_get_temp_dir(); $this->pathHelper = $this->getMock(PathHelper::class); $this->command = $this->getMockBuilder(Command::class)->disableOriginalConstructor()->getMock(); $this->command->expects(static::any())->method('getHelper')->with('path')->willReturn($this->pathHelper); $this->input = $input = $this->getMock(InputInterface::class); $input->expects(static::any())->method('getOption')->willReturn($this->projectPath); $this->output = $this->getMock(OutputInterface::class); }
/** * Constructor. */ public function __construct() { $app = $this; $this['autoloader'] = $this->share(function () { $loader = new UniversalClassLoader(); $loader->register(); return $loader; }); $this['routes'] = $this->share(function () { return new RouteCollection(); }); $this['controllers'] = $this->share(function () use($app) { return new ControllerCollection(); }); $this['exception_handler'] = $this->share(function () { return new ExceptionHandler(); }); $this['dispatcher'] = $this->share(function () use($app) { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber($app); $urlMatcher = new LazyUrlMatcher(function () use($app) { return $app['url_matcher']; }); $dispatcher->addSubscriber(new RouterListener($urlMatcher)); return $dispatcher; }); $this['resolver'] = $this->share(function () use($app) { return new ControllerResolver($app); }); $this['kernel'] = $this->share(function () use($app) { return new HttpKernel($app['dispatcher'], $app['resolver']); }); $this['request_context'] = $this->share(function () use($app) { $context = new RequestContext(); $context->setHttpPort($app['request.http_port']); $context->setHttpsPort($app['request.https_port']); return $context; }); $this['url_matcher'] = $this->share(function () use($app) { return new RedirectableUrlMatcher($app['routes'], $app['request_context']); }); $this['request.default_locale'] = 'en'; $this['request'] = function () { throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.'); }; $this['request.http_port'] = 80; $this['request.https_port'] = 443; $this['debug'] = false; $this['charset'] = 'UTF-8'; }
/** * @test */ function shouldSlicePaginateAnArray() { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new ArraySubscriber()); $dispatcher->addSubscriber(new MockPaginationSubscriber()); // pagination view $p = new Paginator($dispatcher); $items = range('a', 'u'); $view = $p->paginate($items, 2, 10); $this->assertEquals(2, $view->getCurrentPageNumber()); $this->assertEquals(10, $view->getItemNumberPerPage()); $this->assertEquals(10, count($view->getItems())); $this->assertEquals(21, $view->getTotalItemCount()); }
public function init() { $this->dispatcher = new EventDispatcher(); foreach ($this->events as $event => $listeners) { foreach ($listeners as $listener) { $this->dispatcher->addListener($event, $listener); } } foreach ($this->subscribers as $event => $subscribers) { foreach ($subscribers as $subscriber) { $this->dispatcher->addSubscriber($subscriber); } } parent::init(); }