Skip to content

Commit

Permalink
Fix config, add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Jun 13, 2016
1 parent 80d5799 commit 5a89e88
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 13 deletions.
File renamed without changes.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
<?php

use PedroTroller\Symfony\IntegrationChecker\ConfigurableKernel;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Translation\TranslatorInterface;

$config = array(
'framework' => 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)
;
};
```
2 changes: 1 addition & 1 deletion bin/symfony-integration-checker
Original file line number Diff line number Diff line change
Expand Up @@ -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();
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Pedrotroller\Symfony\IntegrationChecker;
namespace PedroTroller\Symfony\IntegrationChecker;

use Pedrotroller\Symfony\IntegrationChecker\Command\CheckCommand;
use PedroTroller\Symfony\IntegrationChecker\Command\CheckCommand;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\ArgvInput;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Pedrotroller\Symfony\IntegrationChecker\Command;
namespace PedroTroller\Symfony\IntegrationChecker\Command;

use Pedrotroller\Symfony\IntegrationChecker\ConfigurableKernel;
use PedroTroller\Symfony\IntegrationChecker\ConfigurableKernel;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -11,6 +11,8 @@

class CheckCommand extends Command
{
const DEFAULT_ROOT = '/dev/shm';

/**
* {@inheritdoc}
*/
Expand All @@ -19,6 +21,7 @@ protected function configure()
$this
->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')
;
}
Expand All @@ -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);
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Pedrotroller\Symfony\IntegrationChecker;
namespace PedroTroller\Symfony\IntegrationChecker;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -24,20 +24,37 @@ class ConfigurableKernel extends Kernel
*/
private $afterBoot = array();

/**
* @var string
*/
private $rootDirectory;

/**
* @param string $rootDirectory
*
* @return ConfigurableKernel
*/
public function setRootDirectory($rootDirectory)
{
$this->rootDirectory = $rootDirectory;

return $this;
}

/**
* {@inheritdoc}
*/
public function getCacheDir()
{
return sys_get_temp_dir();
return rtrim($this->rootDirectory, '/') . '/cache';
}

/**
* {@inheritdoc}
*/
public function getLogDir()
{
return sys_get_temp_dir();
return rtrim($this->rootDirectory, '/') . '/logs';
}

/**
Expand Down

0 comments on commit 5a89e88

Please sign in to comment.