<commit_before><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2009, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\console\command;

use \lithium\core\Libraries;
use \lithium\test\Group;
use \lithium\test\Dispatcher;
use \lithium\analysis\Inspector;

/**
 * Runs a given set unit tests and outputs the results.
 */
class Test extends \lithium\console\Command {

	/**
	 * path to test case in dot notation
	 * example: lithium test -case console.CommandTest
	 *
	 * @var string
	 */
	public $case = null;

	/**
	 * path to test group in dot notation
	 * example: lithium test -group console
	 *
	 * @var string
	 */
	public $group = null;

	/**
	 * filters
	 *
	 * @var string
	 */
	public $filters = array();

	/**
	 * Runs tests. Will provide a list of available tests if none are give
	 * Test cases should be given in dot notation.
	 *
	 * case example: lithium test --case=lithium.tests.cases.core.ObjectTest
	 * group example: lithium test --group=lithium.tests.cases.core
	 *
	 * @return void
	 */
	public function run() {
		if ($this->_getTests() != true) {
			return 0;
		}
		$startBenchmark = microtime(true);

		error_reporting(E_ALL | E_STRICT | E_DEPRECATED);

		if (!empty($this->case)) {
			$this->case = '\\' . str_replace('.', '\\', $this->case);
		}

		if (!empty($this->group)) {
			$this->group = '\\' . str_replace('.', '\\', $this->group);
		}
		$run = $this->case ?: $this->group;

		$report = Dispatcher::run($run, array(
			'filters' => $this->filters, 'reporter' => 'text'
		));

		$this->header($report->title);

		$this->out($report->stats());

		$this->out($report->filters());
	}

	/**
	 * Shows which classes are un-tested
	 *
	 * @return void
	 */
	public function missing() {
		$tests = Group::all();
		$this->header('Classes with no test case');
		$classFilter = '/\w+Test$|webroot|index$|^app\\\\config|^app\\\\views/';
		$classes = array_diff(
			Libraries::find(true, array('exclude' => $classFilter, 'recursive' => true)),
			$tests
		);
		sort($classes);
		$this->out($classes);
	}

	/**
	 * Show included files
	 *
	 * @return void
	 */
	public function included() {
		$this->header('Included Files');
		$base = dirname(dirname(dirname(dirname(__DIR__))));
		$files = str_replace($base, '', get_included_files());
		sort($files);
		$this->out($files);
	}

	/**
	 * Provide a list of test cases and accept input as case to run
	 *<commit_msg>Fixing some styling to reflect document standard, and some whitespace in lithium\console\command\Test<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2009, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\console\command;

use \lithium\core\Libraries;
use \lithium\test\Group;
use \lithium\test\Dispatcher;
use \lithium\analysis\Inspector;

/**
 * Runs a given set of unit tests and outputs the results.
 */
class Test extends \lithium\console\Command {

	/**
	 * Path to test case in dot notation.
	 *
	 * For example:
	 * {{{
	 * lithium test -case console.CommandTest
	 * }}}
	 *
	 * @var string
	 */
	public $case = null;

	/**
	 * Path to test group in dot notation.
	 *
	 * For example:
	 * {{{
	 * lithium test -group console
	 * }}}
	 *
	 * @var string
	 */
	public $group = null;

	/**
	 * Filters.
	 *
	 * @var string
	 */
	public $filters = array();

	/**
	 * Runs tests. Will provide a list of available tests if none are given.
	 * Test cases should be given in dot notation.
	 *
	 * Case usage:
	 * {{{
	 * lithium test -case lithium.tests.cases.core.ObjectTest
	 * }}}
	 * {{{
	 * Group usage:
	 * lithium test -group lithium.tests.cases.core
	 * }}}
	 *
	 * @return void
	 */
	public function run() {
		if ($this->_getTests() != true) {
			return 0;
		}
		$startBenchmark = microtime(true);

		error_reporting(E_ALL | E_STRICT | E_DEPRECATED);

		if (!empty($this->case)) {
			$this->case = '\\' . str_replace('.', '\\', $this->case);
		}

		if (!empty($this->group)) {
			$this->group = '\\' . str_replace('.', '\\', $this->group);
		}
		$run = $this->case ?: $this->group;

		$report = Dispatcher::run($run, array(
			'filters' => $this->filters, 'reporter' => 'text'
		));

		$this->header($report->title);

		$this->out($report->stats());

		$this->out($report->filters());
	}

	/**
	 * Shows which classes are un-tested.
	 *
	 * @return void
	 */
	public function missing() {
		$tests = Group::all();
		$this->header('Classes with no test case');
		$classFilter = '/\w+Test$|webroot|index$|^app\\\\config|^app\\\\views/';
		$classes = array_diff(
			Libraries::find(true, array('exclude' => $classFilter, 'recursive' => true)),
			$tests
		);
		sort($classes);
		$this->out($classes);
	}

	/**
	 * Show included files.
	 *
	 * @return void
	 */
	public function included() {
		$this->header('Included Files');
		$base = dirname(dirname(dirname(dirname(__DIR__))));
		$files = str_replace($base, '', get_included_files());
		sort($files);
		$this->out($files);
	}

	/**
	 * Provide a list of test cases and accept input as case to run.
	 *
{'fraction_non_alphanumeric': 0.18110236220472442, 'fraction_numerical': 0.0019204916458613404, 'mean_word_length': 3.136616362192216, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '6876925', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1705, 'n_words': 438}