/**
  * Setup the ZF2 extension.
  *
  * @param  \PhpSpec\ServiceContainer $container
  * @return void
  */
 public function load(ServiceContainer $container)
 {
     chdir(__DIR__);
     self::chroot();
     self::initAutoloader();
     $zf2ModulePaths = array(dirname(dirname(__DIR__)));
     if ($path = static::findParentPath('vendor')) {
         $zf2ModulePaths[] = $path;
     }
     if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0]) {
         $zf2ModulePaths[] = $path;
     }
     $config = (require getcwd() . '/config/application.config.php');
     $container->setShared('zf2', function ($c) use($config) {
         $serviceManager = new ServiceManager(new ServiceManagerConfig());
         $serviceManager->setService('ApplicationConfig', $config);
         $serviceManager->get('ModuleManager')->loadModules();
         return $serviceManager;
     });
     $container->setShared('runner.maintainers.zf2sm', function ($c) {
         return new ServiceManagerMaintainer($c->get('zf2'));
     });
     $container->setShared('event_dispatcher.listeners.zf2', function ($c) {
         return new ZendFramework2Listener($c->get('zf2'));
     });
 }
Exemple #2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $helperSet = $this->getHelperSet();
     $this->container->set('console.input', $input);
     $this->container->set('console.output', $output);
     $this->container->setShared('console.prompter.factory', function ($c) use($helperSet) {
         return new Factory($c->get('console.input'), $c->get('console.output'), $helperSet);
     });
     $this->container->setShared('process.executioncontext', function () {
         return JsonExecutionContext::fromEnv($_SERVER);
     });
     $assembler = new ContainerAssembler();
     $assembler->build($this->container);
     $this->loadConfigurationFile($input, $this->container);
     foreach ($this->container->getByPrefix('console.commands') as $command) {
         $this->add($command);
     }
     $this->setDispatcher($this->container->get('console_event_dispatcher'));
     $this->container->get('console.io')->setConsoleWidth($this->getTerminalWidth());
     StreamWrapper::reset();
     foreach ($this->container->getByPrefix('loader.resource_loader.spec_transformer') as $transformer) {
         StreamWrapper::addTransformer($transformer);
     }
     StreamWrapper::register();
     return parent::doRun($input, $output);
 }
 public function load(ServiceContainer $container)
 {
     $container->setShared('runner.maintainers.phpunit_matchers', function ($c) {
         return new PHPUnitMatchersMaintainer($c->get('formatter.presenter'));
     });
     $container->setShared('formatter.presenter.differ', function ($c) {
         return new Differ();
     });
 }
 private function setCodeGenerators(ServiceContainer $container)
 {
     $container->setShared('code_generator.generators.wp_class', function ($c) {
         return new WpGenerator($c->get('console.io'), $c->get('code_generator.templates'), $c->get('filesystem'));
     });
     $container->setShared('code_generator.generators.wp_specification', function ($c) {
         return new SpecificationGenerator($c->get('console.io'), $c->get('code_generator.templates'), $c->get('filesystem'));
     });
 }
 protected function setupUtils(ServiceContainer $container)
 {
     $container->setShared('well.utils.filesystem', function () {
         return new Filesystem();
     });
     $container->setShared('well.utils.inspector', function ($c) {
         return new ResourceInspector($c->get('well.utils.filesystem'));
     });
 }
 /**
  * {@inheritdoc}
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('locator.resource_relocator', function ($c) {
         return new ResourceRelocator(new Filesystem());
     });
     $container->setShared('console.commands.rename', function ($c) {
         return new RenameCommand();
     });
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('code_generator.generators.specification', function (ServiceContainer $c) {
         return new ClassNotationSpecificationGenerator($c->get('console.io'), $c->get('code_generator.templates'));
     });
     $container->setParam('code_generator.templates.paths', array(rtrim(__DIR__, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.phpspec'));
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('silex.app', function ($c) {
         $config = $c->getParam('silex_extension');
         $path = $this->getBootstrapPath(isset($config['bootstrap_path']) ? $config['bootstrap_path'] : 'app/boostrap.php');
         if (!is_file($path)) {
             throw new InvalidArgumentException("App bootstrap at `{$path}` not found.");
         }
         $realpath = realpath($path);
         $app = (require_once $realpath);
         $this->removeSilexExceptionAndErrorHandler();
         return $app;
     });
     $container->setShared('runner.maintainers.silex_app', function ($c) {
         return new AppMaintainer($c->get('silex.app'));
     });
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $helperSet = $this->getHelperSet();
     $this->container->set('console.input', $input);
     $this->container->set('console.output', $output);
     $this->container->setShared('console.prompter.factory', function ($c) use($helperSet) {
         return new Factory($c->get('console.input'), $c->get('console.output'), $helperSet);
     });
     $assembler = new ContainerAssembler();
     $assembler->build($this->container);
     $this->loadConfigurationFile($input, $this->container);
     foreach ($this->container->getByPrefix('console.commands') as $command) {
         $this->add($command);
     }
     $this->setDispatcher($this->container->get('console_event_dispatcher'));
     $this->container->get('console.io')->setConsoleWidth($this->getTerminalWidth());
     return parent::doRun($input, $output);
 }
 /**
  * @param ServiceContainer $container
  */
 public function build(ServiceContainer $container)
 {
     $container->setShared('console.commands.describe_model', function ($c) {
         return new DescribeModelCommand();
     });
     $container->setShared('console.commands.describe_resource_model', function ($c) {
         return new DescribeResourceModelCommand();
     });
     $container->setShared('console.commands.describe_block', function ($c) {
         return new DescribeBlockCommand();
     });
     $container->setShared('console.commands.describe_helper', function ($c) {
         return new DescribeHelperCommand();
     });
     $container->setShared('console.commands.describe_controller', function ($c) {
         return new DescribeControllerCommand();
     });
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('event_dispatcher.listeners.data_provider', function ($c) {
         return new DataProviderListener();
     });
     $container->set('runner.maintainers.data_provider', function ($c) {
         return new DataProviderMaintainer();
     });
 }
 /**
  * Setup the Laravel extension.
  *
  * @param \PhpSpec\ServiceContainer $container
  * @return void
  */
 public function load(ServiceContainer $container)
 {
     $getBoostrapPath = function ($manualPath = null) {
         // Configured absolute paths
         if ($manualPath !== null && strpos($manualPath, '/') === 0) {
             return $manualPath . '/bootstrap';
         }
         // Paths relative to vendor/ dir
         if (!is_dir($vendorDir = getcwd() . '/vendor')) {
             $vendorDir = __DIR__ . '/../../../../../..';
         }
         if ($manualPath !== null && is_dir($vendorDir . '/' . $manualPath)) {
             return $vendorDir . '/' . $manualPath . '/bootstrap';
         } else {
             return $vendorDir . '/../bootstrap';
         }
     };
     // Create & store Laravel wrapper
     $container->setShared('laravel', function ($c) use($getBoostrapPath) {
         $config = $c->getParam('laravel_extension');
         $bootstrapPath = $getBoostrapPath(isset($config['framework_path']) ? $config['framework_path'] : null);
         if (file_exists($bootstrapPath . '/autoload.php')) {
             require $bootstrapPath . '/autoload.php';
         } else {
             die("Bootstrap dir not found at {$bootstrapPath}");
         }
         $laravel = new Laravel(isset($config['testing_environment']) ? $config['testing_environment'] : null, $bootstrapPath);
         return $laravel->setMigrateDatabase(isset($config['migrate_db']) ? $config['migrate_db'] : false)->setSeedDatabase(isset($config['seed_db']) ? $config['seed_db'] : false, isset($config['seed_class']) ? $config['seed_class'] : null);
     });
     // Bootstrap maintainer to bind Laravel wrapper to specs
     $container->setShared('runner.maintainers.laravel', function ($c) {
         return new LaravelMaintainer($c->get('laravel'));
     });
     // Bootstrap maintainer to bind app Presenter to specs, so it
     // can be passed to custom matchers
     $container->setShared('runner.maintainers.presenter', function ($c) {
         return new PresenterMaintainer($c->get('formatter.presenter'));
     });
     // Bootstrap listener to setup Laravel application for specs
     $container->setShared('event_dispatcher.listeners.laravel', function ($c) {
         return new LaravelListener($c->get('laravel'));
     });
 }
 protected function loadConfigurationFile(InputInterface $input, ServiceContainer $container)
 {
     $container->setShared('event_dispatcher.listeners.phpguard', function ($c) {
         $ext = new PhpGuardExtension();
         if ($runner = CodeCoverageSession::getCached()) {
             $ext->setCoverageRunner($runner);
         }
         $ext->load($c);
         return $ext;
     });
     parent::loadConfigurationFile($input, $container);
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('console.commands.describe', function () {
         return new DescribeCommand();
     });
     $container->setShared('code_generator.generators.broadway_command_handler_class', function ($c) {
         return new CommandHandlerClassGenerator($c->get('console.io'), $c->get('code_generator.templates'));
     });
     $container->setShared('code_generator.generators.broadway_command_handler_specification', function ($c) {
         $generator = new CommandHandlerSpecificationGenerator($c->get('console.io'), $c->get('code_generator.templates'));
         $generator->setCommand($c->getParam('broadway.acts-on'));
         return $generator;
     });
     $container->setShared('code_generator.generators.broadway_projector_class', function ($c) {
         return new ProjectorClassGenerator($c->get('console.io'), $c->get('code_generator.templates'));
     });
     $container->setShared('code_generator.generators.broadway_projector_specification', function ($c) {
         $generator = new ProjectorSpecificationGenerator($c->get('console.io'), $c->get('code_generator.templates'));
         $generator->setEvent($c->getParam('broadway.acts-on'));
         return $generator;
     });
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('phpspec_extension.git.repository', function () {
         return GitRepository::fromCurrentWorkingDirectory();
     });
     // N.B. - this is not ideal, but there appears to be no other way to achieve this currently.
     $classGenerator = $container->get('code_generator.generators.class');
     $specGenerator = $container->get('code_generator.generators.specification');
     $interfaceGenerator = $container->get('code_generator.generators.interface');
     $this->decorateGenerator($container, 'code_generator.generators.class', $classGenerator);
     $this->decorateGenerator($container, 'code_generator.generators.specification', $specGenerator);
     $this->decorateGenerator($container, 'code_generator.generators.interface', $interfaceGenerator);
 }
 /**
  * Setup the Laravel extension.
  *
  * @param  \PhpSpec\ServiceContainer $container
  * @return void
  */
 public function load(ServiceContainer $container)
 {
     // Create & store Laravel wrapper
     $container->setShared('laravel', function ($c) {
         $config = $c->getParam('laravel_extension');
         $laravel = new Laravel(isset($config['testing_environment']) ? $config['testing_environment'] : null, $this->getBootstrapPath(isset($config['framework_path']) ? $config['framework_path'] : null));
         return $laravel;
     });
     // Bootstrap maintainer to bind Laravel wrapper to specs
     $container->setShared('runner.maintainers.laravel', function ($c) {
         return new LaravelMaintainer($c->get('laravel'));
     });
     // Bootstrap maintainer to bind app Presenter to specs, so it
     // can be passed to custom matchers
     $container->setShared('runner.maintainers.presenter', function ($c) {
         return new PresenterMaintainer($c->get('formatter.presenter'));
     });
     // Bootstrap listener to setup Laravel application for specs
     $container->setShared('event_dispatcher.listeners.laravel', function ($c) {
         return new LaravelListener($c->get('laravel'));
     });
 }
Exemple #17
0
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     /** @var IO $io */
     $io = $container->get('console.io');
     if (!extension_loaded('xdebug')) {
         $io->writeln('<fg=white;bg=red>Code coverage disabled (missing xdebug extension)</>');
         return;
     }
     $container->setShared('event_dispatcher.listeners.addvilz_code_coverage', function (ServiceContainer $container) use($io) {
         $defaults = ['max_specs' => 1];
         $options = array_merge($defaults, $container->getParam('phpspec_cover', []));
         $listener = new Listener(new \PHP_CodeCoverage(), $io, new Reporter(new OutputFormatter($io->isDecorated())), $options['max_specs']);
         register_shutdown_function([$listener, 'shutdown']);
         return $listener;
     });
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('loader.resource_loader', function (ServiceContainer $c) {
         $filters = $c->getParam('humbug.filtered_resource_loader.filters');
         $filteredResourceLoader = new FilteredResourceLoader($c->get('locator.resource_manager'));
         if (null !== $filters && is_array($filters)) {
             foreach ($filters as $class) {
                 $filter = new $class();
                 if (($class === 'Humbug\\PhpSpec\\Loader\\Filter\\Specification\\FastestFirstFilter' || $class === 'Humbug\\PhpSpec\\Loader\\Filter\\Example\\FastestFirstFilter') && null !== $c->getParam('humbug.time_collector.target')) {
                     $filter->setLoggerFile($c->getParam('humbug.time_collector.target'));
                 }
                 if ($class === 'Humbug\\PhpSpec\\Loader\\Filter\\Specification\\IncludeOnlyFilter' && null !== $c->getParam('humbug.filter.include_only.specs')) {
                     $filter->setSpecs($c->getParam('humbug.filter.include_only.specs'));
                 }
                 $filteredResourceLoader->addFilter($filter);
             }
         }
         return $filteredResourceLoader;
     });
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('event_dispatcher.listeners.class_listener', function (ServiceContainer $c) {
         return new ClassListener($c->get('elfiggo.brobdingnagian.detector'), $c->get('elfiggo.brobdingnagian.params'), $c->get('elfiggo.brobdingnagian.reporter'), $c->get('console.io'));
     });
     $container->setShared('elfiggo.brobdingnagian.detector', function () {
         return new Detector();
     });
     $container->setShared('elfiggo.brobdingnagian.params', function (ServiceContainer $c) {
         return new Params($c);
     });
     $container->setShared('elfiggo.brobdingnagian.reporter', function (ServiceContainer $c) {
         return new Reporter($c->get('elfiggo.brobdingnagian.params'), $c->get('elfiggo.brobdingnagian.logger'), $c->get('elfiggo.brobdingnagian.exception'));
     });
     $container->setShared('elfiggo.brobdingnagian.logger', function (ServiceContainer $c) {
         return new LoggerHandler();
     });
     $container->setShared('elfiggo.brobdingnagian.exception', function (ServiceContainer $c) {
         return new ExceptionHandler();
     });
     $container->setShared('console.commands.run', function () {
         return new ListBrobCommand();
     });
 }
Exemple #20
0
 private function setEvents(ServiceContainer $container)
 {
     $container->setShared('event_dispatcher.listeners.module_update', function ($c) {
         return new ModuleUpdateListener($c->get('xml_generator.generators.module'), $c->get('xml_generator.generators.config'), $c->get('console.io'), $c->get('util.class_detector'));
     });
 }
 /**
  * @param ServiceContainer $container
  */
 private function setupRerunner(ServiceContainer $container)
 {
     $container->setShared('process.rerunner', function (ServiceContainer $c) {
         return new ReRunner\OptionalReRunner($c->get('process.rerunner.platformspecific'), $c->get('console.io'));
     });
     if ($container->isDefined('process.rerunner.platformspecific')) {
         return;
     }
     $container->setShared('process.rerunner.platformspecific', function (ServiceContainer $c) {
         return new ReRunner\CompositeReRunner($c->getByPrefix('process.rerunner.platformspecific'));
     });
     $container->setShared('process.rerunner.platformspecific.pcntl', function (ServiceContainer $c) {
         return new ReRunner\PcntlReRunner($c->get('process.phpexecutablefinder'));
     });
     $container->setShared('process.rerunner.platformspecific.passthru', function (ServiceContainer $c) {
         return new ReRunner\PassthruReRunner($c->get('process.phpexecutablefinder'));
     });
     $container->setShared('process.phpexecutablefinder', function () {
         return new PhpExecutableFinder();
     });
 }
 private function setXmlElementGenerators(ServiceContainer $container)
 {
     $container->setShared('xml_generator.generators.config.element.block', function () {
         return new BlockElement();
     });
     $container->setShared('xml_generator.generators.config.element.helper', function ($c) {
         return new HelperElement();
     });
     $container->setShared('xml_generator.generators.config.element.controller', function ($c) {
         return new ControllerElement();
     });
     $container->setShared('xml_generator.generators.config.element.model', function ($c) {
         return new ModelElement();
     });
     $container->setShared('xml_generator.generators.config.element.resource_model', function ($c) {
         return new ResourceModelElement();
     });
 }
 /**
  * @param ServiceContainer $container
  */
 protected function setupRunner(ServiceContainer $container)
 {
     $container->setShared('runner.suite', function ($c) {
         return new Runner\SuiteRunner($c->get('event_dispatcher'), $c->get('runner.specification'));
     });
     $container->setShared('runner.specification', function ($c) {
         return new Runner\SpecificationRunner($c->get('event_dispatcher'), $c->get('runner.example'));
     });
     $container->setShared('runner.example', function ($c) {
         $runner = new Runner\ExampleRunner($c->get('event_dispatcher'), $c->get('formatter.presenter'));
         array_map(array($runner, 'registerMaintainer'), $c->getByPrefix('runner.maintainers'));
         return $runner;
     });
     $container->set('runner.maintainers.errors', function ($c) {
         return new Runner\Maintainer\ErrorMaintainer($c->getParam('runner.maintainers.errors.level', E_ALL ^ E_STRICT));
     });
     $container->set('runner.maintainers.collaborators', function ($c) {
         return new Runner\Maintainer\CollaboratorsMaintainer($c->get('unwrapper'));
     });
     $container->set('runner.maintainers.let_letgo', function ($c) {
         return new Runner\Maintainer\LetAndLetgoMaintainer();
     });
     $container->set('runner.maintainers.matchers', function ($c) {
         return new Runner\Maintainer\MatchersMaintainer($c->get('formatter.presenter'), $c->get('unwrapper'));
     });
     $container->set('runner.maintainers.subject', function ($c) {
         return new Runner\Maintainer\SubjectMaintainer($c->get('formatter.presenter'), $c->get('unwrapper'), $c->get('event_dispatcher'));
     });
     $container->setShared('unwrapper', function ($c) {
         return new Wrapper\Unwrapper();
     });
 }
Exemple #24
0
 /**
  * @param ServiceContainer $container
  */
 private function assembleHtmlPresenter(ServiceContainer $container)
 {
     $container->setShared('formatter.presenter.html', function (ServiceContainer $c) {
         new SimplePresenter($c->get('formatter.presenter.value_presenter'), new SimpleExceptionPresenter($c->get('formatter.presenter.differ'), $c->get('formatter.presenter.html.exception_element_presenter'), new CallArgumentsPresenter($c->get('formatter.presenter.differ')), $c->get('formatter.presenter.html.exception.phpspec')));
     });
     $container->setShared('formatter.presenter.html.exception_element_presenter', function (ServiceContainer $c) {
         return new SimpleExceptionElementPresenter($c->get('formatter.presenter.value.exception_type_presenter'), $c->get('formatter.presenter.value_presenter'));
     });
     $container->setShared('formatter.presenter.html.exception.phpspec', function () {
         return new HtmlPhpSpecExceptionPresenter();
     });
 }
 public function load(ServiceContainer $container)
 {
     $container->setShared('event_dispatcher.listeners.environment', function ($container) {
         return new ServerEnvListener($container->getParam('server_env'));
     });
 }
 private function setFilesystem(ServiceContainer $container)
 {
     $container->setShared('filesystem', function () {
         return new Filesystem();
     });
 }
 /**
  * {@inheritDoc}
  */
 public function load(ServiceContainer $container)
 {
     $container->setShared('code_coverage.filter', function () {
         return new \PHP_CodeCoverage_Filter();
     });
     $container->setShared('code_coverage', function ($container) {
         return new \PHP_CodeCoverage(null, $container->get('code_coverage.filter'));
     });
     $container->setShared('code_coverage.options', function ($container) {
         $options = $container->getParam('code_coverage');
         if (!isset($options['format'])) {
             $options['format'] = array('html');
         } elseif (!is_array($options['format'])) {
             $options['format'] = (array) $options['format'];
         }
         if (isset($options['output'])) {
             if (!is_array($options['output']) && count($options['format']) == 1) {
                 $format = $options['format'][0];
                 $options['output'] = array($format => $options['output']);
             }
         }
         if (!isset($options['show_uncovered_files'])) {
             $options['show_uncovered_files'] = true;
         }
         if (!isset($options['lower_upper_bound'])) {
             $options['lower_upper_bound'] = 35;
         }
         if (!isset($options['high_lower_bound'])) {
             $options['high_lower_bound'] = 70;
         }
         return $options;
     });
     $container->setShared('code_coverage.reports', function ($container) {
         $options = $container->get('code_coverage.options');
         $reports = array();
         foreach ($options['format'] as $format) {
             switch ($format) {
                 case 'clover':
                     $reports['clover'] = new \PHP_CodeCoverage_Report_Clover();
                     break;
                 case 'php':
                     $reports['php'] = new \PHP_CodeCoverage_Report_PHP();
                     break;
                 case 'text':
                     $reports['text'] = new \PHP_CodeCoverage_Report_Text($options['lower_upper_bound'], $options['high_lower_bound'], $options['show_uncovered_files'], false);
                     break;
                 case 'xml':
                     $reports['xml'] = new \PHP_CodeCoverage_Report_XML();
                     break;
                 case 'crap4j':
                     $reports['crap4j'] = new \PHP_CodeCoverage_Report_Crap4j();
                     break;
                 case 'html':
                     $reports['html'] = new \PHP_CodeCoverage_Report_HTML();
                     break;
             }
         }
         $container->setParam('code_coverage', $options);
         return $reports;
     });
     $container->setShared('event_dispatcher.listeners.code_coverage', function ($container) {
         $listener = new CodeCoverageListener($container->get('code_coverage'), $container->get('code_coverage.reports'));
         $listener->setIO($container->get('console.io'));
         $listener->setOptions($container->getParam('code_coverage', array()));
         return $listener;
     });
 }
 public function load(ServiceContainer $container, array $params = [])
 {
     $container->setShared('runner.maintainers.iterator', function ($c) {
         return new Maintainer($c->get('unwrapper'));
     });
 }
 /**
  * @param ServiceContainer $container
  */
 private function setupShutdown(ServiceContainer $container)
 {
     $container->setShared('process.shutdown', function () {
         return new Shutdown();
     });
 }
 function it_registers_the_lumen_listener(ServiceContainer $container)
 {
     $container->setShared('event_dispatcher.listeners.lumen', Argument::type('Closure'))->shouldBeCalled();
     $this->load($container);
 }