<commit_before><?php

/*
 * This file is part of Mannequin.
 *
 * (c) 2017 Last Call Media, <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace LastCall\Mannequin\Core\Tests;

use LastCall\Mannequin\Core\Mannequin;
use LastCall\Mannequin\Core\Console\Application as ConsoleApplication;
use LastCall\Mannequin\Core\Console\Command\SnapshotCommand;
use LastCall\Mannequin\Core\Console\Command\StartCommand;
use LastCall\Mannequin\Core\Ui\Controller\ManifestController;
use LastCall\Mannequin\Core\Ui\Controller\RenderController;
use LastCall\Mannequin\Core\Ui\Controller\StaticFileController;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

class MannequinTest extends TestCase
{
    public function testHasExpectedRoutes()
    {
        $application = new Mannequin();
        $application->flush();
        /** @var \Symfony\Component\Routing\RouteCollection $routes */
        $routes = $application['routes'];
        $this->assertEquals('controller.manifest:getManifestAction', $routes->get('manifest')->getDefault('_controller'));
        $this->assertEquals('controller.render:renderAction', $routes->get('component_render')->getDefault('_controller'));
        $this->assertEquals('controller.render:renderSourceAction', $routes->get('component_render_source_raw')->getDefault('_controller'));
        $this->assertEquals('controller.render:renderRawAction', $routes->get('component_render_raw')->getDefault('_controller'));
        $this->assertEquals('controller.ui:staticAction', $routes->get('static')->getDefault('_controller'));
    }

    public function testHasConsole()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
            'autoload_path' => __FILE__,
        ]);
        $console = $application->getConsole();
        $this->assertInstanceOf(ConsoleApplication::class, $console);
        $this->assertInstanceOf(SnapshotCommand::class, $console->get('snapshot'));
        $this->assertInstanceOf(StartCommand::class, $console->get('start'));
    }

    public function testHasManifestController()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
        ]);
        $this->assertInstanceOf(ManifestController::class, $application['controller.manifest']);
    }

    public function testHasRenderController()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
        ]);
        $this->assertInstanceOf(RenderController::class, $application['controller.render']);
    }

    public function testHasUiController()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
        ]);
        $this->assertInstanceOf(StaticFileController::class, $application['controller.ui']);
    }

    public function testResolvesConfig()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
        ]);
        $this->assertEquals('bare-config', $application['config']['name']);
    }

    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage Expected config in foo, but the file does not exist
     */
    public function testThrowsForNonexistentConfigFile()
    {
        $application = new Mannequin([
            'config_file' => 'foo',
        ]);
        $application['config'];
    }

    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage Config was not returned from
     */
    public function testThrowsForNonReturningConfigFile()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/nonreturning-config.php',
        ]);<commit_msg>[Core] Fix tests for StaticController<commit_after><?php

/*
 * This file is part of Mannequin.
 *
 * (c) 2017 Last Call Media, <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace LastCall\Mannequin\Core\Tests;

use LastCall\Mannequin\Core\Mannequin;
use LastCall\Mannequin\Core\Console\Application as ConsoleApplication;
use LastCall\Mannequin\Core\Console\Command\SnapshotCommand;
use LastCall\Mannequin\Core\Console\Command\StartCommand;
use LastCall\Mannequin\Core\Ui\Controller\ManifestController;
use LastCall\Mannequin\Core\Ui\Controller\RenderController;
use LastCall\Mannequin\Core\Ui\Controller\StaticFileController;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

class MannequinTest extends TestCase
{
    public function testHasExpectedRoutes()
    {
        $application = new Mannequin();
        $application->flush();
        /** @var \Symfony\Component\Routing\RouteCollection $routes */
        $routes = $application['routes'];
        $this->assertEquals('controller.static:indexAction', $routes->get('index')->getDefault('_controller'));
        $this->assertEquals('controller.manifest:getManifestAction', $routes->get('manifest')->getDefault('_controller'));
        $this->assertEquals('controller.render:renderAction', $routes->get('component_render')->getDefault('_controller'));
        $this->assertEquals('controller.render:renderSourceAction', $routes->get('component_render_source_raw')->getDefault('_controller'));
        $this->assertEquals('controller.render:renderRawAction', $routes->get('component_render_raw')->getDefault('_controller'));
        $this->assertEquals('controller.static:staticAction', $routes->get('static')->getDefault('_controller'));
    }

    public function testHasConsole()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
            'autoload_path' => __FILE__,
        ]);
        $console = $application->getConsole();
        $this->assertInstanceOf(ConsoleApplication::class, $console);
        $this->assertInstanceOf(SnapshotCommand::class, $console->get('snapshot'));
        $this->assertInstanceOf(StartCommand::class, $console->get('start'));
    }

    public function testHasManifestController()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
        ]);
        $this->assertInstanceOf(ManifestController::class, $application['controller.manifest']);
    }

    public function testHasRenderController()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
        ]);
        $this->assertInstanceOf(RenderController::class, $application['controller.render']);
    }

    public function testHasStaticController()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
        ]);
        $this->assertInstanceOf(StaticFileController::class, $application['controller.static']);
    }

    public function testResolvesConfig()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/bare-config.php',
        ]);
        $this->assertEquals('bare-config', $application['config']['name']);
    }

    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage Expected config in foo, but the file does not exist
     */
    public function testThrowsForNonexistentConfigFile()
    {
        $application = new Mannequin([
            'config_file' => 'foo',
        ]);
        $application['config'];
    }

    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage Config was not returned from
     */
    public function testThrowsForNonReturningConfigFile()
    {
        $application = new Mannequin([
            'config_file' => __DIR__.'/Resources/nonreturning-config.php',
        ]);
{'fraction_non_alphanumeric': 0.13780918727915195, 'fraction_numerical': 0.0010095911155981827, 'mean_word_length': 3.5677233429394812, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 80, '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': '2865154', 'n_tokens_mistral': 2129, 'n_tokens_neox': 2126, 'n_words': 362}