/**
  * Add a formatter to the service container
  *
  * @param ServiceContainer $container
  * @param string           $name
  * @param string           $class
  */
 protected function addFormatter(ServiceContainer $container, $name, $class)
 {
     $container->set('formatter.formatters.teamcity', function ($c) use($class) {
         /** @var ServiceContainer $c */
         return new $class($c->get('formatter.presenter'), $c->get('console.io'), $c->get('event_dispatcher.listeners.stats'));
     });
 }
 /**
  * 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'));
     });
 }
 /**
  * @param ServiceContainer $container
  */
 public function build(ServiceContainer $container)
 {
     $assembler = $this;
     $container->addConfigurator(function ($c) use($assembler) {
         $config = $c->getParam('mage_locator', array('main' => ''));
         $srcNS = $assembler->getNamespace($config);
         $specPrefix = $assembler->getSpecPrefix($config);
         $srcPath = $assembler->getSrcPath($config);
         $specPath = $assembler->getSpecPath($config);
         $codePool = $assembler->getCodePool($config);
         $filesystem = $c->get('filesystem');
         if (!$filesystem->isDirectory($srcPath)) {
             $filesystem->makeDirectory($srcPath);
         }
         if (!$filesystem->isDirectory($specPath)) {
             $filesystem->makeDirectory($specPath);
         }
         $c->setShared('locator.locators.model_locator', function ($c) use($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool) {
             return new ModelLocator($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool);
         });
         $c->setShared('locator.locators.resource_model_locator', function ($c) use($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool) {
             return new ResourceModelLocator($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool);
         });
         $c->setShared('locator.locators.block_locator', function ($c) use($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool) {
             return new BlockLocator($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool);
         });
         $c->setShared('locator.locators.helper_locator', function ($c) use($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool) {
             return new HelperLocator($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool);
         });
         $c->setShared('locator.locators.controller_locator', function ($c) use($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool) {
             return new ControllerLocator($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool);
         });
     });
 }
 /**
  * @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'));
 }
 function it_should_use_singular_output()
 {
     $container = new ServiceContainer();
     $container->setParam('code_coverage', array('output' => 'test', 'format' => 'foo'));
     $this->load($container);
     $options = $container->get('code_coverage.options');
     expect($options['output'])->toBe(array('foo' => 'test'));
 }
Example #6
0
 /**
  * {@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();
     });
 }
 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'));
     });
 }
 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();
     });
 }
 /**
  * @return PhpGuardExtension
  */
 private function getExtension()
 {
     $runner = new \PhpGuard\Application\Bridge\CodeCoverage\CodeCoverageSession();
     $container = new ServiceContainer();
     $container->set('coverage.session', $runner);
     $extension = new PhpGuardExtension();
     $extension->load($container);
     return $extension;
 }
 /**
  * @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();
     });
 }
 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'));
     });
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->set('matchers.rest_view', function (ServiceContainer $c) {
         /** @var PresenterInterface $presenter */
         $presenter = $c->get('formatter.presenter');
         $matcher = new SimpleFactory();
         return new RestViewMatcher($presenter, $matcher);
     });
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->set('runner.maintainers.configuration_loaded_extensions', function (ServiceContainer $c) {
         $config = $c->getParam('matchers', []);
         $presenter = $c->get('formatter.presenter');
         $instances = $this->createInstances($config);
         $matchers = $this->resolveMatchers($instances, $presenter);
         return new MatchersLoaderMaintainer($matchers);
     });
 }
Example #14
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);
 }
 /**
  * @param ServiceContainer $container
  */
 public function load(ServiceContainer $container)
 {
     $container->set('code_generator.generators.method.classidentifier', function ($c) {
         return new ClassIdentifier();
     });
     $container->set('code_generator.generators.method.argumentbuilder', function ($c) {
         return new StringBuilder($c->get('code_generator.generators.method.classidentifier'));
     });
     $container->set('code_generator.generators.method', function ($c) {
         return new TypeHintedMethodGenerator($c->get('console.io'), $c->get('code_generator.templates'), null, $c->get('code_generator.generators.method.argumentbuilder'));
     });
 }
Example #16
0
 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);
 }
 /**
  * Loads matchers into PHPSpec service container
  *
  * @param ServiceContainer $container
  * @param array $params
  */
 public function load(ServiceContainer $container, array $params)
 {
     $container->define('ecomdev.matcher.file', function () {
         return $this->createFileMatcher();
     }, ['matchers']);
     $container->define('ecomdev.matcher.file_content', function () {
         return $this->createFileContentMatcher();
     }, ['matchers']);
     $container->define('ecomdev.matcher.directory', function () {
         return $this->createDirectoryMatcher();
     }, ['matchers']);
 }
 function let(SpecificationNode $specificationNode, ExampleEvent $exampleEvent, ServiceContainer $container, CodeCoverageSession $coverageSession)
 {
     $r = new \ReflectionClass(__CLASS__);
     $specificationNode->getClassReflection()->willReturn($r);
     $specificationNode->getTitle()->willReturn('Specification');
     $exampleEvent->getSpecification()->willReturn($specificationNode);
     $exampleEvent->getTitle()->willReturn('it should do something');
     $this->cwd = getcwd();
     chdir(sys_get_temp_dir());
     $container->get('coverage.session')->willReturn($coverageSession);
     $this->setCoverageRunner($coverageSession);
     $this->load($container);
 }
Example #19
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $this->container->set('console.input', $input);
     $this->container->set('console.output', $output);
     $this->container->set('console.helper.dialog', $this->getHelperSet()->get('dialog'));
     $assembler = new ContainerAssembler();
     $assembler->build($this->container);
     $this->loadConfigurationFile($input, $this->container);
     foreach ($this->container->getByPrefix('console.commands') as $command) {
         $this->add($command);
     }
     return parent::doRun($input, $output);
 }
Example #20
0
 /**
  * set global fuel setting
  *  $_SERVER[
  *   [doc_root] => ../../
  *   [app_path] => fuel/app
  *   [core_path] => fuel/core
  *   [package_path] => fuel/packages
  *   [vendor_path] => fuel/vendor
  *   [FUEL_ENV] => test
  *  ]
  * and
  * load bootstrap;
  * @param ServiceContainer $container
  */
 protected function loadPhpunitConfiguration(ServiceContainer $container)
 {
     try {
         $file = $container->getParam('phpunit.xml', self::DEFAULTPATH_PHPUNITXML);
         $config = PHPUnit_Util_Configuration::getInstance($file);
         $config->handlePHPConfiguration();
         $configures = $config->getPHPUnitConfiguration();
         if (file_exists($configures['bootstrap'])) {
             include_once $configures['bootstrap'];
         }
     } catch (\Exception $e) {
         echo "can't find phpunit.xml\n";
     }
 }
Example #21
0
 /**
  * {@inheritdoc}
  *
  * @link https://github.com/phpspec/phpspec/blob/36c1e97d59630888fd022a542b1650ae5eab1f18/src/PhpSpec/Console/ContainerAssembler.php#L338
  */
 public function load(ServiceContainer $container)
 {
     $container->addConfigurator(function (ServiceContainer $c) {
         $resourceManager = $c->get('locator.resource_manager');
         $suites = $c->getParam('suites', array('main' => ''));
         foreach ($suites as $name => $suite) {
             $suite = is_array($suite) ? $suite : array('namespace' => $suite);
             $defaults = array('namespace' => '', 'spec_prefix' => 'spec', 'src_path' => 'src', 'spec_path' => '.', 'psr4_prefix' => null);
             $config = array_merge($defaults, $suite);
             $locator = new FQCNLocator($config['namespace'], $config['spec_prefix'], $config['src_path'], $config['spec_path'], null, $config['psr4_prefix']);
             $resourceManager->registerLocator($locator);
         }
     });
 }
 /**
  * {@inheritdoc}
  */
 public function load(ServiceContainer $container, array $params)
 {
     if (!$container instanceof IndexedServiceContainer) {
         throw new \InvalidArgumentException(sprintf('Container passed from PhpSpec must be an instance of "%s"', IndexedServiceContainer::class));
     }
     $container->define('pamil.matchers.generate', function (IndexedServiceContainer $c) {
         return new Matcher\GenerateMatcher($c->get('formatter.presenter'));
     }, ['matchers']);
     $container->define('pamil.matchers.generate_values', function (IndexedServiceContainer $c) {
         return new Matcher\GenerateValuesMatcher($c->get('formatter.presenter'));
     }, ['matchers']);
     $container->define('pamil.matchers.generate_keys', function (IndexedServiceContainer $c) {
         return new Matcher\GenerateKeysMatcher($c->get('formatter.presenter'));
     }, ['matchers']);
 }
 /**
  * {@inheritdoc}
  */
 public function load(ServiceContainer $container, array $params)
 {
     $container->define('laravel', function () use($params) {
         return new Laravel(isset($params['testing_environment']) ? $params['testing_environment'] : null, $this->getBootstrapPath(isset($params['framework_path']) ? $params['framework_path'] : null));
     });
     $container->define('runner.maintainers.laravel', function (ServiceContainer $c) {
         return new LaravelMaintainer($c->get('laravel'));
     }, ['runner.maintainers']);
     $container->define('runner.maintainers.presenter', function (ServiceContainer $c) {
         return new PresenterMaintainer($c->get('formatter.presenter'));
     }, ['runner.maintainers']);
     $container->define('event_dispatcher.listeners.laravel', function (ServiceContainer $c) {
         return new LaravelListener($c->get('laravel'));
     }, ['event_dispatcher.listeners']);
 }
 function it_adds_existing_matchers(ServiceContainer $container)
 {
     $container->define('ecomdev.matcher.file', Argument::that(function ($value) {
         $check = $value();
         return $check instanceof CheckMatcher && $check->supports('haveFile', null, ['file']) && $check->supports('beFile', null, ['file']) && $check->supports('haveFiles', null, ['file', 'file2']) && $check->supports('createFiles', null, ['file', 'file2']);
     }), ['matchers'])->shouldBeCalled();
     $container->define('ecomdev.matcher.file_content', Argument::that(function ($value) {
         $check = $value();
         return $check instanceof CheckMatcher && $check->supports('haveFileContent', null, ['file', 'content']);
     }), ['matchers'])->shouldBeCalled();
     $container->define('ecomdev.matcher.directory', Argument::that(function ($value) {
         $check = $value();
         return $check instanceof CheckMatcher && $check->supports('haveDirectory', null, ['directory']) && $check->supports('beDirectory', null, ['directory']) && $check->supports('haveDirectories', null, ['directory', 'directory2']) && $check->supports('createDirectories', null, ['directory', 'directory2']);
     }), ['matchers'])->shouldBeCalled();
     $this->load($container, []);
 }
Example #25
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('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'));
     });
 }
 /**
  * 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'));
     });
 }
 /**
  * @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 build(ServiceContainer $container)
 {
     $assembler = $this;
     $container->addConfigurator(function ($c) use($assembler) {
         $config = $c->getParam('wp_locator', array('main' => ''));
         $srcNS = $assembler->getNamespace($config);
         $specPrefix = $assembler->getSpecPrefix($config);
         $srcPath = $assembler->getSrcPath($config);
         $specPath = $assembler->getSpecPath($config);
         $filesystem = $c->get('filesystem');
         if (!$filesystem->isDirectory($srcPath)) {
             $filesystem->makeDirectory($srcPath);
         }
         if (!$filesystem->isDirectory($specPath)) {
             $filesystem->makeDirectory($specPath);
         }
         $c->setShared('locator.locators.wp_locator', function ($c) use($srcNS, $specPrefix, $srcPath, $specPath, $filesystem) {
             return new WpLocator($srcNS, $specPrefix, $srcPath, $specPath, $filesystem);
         });
     });
 }
 /**
  * Set up Locator services for each phpspec suite configured, which may have
  * different class filename extensions.
  *
  * @param ServiceContainer $container
  */
 private function setupLocators(ServiceContainer $container)
 {
     $container->addConfigurator(function ($c) {
         $suites = $c->getParam('suites');
         foreach ($suites as $suite => $config) {
             // Not keen on how we have to track these config directives...
             $srcPath = $this->configParamOrDefault('src_path', $config, 'src');
             $specPath = $this->configParamOrDefault('spec_path', $config, '.');
             $srcNamespace = $this->configParamOrDefault('namespace', $config, '');
             $specNamespacePrefix = $this->configParamOrDefault('spec_prefix', $config, 'spec');
             $psr4Prefix = $this->configParamOrDefault('psr4_prefix', $config, null);
             $extension = $this->configParamOrDefault('src_extension', $config, '.php');
             $c->setShared('locator.locators.rdm.class_locator_' . $suite, function ($c) use($srcNamespace, $specNamespacePrefix, $srcPath, $specPath, $psr4Prefix, $extension) {
                 $l = new SuffixablePSR0Locator($srcNamespace, $specNamespacePrefix, $srcPath, $specPath, null, $psr4Prefix, $extension);
                 return $l;
             });
         }
         $resourceManager = $c->get('locator.resource_manager');
         array_map(array($resourceManager, 'registerLocator'), $c->getByPrefix('locator.locators.rdm'));
     });
 }