<commit_before><?php

namespace Codeception\Module;

use Arachne\Codeception\Util\Connector\Nette as NetteConnector;
use Codeception\TestCase;
use Codeception\Lib\Framework;
use Nette\Configurator;
use Nette\DI\Container;
use Nette\DI\MissingServiceException;
use Nette\InvalidStateException;
use Nette\Utils\Validators;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

/**
 * @author <NAME>
 */
class Nette extends Framework
{

	/** @var Configurator */
	protected $configurator;

	/** @var Container */
	protected $container;

	/** @var string */
	private $suite;

	/**
	 * @var array $config
	 */
	public function __construct($config = array())
	{
		$this->config = array(
			'configFiles' => array(),
		);
		parent::__construct($config);
	}

	protected function validateConfig()
	{
		parent::validateConfig();
		Validators::assertField($this->config, 'configFiles', 'array');
	}

	// TODO: separate ArachneTools module (debugContent method)
	public function _beforeSuite($settings = array())
	{
		parent::_beforeSuite($settings);

		$this->detectSuiteName($settings);
		$path = pathinfo($settings['path'], PATHINFO_DIRNAME);
		$tempDir = $path . DIRECTORY_SEPARATOR . '_temp' . DIRECTORY_SEPARATOR . $this->suite;

		self::purge($tempDir);
		$this->configurator = new Configurator();
		$this->configurator->setDebugMode(FALSE);
		$this->configurator->setTempDirectory($tempDir);
		$this->configurator->addParameters(array(
			'container' => array(
				'class' => $this->getContainerClass(),
			),
		));

		$files = $this->config['configFiles'];
		$files[] = __DIR__ . '/config.neon';
		foreach ($files as $file) {
			$this->configurator->addConfig($file);
		}

		// Generates and loads the container class.
		// The actual container is created later.
		$this->configurator->createContainer();
	}

	public function _before(TestCase $test)
	{
		$class = $this->getContainerClass();
		// Cannot use $this->configurator->createContainer() directly beacuse it would call $container->initialize().
		// Container initialization is called laiter by NetteConnector.
		$this->container = new $class;
		$this->client = new NetteConnector();
		$this->client->setContainer($this->container);
		parent::_before($test);
	}

	public function _after(TestCase $test)
	{
		parent::_after($test);
		$_SESSION = array();
		$_GET = array();
		$_POST = array();
		$_COOKIE = array();
	}

	/**
	 * @param string $service
	 * @return object
	 */
	public function grabService($service)
	{
		try {
			return $this->container->getByType($service);
		} catch (MissingServiceException $e) {
			$this->fail($e->getMessage());
		}
	}
	
	public function seeRedirectTo($url)
	{
		$response = $this->container->getByType('Nette\Http\IResponse');
		if ($response->getHeader('Location') !== $url) {
			$this->fail('Couldn\'t confirm redirect target to be "' . $url . '", Location header contains "' . $response->getHeader('Location') . '".');<commit_msg>Disabled followRedirects<commit_after><?php

namespace Codeception\Module;

use Arachne\Codeception\Util\Connector\Nette as NetteConnector;
use Codeception\TestCase;
use Codeception\Lib\Framework;
use Nette\Configurator;
use Nette\DI\Container;
use Nette\DI\MissingServiceException;
use Nette\InvalidStateException;
use Nette\Utils\Validators;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

/**
 * @author <NAME>
 */
class Nette extends Framework
{

	/** @var Configurator */
	protected $configurator;

	/** @var Container */
	protected $container;

	/** @var string */
	private $suite;

	/**
	 * @var array $config
	 */
	public function __construct($config = array())
	{
		$this->config = array(
			'configFiles' => array(),
		);
		parent::__construct($config);
	}

	protected function validateConfig()
	{
		parent::validateConfig();
		Validators::assertField($this->config, 'configFiles', 'array');
	}

	// TODO: separate ArachneTools module (debugContent method)
	public function _beforeSuite($settings = array())
	{
		parent::_beforeSuite($settings);

		$this->detectSuiteName($settings);
		$path = pathinfo($settings['path'], PATHINFO_DIRNAME);
		$tempDir = $path . DIRECTORY_SEPARATOR . '_temp' . DIRECTORY_SEPARATOR . $this->suite;

		self::purge($tempDir);
		$this->configurator = new Configurator();
		$this->configurator->setDebugMode(FALSE);
		$this->configurator->setTempDirectory($tempDir);
		$this->configurator->addParameters(array(
			'container' => array(
				'class' => $this->getContainerClass(),
			),
		));

		$files = $this->config['configFiles'];
		$files[] = __DIR__ . '/config.neon';
		foreach ($files as $file) {
			$this->configurator->addConfig($file);
		}

		// Generates and loads the container class.
		// The actual container is created later.
		$this->configurator->createContainer();
	}

	public function _before(TestCase $test)
	{
		$class = $this->getContainerClass();
		// Cannot use $this->configurator->createContainer() directly beacuse it would call $container->initialize().
		// Container initialization is called laiter by NetteConnector.
		$this->container = new $class;
		$this->client = new NetteConnector();
		$this->client->setContainer($this->container);
		// TODO: make this configurable
		$this->client->followRedirects(FALSE);
		parent::_before($test);
	}

	public function _after(TestCase $test)
	{
		parent::_after($test);
		$_SESSION = array();
		$_GET = array();
		$_POST = array();
		$_COOKIE = array();
	}

	/**
	 * @param string $service
	 * @return object
	 */
	public function grabService($service)
	{
		try {
			return $this->container->getByType($service);
		} catch (MissingServiceException $e) {
			$this->fail($e->getMessage());
		}
	}
	
	public function seeRedirectTo($url)
	{
		$response = $this->container->getByType('Nette\Http\IResponse');
		if ($response->getHeader('Location') !== $url) {
			$this->fail('Couldn\'t confirm redirect target to be "' . $url . '", Location header contains "' . $response->getHeader('Location') . '".');
{'fraction_non_alphanumeric': 0.16258389261744965, 'fraction_numerical': 0.0, 'mean_word_length': 4.5919324577861165, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 83, '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': '1534942', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1853, 'n_words': 396}