diff --git a/checker_bootstrap.php b/.symfony_checker similarity index 100% rename from checker_bootstrap.php rename to .symfony_checker diff --git a/.travis.yml b/.travis.yml index 3bade82..d0d05b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,5 +14,4 @@ before_script: - composer update --dev $COMPOSER_PREFER script: - - bin/symfony-integration-checker check -vvv - - bin/php-cs-fixer --diff --dry-run -v fix + - make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e6e0b20 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +test: + bin/phpspec run -fpretty + bin/symfony-integration-checker check -vvv + bin/php-cs-fixer --diff --dry-run -v fix + +fix: + bin/php-cs-fixer fix -vvv diff --git a/README.md b/README.md index c828769..8b55b37 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,74 @@ #SYMFONY Integration Checker +============================ +## Installation +```bash +$ composer require pedrotroller/symfony-integration-checker --dev ~1.0.0 +``` + +## Usage + +You just have to create a `.symfony_checker`. This script should return a callback. This callback will have an instance of `PedroTroller\Symfony\IntegrationChecker\ConfigurableKernel` as parameter. + +```php +use PedroTroller\Symfony\IntegrationChecker\ConfigurableKernel; + +return function (ConfigurableKernel $kernel) { + // Your configuration +}; +``` + +## Launch the checker + +```bash +$ ./bin/symfony-integration-checker check +``` + +## Available kernel customization + +`$kernel->addBundle(BundleInterface $bundle)`: you can dynamically inject bundles into your kernel. + +`$kernel->setConfig(array $config)`: inject a configuration. + +`$kernel->setContainerBuilder(ContainerBuilder $container)`: inject your own container. + +`$kernel->afterBoot(callable $callable)`: inject a callable. This callable will be executed after the kernel boot. + +## Example + +```php + 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/bin/symfony-integration-checker b/bin/symfony-integration-checker index 076b81d..be7e81d 100755 --- a/bin/symfony-integration-checker +++ b/bin/symfony-integration-checker @@ -26,5 +26,5 @@ if (false === $loaded) { throw new \Exception('Can\'t find autoload'); } -$application = new Pedrotroller\Symfony\IntegrationChecker\Application; +$application = new PedroTroller\Symfony\IntegrationChecker\Application; $application->run(); diff --git a/composer.json b/composer.json index 24f4d38..377c05c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,7 @@ { "name": "pedrotroller/symfony-integration-checker", + "description": "Assert that your bundle integration with symfony is still working.", + "license": "MIT", "authors": [ { "name": "Pierre PLAZANET", @@ -13,14 +15,20 @@ }, "require-dev": { "fabpot/php-cs-fixer": "~1.11.0", + "phpspec/phpspec": "^2.5", "symfony/framework-bundle": "~2.3|~3.0" }, "autoload": { - "psr-0": { "Pedrotroller\\Symfony\\IntegrationChecker": "src/" } + "psr-4": { "PedroTroller\\Symfony\\IntegrationChecker\\": "src/PedroTroller/Symfony/IntegrationChecker" } }, "config": { "bin-dir": "bin" }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "bin": [ "bin/symfony-integration-checker" ] diff --git a/src/Pedrotroller/Symfony/IntegrationChecker/Application.php b/src/PedroTroller/Symfony/IntegrationChecker/Application.php similarity index 88% rename from src/Pedrotroller/Symfony/IntegrationChecker/Application.php rename to src/PedroTroller/Symfony/IntegrationChecker/Application.php index 9d290fc..343cd61 100644 --- a/src/Pedrotroller/Symfony/IntegrationChecker/Application.php +++ b/src/PedroTroller/Symfony/IntegrationChecker/Application.php @@ -1,8 +1,8 @@ setName('check') ->addArgument('bootstrap_file', InputArgument::OPTIONAL, 'The kernel initialisation file.', $this->getDefaultBootstrapFilename()) + ->addOption('root_directory', 'd', InputOption::VALUE_OPTIONAL, 'Cache/Logs directory', self::DEFAULT_ROOT) ->addOption('env', 'e', InputOption::VALUE_REQUIRED, 'Symfony environement', 'prod') ; } @@ -43,7 +46,9 @@ public function run(InputInterface $input, OutputInterface $output) throw new \Exception(sprintf('Bootstrap file "%s" not found', $file)); } - $kernel = new ConfigurableKernel($env, true); + $kernel = new ConfigurableKernel($env, true); + $kernel->setRootDirectory($input->hasOption('root_directory') ? $input->getOption('root_directory') : self::DEFAULT_ROOT); + $callback = require $file; $callback($kernel); @@ -66,6 +71,6 @@ public function run(InputInterface $input, OutputInterface $output) */ private function getDefaultBootstrapFilename() { - return sprintf('%s/checker_bootstrap.php', getcwd()); + return sprintf('%s/.symfony_checker', getcwd()); } } diff --git a/src/Pedrotroller/Symfony/IntegrationChecker/ConfigurableKernel.php b/src/PedroTroller/Symfony/IntegrationChecker/ConfigurableKernel.php similarity index 84% rename from src/Pedrotroller/Symfony/IntegrationChecker/ConfigurableKernel.php rename to src/PedroTroller/Symfony/IntegrationChecker/ConfigurableKernel.php index 24ba58c..049c8f5 100644 --- a/src/Pedrotroller/Symfony/IntegrationChecker/ConfigurableKernel.php +++ b/src/PedroTroller/Symfony/IntegrationChecker/ConfigurableKernel.php @@ -1,6 +1,6 @@ rootDirectory = $rootDirectory; + + return $this; + } + /** * {@inheritdoc} */ public function getCacheDir() { - return sys_get_temp_dir(); + return rtrim($this->rootDirectory, '/') . '/cache'; } /** @@ -37,7 +54,7 @@ public function getCacheDir() */ public function getLogDir() { - return sys_get_temp_dir(); + return rtrim($this->rootDirectory, '/') . '/logs'; } /**