Browse Source

Updating flint

Julio Montoya 11 years ago
parent
commit
b3c12600d0
37 changed files with 999 additions and 97 deletions
  1. 7 0
      vendor/flint/flint/.gitattributes
  2. 5 0
      vendor/flint/flint/.gitignore
  3. 11 0
      vendor/flint/flint/.travis.yml
  4. 38 24
      vendor/flint/flint/doc/index.rst
  5. 28 0
      vendor/flint/flint/phpunit.xml.dist
  6. 0 11
      vendor/flint/flint/src/Flint/Application.php
  7. 72 0
      vendor/flint/flint/src/Flint/Config/Loader/AbstractLoader.php
  8. 22 0
      vendor/flint/flint/src/Flint/Config/Loader/IniFileLoader.php
  9. 1 56
      vendor/flint/flint/src/Flint/Config/Loader/JsonFileLoader.php
  10. 28 0
      vendor/flint/flint/src/Flint/Config/Loader/YamlFileLoader.php
  11. 49 0
      vendor/flint/flint/src/Flint/Console/PimpleHelper.php
  12. 68 0
      vendor/flint/flint/src/Flint/Controller/Controller.php
  13. 2 3
      vendor/flint/flint/src/Flint/Controller/ControllerResolver.php
  14. 8 2
      vendor/flint/flint/src/Flint/Provider/ConfigServiceProvider.php
  15. 1 1
      vendor/flint/flint/src/Flint/Provider/FlintServiceProvider.php
  16. 68 0
      vendor/flint/flint/tests/Flint/Tests/ApplicationTest.php
  17. 83 0
      vendor/flint/flint/tests/Flint/Tests/Config/ConfiguratorTest.php
  18. 44 0
      vendor/flint/flint/tests/Flint/Tests/Config/Loader/IniFileLoaderTest.php
  19. 40 0
      vendor/flint/flint/tests/Flint/Tests/Config/Loader/JsonFileLoaderTest.php
  20. 44 0
      vendor/flint/flint/tests/Flint/Tests/Config/Loader/YamlFileLoaderTest.php
  21. 26 0
      vendor/flint/flint/tests/Flint/Tests/Config/Normalizer/ChainNormalizerTest.php
  22. 17 0
      vendor/flint/flint/tests/Flint/Tests/Config/Normalizer/EnvironmentNormalizerTest.php
  23. 46 0
      vendor/flint/flint/tests/Flint/Tests/Config/Normalizer/PimpleAwareNormalizerTest.php
  24. 19 0
      vendor/flint/flint/tests/Flint/Tests/Config/ResourceCollectionTest.php
  25. 21 0
      vendor/flint/flint/tests/Flint/Tests/Console/ApplicationTest.php
  26. 21 0
      vendor/flint/flint/tests/Flint/Tests/Console/PimpleHelperTest.php
  27. 49 0
      vendor/flint/flint/tests/Flint/Tests/Controller/ControllerResolverTest.php
  28. 3 0
      vendor/flint/flint/tests/Flint/Tests/Fixtures/base.json
  29. 2 0
      vendor/flint/flint/tests/Flint/Tests/Fixtures/config.ini
  30. 4 0
      vendor/flint/flint/tests/Flint/Tests/Fixtures/config.json
  31. 2 0
      vendor/flint/flint/tests/Flint/Tests/Fixtures/config.yml
  32. 5 0
      vendor/flint/flint/tests/Flint/Tests/Fixtures/inherit.ini
  33. 5 0
      vendor/flint/flint/tests/Flint/Tests/Fixtures/inherit.yml
  34. 28 0
      vendor/flint/flint/tests/Flint/Tests/PimpleAwareTest.php
  35. 30 0
      vendor/flint/flint/tests/Flint/Tests/Provider/ConfigServiceProviderTest.php
  36. 59 0
      vendor/flint/flint/tests/Flint/Tests/Provider/FlintServiceProviderTest.php
  37. 43 0
      vendor/flint/flint/tests/Flint/Tests/Provider/RoutingServiceProviderTest.php

+ 7 - 0
vendor/flint/flint/.gitattributes

@@ -0,0 +1,7 @@
+/docs               export-ignore
+/tests              export-ignore
+/phpunit.xml.dist   export-ignore
+/.jms.yml           export-ignore
+/.travis.yml        export-ignore
+/.gitignore         export-ignore
+/.gitattributes     export-ignore

+ 5 - 0
vendor/flint/flint/.gitignore

@@ -0,0 +1,5 @@
+vendor
+coverage
+docs/_build
+composer.lock
+phpunit.xml

+ 11 - 0
vendor/flint/flint/.travis.yml

@@ -0,0 +1,11 @@
+language: php
+
+php:
+    - 5.3
+    - 5.4
+    - 5.5
+
+before_script:
+    - "echo '{\"config\":{\"github-oauth\": {\"github.com\":\"fa354b2f030836334eac842f8fd69a03e353d247\"}}}' > ~/.composer/config.json"
+    - "composer install --dev"
+

+ 38 - 24
vendor/flint/flint/doc/index.rst

@@ -109,11 +109,9 @@ parameter will be used as to determaine if cache should be used or not.
     <?php
 
     // .. create a $app before this line
-    $app->inject(array(
-        'routing.options' => array(
-            'cache_dir' => '/my/cache/directory/routing',
-        ),
-    ));
+    $app['routing.options'] = array(
+        'cache_dir' => '/my/cache/directory/routing',
+    );
 
 Before it is possible to use the full power of caching it is needed to
 use configuration files because Silex will always call add routes via
@@ -125,9 +123,7 @@ baked right in.
     <?php
 
     // .. create $app
-    $app->inject(array(
-        'routing.resource' => 'config/routing.xml',
-    ));
+    $app['routing.resource'] = 'config/routing.xml';
 
 .. code-block:: xml
 
@@ -187,10 +183,9 @@ services to add paths for caching, logs or other directories.
 
     <?php
 
-    // .. create $app
-    $app->inject(array(
-        'twig.path' => $app['root_dir'] . '/views',
-    ));
+    $app = new Flint\Application(__DIR__, true);
+    $app['debug'] === true;
+    $app['root_dir'] === __DIR__;
 
 Custom Error Pages
 ------------------
@@ -229,25 +224,44 @@ To see what parameter the controller action takes look at the one
 provided by default. Normally it should not be overwritten as it already
 gives a lot of flexibilty with the template lookup.
 
-Injecting Configuration Parameters
-----------------------------------
 
-Some times it is more useful to inject an array of parameters instead of
-setting them on the application one-by-one. Flint have a method that
-does this. It does the same thing as the second parameter of Silex
-``register`` method.
+Pimple Console
+--------------
+
+Helper
+~~~~~~
+
+Flint have a helper that provides access to a pimple instance or in the case of Flint access to you application
+object.
 
 .. code-block:: php
 
     <?php
 
-    // .. $app
-    $app->inject(array(
-        'twig.paths' => '/my/path/to/views',
-    ));
+    class SomeCommand extends Command
+    {
+        public function execute(InputInterface $input, OutputInterface $output)
+        {
+            $pimple = $this->getHelperSet()->get('pimple');
+        }
+    }
 
-Pimple Console
---------------
+To register the helper do this.
+
+.. code-block:: php
+
+    <?php
+
+    $app = new Symfony\Component\Console\Application;
+    $app->getHelperSet()->set(new Flint\Console\PimpleHelper($pimple));
+
+
+Application
+~~~~~~~~~~~
+
+.. warning::
+    
+    This is deprecated and it is adviced to use ``Flint\Console\PimpleHelper`` instead.
 
 ``Flint\Console\Application`` is an extension of the base console
 application shipped with Symfony. It gives access to Pimple in commands.

+ 28 - 0
vendor/flint/flint/phpunit.xml.dist

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
+<phpunit
+    backupGlobals               = "false"
+    backupStaticAttributes      = "false"
+    colors                      = "true"
+    convertErrorsToExceptions   = "true"
+    convertNoticesToExceptions  = "true"
+    convertWarningsToExceptions = "true"
+    processIsolation            = "false"
+    stopOnFailure               = "false"
+    syntaxCheck                 = "false"
+    bootstrap                   = "vendor/autoload.php" >
+
+    <testsuites>
+        <testsuite name="Flint Test Suite">
+            <directory>./tests/Flint/Tests</directory>
+        </testsuite>
+    </testsuites>
+
+    <filter>
+        <whitelist>
+            <directory>./src</directory>
+        </whitelist>
+    </filter>
+
+</phpunit>

+ 0 - 11
vendor/flint/flint/src/Flint/Application.php

@@ -41,15 +41,4 @@ class Application extends \Silex\Application
     {
         $this['configurator']->configure($this, $resource);
     }
-
-    /**
-     * @deprecated
-     * @param array $parameters
-     */
-    public function inject(array $parameters)
-    {
-        foreach ($parameters as $k => $v) {
-            $this[$k] = $v;
-        }
-    }
 }

+ 72 - 0
vendor/flint/flint/src/Flint/Config/Loader/AbstractLoader.php

@@ -0,0 +1,72 @@
+<?php
+
+namespace Flint\Config\Loader;
+
+use Flint\Config\Normalizer\NormalizerInterface;
+use Flint\Config\ResourceCollection;
+use Symfony\Component\Config\FileLocatorInterface;
+use Symfony\Component\Config\Resource\FileResource;
+
+/**
+ * @package Flint
+ */
+abstract class AbstractLoader extends \Symfony\Component\Config\Loader\FileLoader {
+
+    protected $normalizer;
+    protected $resources;
+
+    /**
+     * @param NormalizerInterface  $normalizer
+     * @param FileLocatorInterface $locator
+     * @param ResourceCollection   $resources
+     */
+    public function __construct(
+        NormalizerInterface $normalizer,
+        FileLocatorInterface $locator,
+        ResourceCollection $resources
+    ) {
+        parent::__construct($locator);
+
+        $this->normalizer = $normalizer;
+        $this->resources = $resources;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function load($resource, $type = null)
+    {
+        $resource = $this->locator->locate($resource);
+
+        $this->resources->add(new FileResource($resource));
+
+        return $this->parse($this->read($resource), $resource);
+    }
+
+    /**
+     * @param  array  $parameters
+     * @param  string $file
+     * @return array
+     */
+    protected function parse(array $parameters, $file)
+    {
+        if (!isset($parameters['@import'])) {
+            return $parameters;
+        }
+
+        $import = $parameters['@import'];
+
+        unset($parameters['@import']);
+
+        $this->setCurrentDir(dirname($import));
+
+        return array_replace($this->import($import, null, false, $file), $parameters);
+    }
+
+    /**
+     * @param $resource
+     * @return array
+     */
+    abstract protected function read($resource);
+
+}

+ 22 - 0
vendor/flint/flint/src/Flint/Config/Loader/IniFileLoader.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace Flint\Config\Loader;
+
+/**
+ * @package Flint
+ */
+class IniFileLoader extends AbstractLoader
+{
+    protected function read($resource)
+    {
+        return parse_ini_string($this->normalizer->normalize(file_get_contents($resource)), true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function supports($resource, $type = null)
+    {
+        return is_string($resource) && 'ini' === pathinfo($resource, PATHINFO_EXTENSION);
+    }
+}

+ 1 - 56
vendor/flint/flint/src/Flint/Config/Loader/JsonFileLoader.php

@@ -2,66 +2,11 @@
 
 namespace Flint\Config\Loader;
 
-use Flint\Config\Normalizer\NormalizerInterface;
-use Flint\Config\ResourceCollection;
-use Symfony\Component\Config\FileLocatorInterface;
-use Symfony\Component\Config\Resource\FileResource;
-
 /**
  * @package Flint
  */
-class JsonFileLoader extends \Symfony\Component\Config\Loader\FileLoader
+class JsonFileLoader extends AbstractLoader
 {
-    protected $normalizer;
-    protected $resources;
-
-    /**
-     * @param NormalizerInterface  $normalizer
-     * @param FileLocatorInterface $locator
-     */
-    public function __construct(
-        NormalizerInterface $normalizer,
-        FileLocatorInterface $locator,
-        ResourceCollection $resources
-    ) {
-        parent::__construct($locator);
-
-        $this->normalizer = $normalizer;
-        $this->resources = $resources;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public function load($resource, $type = null)
-    {
-        $resource = $this->locator->locate($resource);
-
-        $this->resources->add(new FileResource($resource));
-
-        return $this->parse($this->read($resource), $resource);
-    }
-
-    /**
-     * @param  array  $parameters
-     * @param  string $file
-     * @return array
-     */
-    protected function parse(array $parameters, $file)
-    {
-        if (!isset($parameters['@import'])) {
-            return $parameters;
-        }
-
-        $import = $parameters['@import'];
-
-        unset($parameters['@import']);
-
-        $this->setCurrentDir(dirname($import));
-
-        return array_replace($this->import($import, null, false, $file), $parameters);
-    }
-
     protected function read($resource)
     {
         return json_decode($this->normalizer->normalize(file_get_contents($resource)), true);

+ 28 - 0
vendor/flint/flint/src/Flint/Config/Loader/YamlFileLoader.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace Flint\Config\Loader;
+
+use Symfony\Component\Yaml\Yaml;
+
+/**
+ * @package Flint
+ */
+class YamlFileLoader extends AbstractLoader
+{
+    /**
+     * @param  $resource
+     * @return array
+     */
+    protected function read($resource)
+    {
+        return Yaml::parse(file_get_contents($resource));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function supports($resource, $type = null)
+    {
+        return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION);
+    }
+}

+ 49 - 0
vendor/flint/flint/src/Flint/Console/PimpleHelper.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace Flint\Console;
+
+use Flint\PimpleAwareInterface;
+use Symfony\Component\Console\Helper\Helper;
+use Pimple;
+
+/**
+ * Provides access to a pimple instance.
+ *
+ * @package Flint
+ */
+class PimpleHelper extends Helper implements PimpleAwareInterface
+{
+    protected $pimple;
+
+    /**
+     * {@inheritDoc}
+     */
+    public function __construct(Pimple $pimple)
+    {
+        $this->setPimple($pimple);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function setPimple(Pimple $pimple = null)
+    {
+        $this->pimple = $pimple;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getPimple()
+    {
+        return $this->pimple;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getName()
+    {
+        return 'pimple';
+    }
+}

+ 68 - 0
vendor/flint/flint/src/Flint/Controller/Controller.php

@@ -55,6 +55,74 @@ abstract class Controller extends \Flint\PimpleAware
         return $this->pimple->abort($statusCode, $message, $headers);
     }
 
+    /**
+     * This will result in a 404 response code.
+     * 
+     * @param string $message
+     * @return Exception
+     */
+    protected function createNotFoundException($message = 'Not Found')
+    {
+        return $this->abort(404, $message);
+    }
+
+    /**
+     * @return Request
+     */
+    protected function getRequest()
+    {
+        return $this->get('request');
+    }
+
+    /**
+     * Get a user from the Security Context
+     *
+     * @throws \LogicException
+     * @return mixed
+     */
+    public function getUser()
+    {
+        if (!$this->has('security')) {
+            throw new \LogicException('The SecurityServiceProvider is not registered in your application.');
+        }
+
+        if (null === $token = $this->get('security')->getToken()) {
+            return null;
+        }
+
+        if (!is_object($user = $token->getUser())) {
+            return null;
+        }
+
+        return $user;
+    }
+
+    /**
+     * Creates and returns a Form instance from the type of the form.
+     *
+     * @param string|FormTypeInterface $type    The built type of the form
+     * @param mixed                    $data    The initial data for the form
+     * @param array                    $options Options for the form
+     *
+     * @return \Symfony\Component\Form\Form
+     */
+    public function createForm($type, $data = null, array $options = array())
+    {
+        return $this->get('form.factory')->create($type, $data, $options);
+    }
+
+    /**
+     * Creates and returns a form builder instance
+     *
+     * @param mixed $data    The initial data for the form
+     * @param array $options Options for the form
+     * @return \Symfony\Component\Form\FormBuilder
+     */
+    public function createFormBuilder($data = null, array $options = array())
+    {
+        return $this->get('form.factory')->createBuilder('form', $data, $options);
+    }
+
     /**
      * @param  string  $id
      * @return boolean

+ 2 - 3
vendor/flint/flint/src/Flint/Controller/ControllerResolver.php

@@ -2,14 +2,13 @@
 
 namespace Flint\Controller;
 
-use Flint\Application;
 use Flint\PimpleAwareInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
 
 /**
- * Injects the Application into the Controller if it implements the right interface
- * otherwise it delegates to the composed resolver.
+ * Injects a Pimple instance into the Controller if it implements
+ * the right interface otherwise it delegates to the wrapped resolver.
  *
  * @package Flint
  */

+ 8 - 2
vendor/flint/flint/src/Flint/Provider/ConfigServiceProvider.php

@@ -3,6 +3,8 @@
 namespace Flint\Provider;
 
 use Flint\Config\Configurator;
+use Flint\Config\Loader\IniFileLoader;
+use Flint\Config\Loader\YamlFileLoader;
 use Flint\Config\ResourceCollection;
 use Flint\Config\Loader\JsonFileLoader;
 use Flint\Config\Normalizer\ChainNormalizer;
@@ -48,9 +50,13 @@ class ConfigServiceProvider implements \Silex\ServiceProviderInterface
         });
 
         $app['config.loader_resolver'] = $app->share(function ($app) {
-            $loader = new JsonFileLoader($app['config.normalizer'], $app['config.locator'], $app['config.resource_collection']);
+            $loaders = array(
+                new JsonFileLoader($app['config.normalizer'], $app['config.locator'], $app['config.resource_collection']),
+                new IniFileLoader($app['config.normalizer'], $app['config.locator'], $app['config.resource_collection']),
+                new YamlFileLoader($app['config.normalizer'], $app['config.locator'], $app['config.resource_collection']),
+            );
 
-            return new LoaderResolver(array($loader));
+            return new LoaderResolver($loaders);
         });
 
         $app['configurator'] = $app->share(function (Application $app) {

+ 1 - 1
vendor/flint/flint/src/Flint/Provider/FlintServiceProvider.php

@@ -26,7 +26,7 @@ class FlintServiceProvider implements \Silex\ServiceProviderInterface
             return new ControllerResolver($resolver, $app);
         }));
 
-        $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function ($loader, $app) {
+        $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function ($loader) {
             $loader->addPath(__DIR__ . '/../Resources/views', 'Flint');
 
             return $loader;

+ 68 - 0
vendor/flint/flint/tests/Flint/Tests/ApplicationTest.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace Flint\Tests;
+
+use Flint\Application;
+
+class ApplicationTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->app = new Application(__DIR__, true);
+    }
+
+    public function testParametersCanBeSetFromConstructor()
+    {
+        $app = new Application(__DIR__, true, array(
+            'my_parameter' => 'my_parameter_value',
+        ));
+
+        $this->assertEquals('my_parameter_value', $app['my_parameter']);
+    }
+
+    public function testRootDirAndDebugIsSet()
+    {
+        $app = new Application('/my/root_dir', true);
+
+        $this->assertTrue($app['debug']);
+        $this->assertEquals('/my/root_dir', $app['root_dir']);
+    }
+
+    public function testConfigureWillLoadConfigFile()
+    {
+        $app = new Application('/my/root_dir', true);
+        $app['configurator'] = $this->getMockBuilder('Flint\Config\Configurator')
+            ->disableOriginalConstructor()->getMock();
+
+        $app['configurator']->expects($this->once())->method('configure')
+            ->with($this->equalTo($app), $this->equalTo('config.json'));
+
+        $app->configure('config.json');
+    }
+
+    /**
+     * @dataProvider serviceProvidersProvider
+     */
+    public function testProvidersAreRegistered($index, $providerClassName)
+    {
+        $mock = $this->getMockBuilder('Flint\Application')
+            ->setMethods(array('register'))
+            ->disableOriginalConstructor()->getMock();
+
+        $mock->expects($this->at($index))
+            ->method('register')
+            ->with($this->isInstanceOf($providerClassName));
+
+        call_user_func_array(array($mock, '__construct'), array(__DIR__, true));
+    }
+
+    public function serviceProvidersProvider()
+    {
+        return array(
+            array(0, 'Flint\Provider\ConfigServiceProvider'),
+            array(1, 'Flint\Provider\RoutingServiceProvider'),
+            array(2, 'Silex\Provider\TwigServiceProvider'),
+            array(3, 'Flint\Provider\FlintServiceProvider'),
+        );
+    }
+}

+ 83 - 0
vendor/flint/flint/tests/Flint/Tests/Config/ConfiguratorTest.php

@@ -0,0 +1,83 @@
+<?php
+
+namespace Flint\Tests\Config;
+
+use Flint\Config\Configurator;
+use Flint\Config\ResourceCollection;
+use Pimple;
+use Symfony\Component\Config\Loader\DelegatingLoader;
+use Symfony\Component\Config\Loader\LoaderResolver;
+
+class ConfiguratorTest extends \PHPUnit_Framework_TestCase
+{
+    const CACHE_CONTENT = <<<CONTENT
+<?php \$parameters = array (
+  'service_parameter' => 'hello',
+);
+CONTENT;
+
+    public function setUp()
+    {
+        $this->loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
+        $this->loader->expects($this->any())->method('supports')->will($this->returnValue(true));
+
+        $this->delegator = new DelegatingLoader(new LoaderResolver(array($this->loader)));
+        $this->cacheFile = "/var/tmp/1058386122.php";
+
+        $this->resources = new ResourceCollection;
+    }
+
+    public function tearDown()
+    {
+        @unlink($this->cacheFile);
+        @unlink($this->cacheDilr.  '.meta');
+    }
+
+    public function testItBuilds()
+    {
+        $this->loader->expects($this->once())->method('load')->with($this->equalTo('config.json'))
+            ->will($this->returnValue(array('service_parameter' => 'hello')));
+
+        $pimple = new Pimple;
+
+        $this->createConfigurator()->configure($pimple, 'config.json');
+
+        $this->assertEquals('hello', $pimple['service_parameter']);
+    }
+
+    public function testAFreshCacheSkipsLoader()
+    {
+        // Create a fresh cache
+        file_put_contents($this->cacheFile, static::CACHE_CONTENT);
+
+        $pimple = new Pimple;
+
+        $this->loader->expects($this->never())->method('load');
+
+        $this->createConfigurator(false)->configure($pimple, 'config.json');
+
+        $this->assertEquals('hello', $pimple['service_parameter']);
+    }
+
+    public function testStaleCacheWritesFile()
+    {
+        $this->loader->expects($this->once())->method('load')->with($this->equalTo('config.json'))->will($this->returnValue(array(
+            'service_parameter' => 'hello',
+        )));
+
+        $pimple = new Pimple;
+
+        $this->createConfigurator(false)->configure($pimple, 'config.json');
+
+        $this->assertEquals(file_get_contents($this->cacheFile), static::CACHE_CONTENT);
+    }
+
+    protected function createConfigurator($debug = true)
+    {
+        $configurator = new Configurator($this->delegator, $this->resources);
+        $configurator->setDebug($debug);
+        $configurator->setCacheDir('/var/tmp');
+
+        return $configurator;
+    }
+}

+ 44 - 0
vendor/flint/flint/tests/Flint/Tests/Config/Loader/IniFileLoaderTest.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace Flint\Tests\Config\Loader;
+
+use Flint\Config\ResourceCollection;
+use Flint\Config\Loader\IniFileLoader;
+use Symfony\Component\Config\FileLocator;
+
+class IniFileLoaderTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $paths = array(__DIR__ . '/../../Fixtures');
+
+        $normalizer = $this->getMock('Flint\Config\Normalizer\NormalizerInterface');
+        $normalizer->expects($this->any())->method('normalize')->will($this->returnCallback(function ($args) {
+            return $args;
+        }));
+
+        $this->loader = new IniFileLoader($normalizer, new FileLocator($paths), new ResourceCollection);
+    }
+
+    public function testLoads()
+    {
+        $this->assertEquals(array('doctrine' => array('driver' => 'mysql')), $this->loader->load('config.ini'));
+    }
+
+    public function testLoadsInheritedConfig()
+    {
+        $parameters = array(
+            'doctrine' => array('driver' => 'pdo_pgsql', 'port' => 8080),
+        );
+
+        $this->assertEquals($parameters, $this->loader->load('inherit.ini'));
+    }
+
+    public function testSupports()
+    {
+        $this->assertTrue($this->loader->supports('config.ini'));
+        $this->assertFalse($this->loader->supports('config.json'));
+        $this->assertFalse($this->loader->supports('config.xml'));
+        $this->assertFalse($this->loader->supports('config.php'));
+    }
+}

+ 40 - 0
vendor/flint/flint/tests/Flint/Tests/Config/Loader/JsonFileLoaderTest.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace Flint\Tests\Config\Loader;
+
+use Flint\Config\ResourceCollection;
+use Flint\Config\Loader\JsonFileLoader;
+use Symfony\Component\Config\FileLocator;
+
+class JsonFileLoaderTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $paths = array(__DIR__ . '/../../Fixtures');
+
+        $normalizer = $this->getMock('Flint\Config\Normalizer\NormalizerInterface');
+        $normalizer->expects($this->any())->method('normalize')->will($this->returnCallback(function ($args) {
+            return $args;
+        }));
+
+        $this->loader = new JsonFileLoader($normalizer, new FileLocator($paths), new ResourceCollection);
+    }
+
+    public function testItLoadsAsJsonFile()
+    {
+        $this->assertEquals(array('base_parameter' => 'hello'), $this->loader->load('base.json'));
+    }
+
+    public function testItLoadsInheritedJsonFiles()
+    {
+        $this->assertEquals(array('base_parameter' => 'hello', 'service_parameter' => 'hello'), $this->loader->load('config.json'));
+    }
+
+    public function testItSupportsJson()
+    {
+        $this->assertTrue($this->loader->supports('config.json'));
+        $this->assertFalse($this->loader->supports('config.ini'));
+        $this->assertFalse($this->loader->supports('config.xml'));
+        $this->assertFalse($this->loader->supports('config.php'));
+    }
+}

+ 44 - 0
vendor/flint/flint/tests/Flint/Tests/Config/Loader/YamlFileLoaderTest.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace Flint\Tests\Config\Loader;
+
+use Flint\Config\ResourceCollection;
+use Flint\Config\Loader\YamlFileLoader;
+use Symfony\Component\Config\FileLocator;
+
+class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $paths = array(__DIR__ . '/../../Fixtures');
+
+        $normalizer = $this->getMock('Flint\Config\Normalizer\NormalizerInterface');
+        $normalizer->expects($this->any())->method('normalize')->will($this->returnCallback(function ($args) {
+            return $args;
+        }));
+
+        $this->loader = new YamlFileLoader($normalizer, new FileLocator($paths), new ResourceCollection);
+    }
+
+    public function testLoads()
+    {
+        $this->assertEquals(array('doctrine' => array('driver' => 'mysql')), $this->loader->load('config.yml'));
+    }
+
+    public function testLoadsInheritedConfig()
+    {
+        $parameters = array(
+            'doctrine' => array('driver' => 'pdo_pgsql', 'port' => 8080),
+        );
+
+        $this->assertEquals($parameters, $this->loader->load('inherit.yml'));
+    }
+
+    public function testSupports()
+    {
+        $this->assertTrue($this->loader->supports('config.yml'));
+        $this->assertFalse($this->loader->supports('config.json'));
+        $this->assertFalse($this->loader->supports('config.xml'));
+        $this->assertFalse($this->loader->supports('config.php'));
+    }
+}

+ 26 - 0
vendor/flint/flint/tests/Flint/Tests/Config/Normalizer/ChainNormalizerTest.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace Flint\Tests\Config\Normalizer;
+
+use Flint\Config\Normalizer\ChainNormalizer;
+
+class ChainNormalizerTest extends \PHPUnit_Framework_TestCase
+{
+    public function testItNormalizesAChainOfNormalizers()
+    {
+        $normalizer = new ChainNormalizer;
+        $normalizer->add($this->createNormalizerMock('original content', 'first modified'));
+        $normalizer->add($this->createNormalizerMock('first modified', 'final content'));
+
+        $this->assertEquals('final content', $normalizer->normalize('original content'));
+    }
+
+    protected function createNormalizerMock($contents, $return)
+    {
+        $mock = $this->getMock('Flint\Config\Normalizer\NormalizerInterface');
+        $mock->expects($this->once())->method('normalize')->with($contents)
+            ->will($this->returnValue($return));
+
+        return $mock;
+    }
+}

+ 17 - 0
vendor/flint/flint/tests/Flint/Tests/Config/Normalizer/EnvironmentNormalizerTest.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace Flint\Tests\Config\Normalizer;
+
+use Flint\Config\Normalizer\EnvironmentNormalizer;
+
+class EnvironmentNormalizerTest extends \PHPUnit_Framework_TestCase
+{
+    public function testItReplacePlaceholders()
+    {
+        putenv('TEST_ENV=replaced');
+
+        $normalizer = new EnvironmentNormalizer;
+
+        $this->assertEquals('replaced', $normalizer->normalize('#TEST_ENV#'));
+    }
+}

+ 46 - 0
vendor/flint/flint/tests/Flint/Tests/Config/Normalizer/PimpleAwareNormalizerTest.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace Flint\Tests\Config\Normalizer;
+
+use Flint\Config\Normalizer\PimpleAwareNormalizer;
+
+class PimpleAwareNormalizerTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->pimple = new \Pimple;
+        $this->normalizer = new PimpleAwareNormalizer($this->pimple);
+    }
+
+    public function testItReplacesPlaceHolders()
+    {
+        $this->pimple['service_parameter'] = 'hello';
+
+        $this->assertEquals('hello', $this->normalizer->normalize('%service_parameter%'));
+        $this->assertEquals('%%hello', $this->normalizer->normalize('%%%service_parameter%'));
+        $this->assertEquals('%%service_parameter%', $this->normalizer->normalize('%%service_parameter%'));
+    }
+
+    public function testItThrowsExceptionWhenReplacementIsObject()
+    {
+        $this->setExpectedException('\RuntimeException', 'Unable to replace placeholder if its replacement is an object or resource.');
+
+        $this->pimple['replacement'] = new \stdClass;
+
+        $this->normalizer->normalize('%replacement%');
+    }
+
+    public function testItReplacesPhpValuesToReadables()
+    {
+
+        $this->pimple['null_value'] = null;
+        $this->pimple['false_value'] = false;
+        $this->pimple['true_value'] = true;
+        $this->pimple['float_value'] = 2.23;
+
+        $this->assertEquals('null', $this->normalizer->normalize('%null_value%'));
+        $this->assertEquals('false', $this->normalizer->normalize('%false_value%'));
+        $this->assertEquals('true', $this->normalizer->normalize('%true_value%'));
+        $this->assertEquals('2.23', $this->normalizer->normalize('%float_value%'));
+    }
+}

+ 19 - 0
vendor/flint/flint/tests/Flint/Tests/Config/ResourceCollectionTest.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace Flint\Tests\Config;
+
+use Flint\Config\ResourceCollection;
+
+class ResourceCollectionTest extends \PHPUnit_Framework_TestCase
+{
+    public function testCollectResources()
+    {
+        $resource = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
+        $resource1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
+
+        $collection = new ResourceCollection(array($resource));
+        $collection->add($resource1);
+
+        $this->assertSame(array($resource, $resource1), $collection->all());
+    }
+}

+ 21 - 0
vendor/flint/flint/tests/Flint/Tests/Console/ApplicationTest.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace Flint\Tests\Console;
+
+use Flint\Console\Application;
+
+class ApplicationTest extends \PHPUnit_Framework_TestCase
+{
+    public function testPimpleIsAccesible()
+    {
+        $pimple = new \Pimple();
+        $application = new Application($pimple);
+
+        $this->assertSame($pimple, $application->getPimple());
+    }
+
+    public function testApplicationIsPimpleAware()
+    {
+        $this->assertInstanceOf('Flint\PimpleAwareInterface', new Application(new \Pimple()));
+    }
+}

+ 21 - 0
vendor/flint/flint/tests/Flint/Tests/Console/PimpleHelperTest.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace Flint\Tests\Console;
+
+use Flint\Console\PimpleHelper;
+
+class PimpleHelperTest extends \PHPUnit_Framework_TestCase
+{
+    public function testPimpleIsAccesible()
+    {
+        $pimple = new \Pimple();
+        $application = new PimpleHelper($pimple);
+
+        $this->assertSame($pimple, $application->getPimple());
+    }
+
+    public function testPimpleHelperIsPimpleAware()
+    {
+        $this->assertInstanceOf('Flint\PimpleAwareInterface', new PimpleHelper(new \Pimple()));
+    }
+}

+ 49 - 0
vendor/flint/flint/tests/Flint/Tests/Controller/ControllerResolverTest.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace Flint\Tests\Controller;
+
+use Flint\Controller\ControllerResolver;
+
+class ControllerResolverTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->resolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface');
+    }
+
+    public function testPimpleIsInjectedWhenControllerIsPimpleAware()
+    {
+        $pimple = new \Pimple();
+        $resolver = new ControllerResolver($this->resolver, $pimple);
+        $controller = $this->getMock('Flint\PimpleAwareInterface');
+
+        $controller->expects($this->once())->method('setPimple')->with($this->equalTo($pimple));
+
+        $this->resolver->expects($this->any())->method('getController')->will($this->returnValue(array(
+            $controller,
+            'indexAction',
+        )));
+
+        $resolver->getController($this->getMock('Symfony\Component\HttpFoundation\Request'));
+    }
+
+    public function testPimpleIsNotInjectedWhenNotApplicable()
+    {
+        $controller = $this->getMock('Flint\PimpleAwareInterface');
+        $controller->expects($this->never())->method('setPimple');
+
+        $this->resolver->expects($this->any())->method('getController')->will($this->returnValue(null));
+
+        $resolver = new ControllerResolver($this->resolver, new \Pimple());
+        $resolver->getController($this->getMock('Symfony\Component\HttpFoundation\Request'));
+    }
+
+    public function testGetArgumentsIsDelegatedToWrappedResolver()
+    {
+        $resolver = new ControllerResolver($this->resolver, new \Pimple());
+
+        $this->resolver->expects($this->once())->method('getArguments');
+
+        $resolver->getArguments($this->getMock('Symfony\Component\HttpFoundation\Request'), array());
+    }
+}

+ 3 - 0
vendor/flint/flint/tests/Flint/Tests/Fixtures/base.json

@@ -0,0 +1,3 @@
+{
+    "base_parameter" : "hello"
+}

+ 2 - 0
vendor/flint/flint/tests/Flint/Tests/Fixtures/config.ini

@@ -0,0 +1,2 @@
+[doctrine]
+driver = "mysql"

+ 4 - 0
vendor/flint/flint/tests/Flint/Tests/Fixtures/config.json

@@ -0,0 +1,4 @@
+{
+    "@import" : "base.json",
+    "service_parameter" : "hello"
+}

+ 2 - 0
vendor/flint/flint/tests/Flint/Tests/Fixtures/config.yml

@@ -0,0 +1,2 @@
+doctrine:
+  driver: mysql

+ 5 - 0
vendor/flint/flint/tests/Flint/Tests/Fixtures/inherit.ini

@@ -0,0 +1,5 @@
+@import = "config.ini"
+
+[doctrine]
+driver = "pdo_pgsql"
+port = 8080

+ 5 - 0
vendor/flint/flint/tests/Flint/Tests/Fixtures/inherit.yml

@@ -0,0 +1,5 @@
+@import: config.yml
+
+doctrine:
+  driver: pdo_pgsql
+  port: 8080

+ 28 - 0
vendor/flint/flint/tests/Flint/Tests/PimpleAwareTest.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace Flint\Tests;
+
+class PimpleAwareTest extends \PHPUnit_Framework_TestCase
+{
+    public function testImplementesInterface()
+    {
+        $aware = $this->getMockForAbstractClass('Flint\PimpleAware');
+
+        $this->assertInstanceOf('Flint\PimpleAwareInterface', $aware);
+    }
+
+    public function testAppPropertyIsSet()
+    {
+        $refl = new \ReflectionProperty('Flint\PimpleAware', 'pimple');
+        $refl->setAccessible(true);
+
+        $mock = $this->getMockForAbstractClass('Flint\PimpleAware');
+
+        $this->assertInternalType('null', $refl->getValue($mock));
+
+        $pimple = new \Pimple();
+        $mock->setPimple($pimple);
+
+        $this->assertSame($pimple, $refl->getValue($mock));
+    }
+}

+ 30 - 0
vendor/flint/flint/tests/Flint/Tests/Provider/ConfigServiceProviderTest.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace Flint\Tests\Provider;
+
+use Flint\Application;
+use Flint\Provider\ConfigServiceProvider;
+
+class ConfigServiceProviderTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->application = new Application(__DIR__, true);
+        $this->provider = new ConfigServiceProvider;
+    }
+
+    public function testServicesAreRegistered()
+    {
+        $this->provider->register($this->application);
+
+        $this->assertInstanceOf('Symfony\Component\Config\FileLocator', $this->application['config.locator']);
+        $this->assertInternalType('array', $this->application['config.paths']);
+    }
+
+    public function testConfigPathsContainsRootConfigDirectory()
+    {
+        $this->provider->register($this->application);
+        $this->assertContains(__DIR__ . '/config', $this->application['config.paths']);
+        $this->assertContains(__DIR__, $this->application['config.paths']);
+    }
+}

+ 59 - 0
vendor/flint/flint/tests/Flint/Tests/Provider/FlintServiceProviderTest.php

@@ -0,0 +1,59 @@
+<?php
+
+namespace Flint\Tests\Provider;
+
+use Flint\Provider\FlintServiceProvider;
+use Flint\Application;
+
+class FlintServiceProviderTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->app = new Application(__DIR__, true);
+        $this->provider = new FlintServiceProvider;
+    }
+
+    public function testResolverIsOverridden()
+    {
+        $this->provider->register($this->app);
+
+        $this->assertInstanceOf('Flint\Controller\ControllerResolver', $this->app['resolver']);
+    }
+
+    public function testCustomExceptionController()
+    {
+        $this->provider->register($this->app);
+        $this->app['exception_controller'] = 'Acme\\Controller\\ExceptionController::showAction';
+
+        $listener = $this->app['exception_handler'];
+        $refl = new \ReflectionProperty($listener, 'controller');
+        $refl->setAccessible(true);
+
+        $this->assertEquals('Acme\\Controller\\ExceptionController::showAction', $refl->getValue($listener));
+    }
+
+    public function testExceptionHandlerIsOverrriden()
+    {
+        $this->provider->register($this->app);
+
+        $this->assertInstanceOf('Symfony\Component\HttpKernel\EventListener\ExceptionListener', $this->app['exception_handler']);
+    }
+
+    public function testTwigFileLoaderFlintNamespacePathIsAdded()
+    {
+        $refl = new \ReflectionClass('Flint\Provider\FlintServiceProvider');
+        $dir = dirname($refl->getFileName()) . '/../Resources/views';
+
+        $loader = $this->getMockBuilder('Twig_Loader_Filesystem')->disableOriginalConstructor()->getMock();
+        $loader->expects($this->once())->method('addPath')->with($this->equalTo($dir), $this->equalTo('Flint'));
+
+        $this->app['twig.loader.filesystem'] = $this->app->share(function () use ($loader) {
+            return $loader;
+        });
+
+        $provider = new FlintServiceProvider;
+        $provider->register($this->app);
+
+        $this->app['twig.loader.filesystem'];
+    }
+}

+ 43 - 0
vendor/flint/flint/tests/Flint/Tests/Provider/RoutingServiceProviderTest.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace Flint\Tests\Provider;
+
+use Flint\Provider\RoutingServiceProvider;
+use Flint\Application;
+
+class RoutingServiceProviderTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->app = new Application(__DIR__, true);
+        $this->provider = new RoutingServiceProvider;
+    }
+
+    public function testUrlMatcherAndGeneratorIsAliasOfRouter()
+    {
+        $this->provider->register($this->app);
+
+        $this->assertInstanceOf('Symfony\Component\Routing\Router', $this->app['url_matcher']);
+        $this->assertInstanceOf('Symfony\Component\Routing\Router', $this->app['url_generator']);
+    }
+
+    public function testRedirectableUrlMatcherIsUsed()
+    {
+        $this->provider->register($this->app);
+
+        $this->assertEquals('Silex\\RedirectableUrlMatcher', $this->app['router']->getOption('matcher_class'));
+        $this->assertEquals('Silex\\RedirectableUrlMatcher', $this->app['router']->getOption('matcher_base_class'));
+    }
+
+    public function testRouteCollectionIsGottenFromRouter()
+    {
+        $router = $this->getMockBuilder('Symfony\Component\Routing\Router')->disableOriginalConstructor()->getMock();
+        $router->expects($this->once())->method('getRouteCollection');
+
+        $this->provider->register($this->app);
+
+        $this->app['router'] = $router;
+
+        $this->app['routes'];
+    }
+}