diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..659065f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor +/bin +composer.lock diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..0ab8658 --- /dev/null +++ b/.php_cs @@ -0,0 +1,21 @@ +in(__DIR__) + ->exclude('vendor') +; + +return Symfony\CS\Config\Config::create() + ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) + ->fixers([ + 'align_double_arrow', + 'align_equals', + 'concat_with_spaces', + 'logical_not_operators_with_spaces', + 'long_array_syntax', + 'newline_after_open_tag', + 'ordered_use', + 'phpdoc_order', + ]) + ->finder($finder) +; diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3bade82 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: php + +php: + - 5.5 + - 5.6 + - 7 + +env: + - COMPOSER_PREFER=--prefer-lowest + - COMPOSER_PREFER=--prefer-stable + +before_script: + - phpenv config-rm xdebug.ini + - composer update --dev $COMPOSER_PREFER + +script: + - bin/symfony-integration-checker check -vvv + - bin/php-cs-fixer --diff --dry-run -v fix diff --git a/README.md b/README.md new file mode 100644 index 0000000..c828769 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +#SYMFONY Integration Checker + + diff --git a/bin/symfony-integration-checker b/bin/symfony-integration-checker new file mode 100755 index 0000000..076b81d --- /dev/null +++ b/bin/symfony-integration-checker @@ -0,0 +1,30 @@ +#!/usr/bin/env php +run(); diff --git a/checker_bootstrap.php b/checker_bootstrap.php new file mode 100644 index 0000000..0c8fcf9 --- /dev/null +++ b/checker_bootstrap.php @@ -0,0 +1,33 @@ + array( + 'translator' => array( + 'enabled' => true, + ), + ), +); + +$test = function (KernelInterface $kernel) { + if (false === $kernel->getContainer()->get('translator') instanceof TranslatorInterface) { + throw new \Exception('Oups, there is a problem !'); + } +}; + +return function (ConfigurableKernel $kernel) use ($config, $test) { + $container = new ContainerBuilder(); + $container->setParameter('kernel.secret', md5(time())); + + $kernel + ->setContainerBuilder($container) + ->setConfig($config) + ->addBundle(new FrameworkBundle()) + ->afterBoot($test) + ; +}; diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..24f4d38 --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "pedrotroller/symfony-integration-checker", + "authors": [ + { + "name": "Pierre PLAZANET", + "email": "plazanet.pierre@gmail.com" + } + ], + "require": { + "symfony/config": "~2.3|~3.0", + "symfony/dependency-injection": "~2.3|~3.0", + "symfony/http-kernel": "~2.3|~3.0" + }, + "require-dev": { + "fabpot/php-cs-fixer": "~1.11.0", + "symfony/framework-bundle": "~2.3|~3.0" + }, + "autoload": { + "psr-0": { "Pedrotroller\\Symfony\\IntegrationChecker": "src/" } + }, + "config": { + "bin-dir": "bin" + }, + "bin": [ + "bin/symfony-integration-checker" + ] +} diff --git a/src/Pedrotroller/Symfony/IntegrationChecker/Application.php b/src/Pedrotroller/Symfony/IntegrationChecker/Application.php new file mode 100644 index 0000000..9d290fc --- /dev/null +++ b/src/Pedrotroller/Symfony/IntegrationChecker/Application.php @@ -0,0 +1,37 @@ +add(new CheckCommand()); + + $this->configureIO($input, $output); + + parent::run($input, $output); + } + + /** + * {@inheritdoc} + */ + protected function getDefaultHelperSet() + { + return new HelperSet(array()); + } +} diff --git a/src/Pedrotroller/Symfony/IntegrationChecker/Command/CheckCommand.php b/src/Pedrotroller/Symfony/IntegrationChecker/Command/CheckCommand.php new file mode 100644 index 0000000..dfb3e13 --- /dev/null +++ b/src/Pedrotroller/Symfony/IntegrationChecker/Command/CheckCommand.php @@ -0,0 +1,71 @@ +setName('check') + ->addArgument('bootstrap_file', InputArgument::OPTIONAL, 'The kernel initialisation file.', $this->getDefaultBootstrapFilename()) + ->addOption('env', 'e', InputOption::VALUE_REQUIRED, 'Symfony environement', 'prod') + ; + } + + /** + * {@inheritdoc} + */ + public function run(InputInterface $input, OutputInterface $output) + { + $file = $this->getDefaultBootstrapFilename(); + $env = 'prod'; + + if (true === $input->hasOption('env')) { + $env = $input->getOption('env'); + } + + if (true === $input->hasArgument('bootstrap_file')) { + $file = $input->getArgument('bootstrap_file'); + } + + if (false === file_exists($file)) { + throw new \Exception(sprintf('Bootstrap file "%s" not found', $file)); + } + + $kernel = new ConfigurableKernel($env, true); + $callback = require $file; + + $callback($kernel); + + $output->writeln('Kernel builded'); + + $kernel->boot(); + + $output->writeln('Kernel booted'); + + foreach ($kernel->getAfterBootCallables() as $callable) { + $callable($kernel); + } + + $output->writeln('Symfony integration succeeded'); + } + + /** + * @return string + */ + private function getDefaultBootstrapFilename() + { + return sprintf('%s/checker_bootstrap.php', getcwd()); + } +} diff --git a/src/Pedrotroller/Symfony/IntegrationChecker/ConfigurableKernel.php b/src/Pedrotroller/Symfony/IntegrationChecker/ConfigurableKernel.php new file mode 100644 index 0000000..f9b0ff6 --- /dev/null +++ b/src/Pedrotroller/Symfony/IntegrationChecker/ConfigurableKernel.php @@ -0,0 +1,132 @@ +registeredBundles[] = $bundle; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function registerBundles() + { + return $this->registeredBundles; + } + + /** + * {@inheritdoc} + */ + public function registerContainerConfiguration(LoaderInterface $loader) + { + return $this->getContainerBuilder(); + } + + /** + * @param ContainerBuilder $containerBuilder + * + * @return ConfigurableKernel + */ + public function setContainerBuilder(ContainerBuilder $containerBuilder) + { + $this->containerBuilder = $containerBuilder; + + return $this; + } + + /** + * @param callable $callable + * + * @return ConfigurableKernel + */ + public function afterBoot(callable $callable) + { + $this->afterBoot[] = $callable; + + return $this; + } + + /** + * @return callable[] + */ + public function getAfterBootCallables() + { + return $this->afterBoot; + } + + /** + * @param array $config + * + * @return ConfigurableKernel + */ + public function setConfig(array $config) + { + $this->config = $config; + + return $this; + } + + /** + * {@inheritdoc} + */ + protected function getContainerBuilder() + { + if (null === $this->containerBuilder) { + $this->containerBuilder = parent::getContainerBuilder(); + } else { + $this->containerBuilder->merge(parent::getContainerBuilder()); + } + + foreach ($this->config as $extension => $config) { + $this->containerBuilder->prependExtensionConfig($extension, $config); + } + + return $this->containerBuilder; + } +}