<commit_before><?php
/**
 * @copyright (c) 2016 Quicken Loans Inc.
 *
 * For full license information, please view the LICENSE distributed with this source code.
 */

namespace QL\Panthor\Bootstrap;

use PHPUnit_Framework_TestCase;
use Slim\App;
use Slim\RouteGroup;

class RouteLoaderTest extends PHPUnit_Framework_TestCase
{
    public $slim;

    public function setUp()
    {
        $this->slim = new App;
    }

    public function testRoutesAttached()
    {
        $routes = [
            'hello_world' => [
                'route' => '/',
                'stack' => ['middleware.one', 'page.one']
            ],
            'test' => [
                'route' => '/test',
                'stack' => ['page.one']
            ]
        ];

        $loader = new RouteLoader($routes);
        $loader($this->slim);

        $routes = $this->slim->getContainer()->get('router')->getRoutes();

        $this->assertCount(2, $routes);
    }

    public function testMultipleMiddlewareAreOrderedCorrectlyInReverse()
    {
        $di = $this->slim->getContainer();
        $di['m.one'] = new TestCallable('one');
        $di['m.two'] = new TestCallable('two');
        $di['m.three'] = new TestCallable('three');
        $di['gm.one'] = new TestCallable('gm.one');
        $di['gm.two'] = new TestCallable('go.two');
        $di['page'] = new TestCallable('controller');

        $routes = [
            'group1' => [
                'route' => '/group1',
                'stack' => ['gm.one:mw', 'gm.two:mw'],
                'routes' => [
                    'hello_world' => [
                        'route' => '/',
                        'stack' => ['m.one:mw', 'm.two:mw', 'm.three:mw', 'page:controller']
                    ]
                ]
            ]
        ];

        $loader = new RouteLoader($routes);
        $loader($this->slim);

        $routes = $di->get('router')->getRoutes();

        $route = array_shift($routes);
        $route->finalize();
        $route->run($di->get('request'), $di->get('response'));

        $expected = <<<OUTPUT
before-gm.one
before-go.two
before-one
before-two
before-three
controller
after-three
after-two
after-one
after-go.two
after-gm.one

OUTPUT;
        $this->assertSame($expected, TestCallable::$output);
    }

    public function testRoutesWithGroupAttached()
    {
        $routes = [
            'hello_world' => [
                'route' => '/hello',<commit_msg>Update unit test for consistency<commit_after><?php
/**
 * @copyright (c) 2016 Quicken Loans Inc.
 *
 * For full license information, please view the LICENSE distributed with this source code.
 */

namespace QL\Panthor\Bootstrap;

use PHPUnit_Framework_TestCase;
use Slim\App;
use Slim\RouteGroup;

class RouteLoaderTest extends PHPUnit_Framework_TestCase
{
    public $slim;

    public function setUp()
    {
        $this->slim = new App;
    }

    public function testRoutesAttached()
    {
        $routes = [
            'hello_world' => [
                'route' => '/',
                'stack' => ['middleware.one', 'page.one']
            ],
            'test' => [
                'route' => '/test',
                'stack' => ['page.one']
            ]
        ];

        $loader = new RouteLoader($routes);
        $loader($this->slim);

        $routes = $this->slim->getContainer()->get('router')->getRoutes();

        $this->assertCount(2, $routes);
    }

    public function testMultipleMiddlewareAreOrderedCorrectlyInReverse()
    {
        $di = $this->slim->getContainer();
        $di['m.one'] = new TestCallable('one');
        $di['m.two'] = new TestCallable('two');
        $di['m.three'] = new TestCallable('three');
        $di['gm.one'] = new TestCallable('gm.one');
        $di['gm.two'] = new TestCallable('gm.two');
        $di['page'] = new TestCallable('controller');

        $routes = [
            'group1' => [
                'route' => '/group1',
                'stack' => ['gm.one:mw', 'gm.two:mw'],
                'routes' => [
                    'hello_world' => [
                        'route' => '/',
                        'stack' => ['m.one:mw', 'm.two:mw', 'm.three:mw', 'page:controller']
                    ]
                ]
            ]
        ];

        $loader = new RouteLoader($routes);
        $loader($this->slim);

        $routes = $di->get('router')->getRoutes();

        $route = array_shift($routes);
        $route->finalize();
        $route->run($di->get('request'), $di->get('response'));

        $expected = <<<OUTPUT
before-gm.one
before-gm.two
before-one
before-two
before-three
controller
after-three
after-two
after-one
after-gm.two
after-gm.one

OUTPUT;
        $this->assertSame($expected, TestCallable::$output);
    }

    public function testRoutesWithGroupAttached()
    {
        $routes = [
            'hello_world' => [
                'route' => '/hello',
{'fraction_non_alphanumeric': 0.1702475956619603, 'fraction_numerical': 0.002864743196234909, 'mean_word_length': 1.9043374925727867, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '967159', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1484, 'n_words': 271}