<commit_before><?php
namespace pyd\testkit;

/**
 * Manage Yii app.
 *
 * This class mostly handles the Yii app creation. In order to do that it will
 * eventually load bootstrap files and set server variables.
 *
 *
 * @author pyd <<EMAIL>>
 */
class AppManager extends \yii\base\Object
{
    /**
     * @var string
     */
    public $appClassName = '\yii\web\Application';

    /**
     * @var \pyd\testkit\interfaces\AppConfigProviderInterface
     */
    protected $configProvider;

    public function init()
    {
        if (null === $this->configProvider) {
            throw new \yii\base\InvalidConfigException(get_class($this) . '::$configProvider must be initialized.');
        }
    }

    public function create()
    {
        $this->setServerVariables($this->configProvider->getServerVariables());
        $this->loadBootstrapFiles($this->configProvider->getBootstrapFiles());
        $this->createYiiApp($this->configProvider->getAppConfig());
    }

    public function clear()
    {
        \Yii::$app = null;
        // reset server variables ?
    }

    /**
     * Initialize $_SERVER variables.
     *
     * @param array $variables ['name' => $value', 'othername' => $otherValue,...]
     */
    protected function setServerVariables(array $variables)
    {
        foreach ($variables as $key => $value) {
            $_SERVER[$key] = $value;
        }
    }

    /**
     * Load bootstrap files.
     *
     * @param array $bootstrapFiles ['/path/to/bootstrapFileOne.php', '/path/to/bootstrapFileTwo.php', ...]
     */
    protected function loadBootstrapFiles(array $bootstrapFiles)
    {
        foreach ($bootstrapFiles as $bootstrapFile) {
            require_once $bootstrapFile;
        }
    }

    /**
     * Create Yii app.
     * 
     * @param array $appConfig
     */
    protected function createYiiApp(array $appConfig)
    {
        if (empty($appConfig['class'])) $appConfig['class'] = $this->appClassName;
        \Yii::createObject($appConfig);
    }

    /**
     * @param string|array|\pyd\testkit\interfaces\AppConfigProviderInterface $configProvider
     */
    protected function setConfigProvider($configProvider)
    {
        $this->configProvider = \yii\di\Instance::ensure($configProvider, '\pyd\testkit\interfaces\AppConfigProviderInterface');
    }
}<commit_msg>Refactor and rename Yii app manager.<commit_after><?php
namespace pyd\testkit;

/**
 * Manage Yii app.
 *
 * This class mostly handles the Yii app creation. In order to do that it will
 * eventually load bootstrap files and set server variables.
 *
 *
 * @author pyd <<EMAIL>>
 */
class AppFixture extends \yii\base\Object
{
    /**
     * @var string
     */
    public $appClassName = '\yii\web\Application';

    /**
     * @var \pyd\testkit\interfaces\AppConfigProviderInterface
     */
    protected $configProvider;

    public function init()
    {
        if (null === $this->configProvider) {
            throw new \yii\base\InvalidConfigException(get_class($this) . '::$configProvider must be initialized.');
        }
    }

    /**
     * Create Yii application instance @see $appClassname.
     *
     * If bootstrap files to load and/or $_SERVER variables to initialized are
     * returned by the @see $configProvider, it will be done before the Yii app
     * creation.
     *
     * @param string $testCaseDirPath path to the parent directory of the
     * currently executed test case
     */
    public function create($testCaseDirPath)
    {
        $this->loadBootstrapFiles($this->configProvider->getBootstrapFiles($testCaseDirPath));
        $this->setServerVariables($this->configProvider->getServerVariables($testCaseDirPath));
        $this->createYiiApp($this->configProvider->getAppConfig($testCaseDirPath));
    }

    public function clear()
    {
        \Yii::$app = null;
        // reset server variables ?
    }

    /**
     * Check if Yii application was created.
     *
     * @return boolean
     */
    public function appCreated()
    {
        return null !== \Yii::$app;
    }

    /**
     * Initialize $_SERVER variables.
     *
     * @param array $variables ['name' => $value', 'othername' => $otherValue,...]
     */
    public function setServerVariables(array $variables)
    {
        foreach ($variables as $key => $value) {
            $_SERVER[$key] = $value;
        }
    }

    /**
     * Load bootstrap files.
     *
     * @param array $bootstrapFiles ['/path/to/bootstrapFileOne.php', '/path/to/bootstrapFileTwo.php', ...]
     */
    public function loadBootstrapFiles(array $bootstrapFiles)
    {
        foreach ($bootstrapFiles as $bootstrapFile) {
            require_once $bootstrapFile;
        }
    }

    /**
     * Create Yii app.
     *
     * @param array $appConfig
     */
    public function createYiiApp(array $appConfig)
    {
        if (empty($appConfig['class'])) $appConfig['class'] = $this->appClassName;
        \Yii::createObject($appConfig);
    }

    /**
     * @param string|array|\pyd\testkit\interfaces\AppConfigProviderInterface $configProvider
     */
    protected function setConfigProvider($configProvider)
    {
        $this->configProvider = \yii\di\Instance::ensure($configProvider, '\pyd\testkit\interfaces\AppConfigProviderInterface');
    }
}
{'fraction_non_alphanumeric': 0.13162393162393163, 'fraction_numerical': 0.0, 'mean_word_length': 2.538978494623656, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, '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': '5959855', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1487, 'n_words': 334}