<commit_before><?php

namespace Digex;

use Silex\WebTestCase as BaseWebTestCase;
use Symfony\Component\Finder\Finder;

abstract class WebTestCase extends BaseWebTestCase
{
    protected static $cache;

    /**
     * Finds the directory where the phpunit.xml(.dist) is stored.
     *
     * If you run tests with the PHPUnit CLI tool, everything will work as expected.
     * If not, override this method in your test classes.
     *
     * @return string The directory where phpunit.xml(.dist) is stored
     */
    protected static function getPhpUnitXmlDir()
    {
        if (!isset($_SERVER['argv']) || false === strpos($_SERVER['argv'][0], 'phpunit')) {
            throw new \RuntimeException('You must override the WebTestCase::createApplication() method.');
        }

        $dir = static::getPhpUnitCliConfigArgument();
        if ($dir === null &&
            (is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml') ||
            is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml.dist'))) {
            $dir = getcwd();
        }

        // Can't continue
        if ($dir === null) {
            throw new \RuntimeException('Unable to guess the app directory.');
        }

        if (!is_dir($dir)) {
            $dir = dirname($dir);
        }

        return $dir;
    }

    /**
     * Finds the value of configuration flag from cli
     *
     * PHPUnit will use the last configuration argument on the command line, so this only returns
     * the last configuration argument
     *
     * @return string The value of the phpunit cli configuration option
     */
    private static function getPhpUnitCliConfigArgument()
    {
        $dir = null;
        $reversedArgs = array_reverse($_SERVER['argv']);
        foreach ($reversedArgs as $argIndex => $testArg) {
            if ($testArg === '-c' || $testArg === '--configuration') {
                $dir = realpath($reversedArgs[$argIndex - 1]);
                break;
            } elseif (strpos($testArg, '--configuration=') === 0) {
                $argPath = substr($testArg, strlen('--configuration='));
                $dir = realpath($argPath);
                break;
            }
        }

        return $dir;
    }

    /**
     * Attempts to guess the app location.
     *
     * When the app is located, the file is required and returned.
     *
     * @return Silex\Application The application
     */
    protected static function getApplication()
    {
        if (!isset(static::$cache['app'])) {
            $dir = isset($_SERVER['APP_DIR']) ? $_SERVER['APP_DIR'] : static::getPhpUnitXmlDir();

            $finder = new Finder();
            $finder->name('app.php')->depth(0)->in($dir);
            $results = iterator_to_array($finder);
            if (!count($results)) {
                throw new \RuntimeException('Either set APP_DIR in your phpunit.xml or override the WebTestCase::createApplication() method.');
            }

            $file = current($results);

            $env = 'test';
            static::$cache['app'] = require_once $file;
        }

        return static::$cache['app'];
    }

    /**
     * Create an application
     * 
     * @return Silex\Application The application
     */
    public function createApplication()
    {
        $app = static::getApplication();
        $app['debug'] = true;
        
        //unset($app['exception_handler']);
        // $this->app['session.test'] = true;

        return $app;
    }
}<commit_msg>added test session for WebTestCase<commit_after><?php

namespace Digex;

use Silex\WebTestCase as BaseWebTestCase;
use Symfony\Component\Finder\Finder;

abstract class WebTestCase extends BaseWebTestCase
{
    protected static $cache;

    /**
     * Finds the directory where the phpunit.xml(.dist) is stored.
     *
     * If you run tests with the PHPUnit CLI tool, everything will work as expected.
     * If not, override this method in your test classes.
     *
     * @return string The directory where phpunit.xml(.dist) is stored
     */
    protected static function getPhpUnitXmlDir()
    {
        if (!isset($_SERVER['argv']) || false === strpos($_SERVER['argv'][0], 'phpunit')) {
            throw new \RuntimeException('You must override the WebTestCase::createApplication() method.');
        }

        $dir = static::getPhpUnitCliConfigArgument();
        if ($dir === null &&
            (is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml') ||
            is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml.dist'))) {
            $dir = getcwd();
        }

        // Can't continue
        if ($dir === null) {
            throw new \RuntimeException('Unable to guess the app directory.');
        }

        if (!is_dir($dir)) {
            $dir = dirname($dir);
        }

        return $dir;
    }

    /**
     * Finds the value of configuration flag from cli
     *
     * PHPUnit will use the last configuration argument on the command line, so this only returns
     * the last configuration argument
     *
     * @return string The value of the phpunit cli configuration option
     */
    private static function getPhpUnitCliConfigArgument()
    {
        $dir = null;
        $reversedArgs = array_reverse($_SERVER['argv']);
        foreach ($reversedArgs as $argIndex => $testArg) {
            if ($testArg === '-c' || $testArg === '--configuration') {
                $dir = realpath($reversedArgs[$argIndex - 1]);
                break;
            } elseif (strpos($testArg, '--configuration=') === 0) {
                $argPath = substr($testArg, strlen('--configuration='));
                $dir = realpath($argPath);
                break;
            }
        }

        return $dir;
    }

    /**
     * Attempts to guess the app location.
     *
     * When the app is located, the file is required and returned.
     *
     * @return Silex\Application The application
     */
    protected static function getApplication()
    {
        if (!isset(static::$cache['app'])) {
            $dir = isset($_SERVER['APP_DIR']) ? $_SERVER['APP_DIR'] : static::getPhpUnitXmlDir();

            $finder = new Finder();
            $finder->name('app.php')->depth(0)->in($dir);
            $results = iterator_to_array($finder);
            if (!count($results)) {
                throw new \RuntimeException('Either set APP_DIR in your phpunit.xml or override the WebTestCase::createApplication() method.');
            }

            $file = current($results);

            $env = 'test';
            static::$cache['app'] = require_once $file;
        }

        return static::$cache['app'];
    }

    /**
     * Create an application
     *
     * @return Silex\Application The application
     */
    public function createApplication()
    {
        $app = static::getApplication();

        // $app['debug'] = true;
        // $app['exception_handler']->disable();

        $app['session.test'] = true;

        return $app;
    }
}
{'fraction_non_alphanumeric': 0.13195044655718813, 'fraction_numerical': 0.0011524056467876692, 'mean_word_length': 2.113452914798206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '7117904', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1869, 'n_words': 508}