<commit_before><?php

/*
  +------------------------------------------------------------------------+
  | Phalcon Framework                                                      |
  +------------------------------------------------------------------------+
  | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file docs/LICENSE.txt.                        |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to <EMAIL> so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Authors: <NAME> <<EMAIL>>                      |
  |          <NAME> <<EMAIL>>                         |
  +------------------------------------------------------------------------+
*/

class RestHandler
{

	protected $_access = 0;

	protected $_trace = array();

	public function find()
	{
		$this->_access++;
		$this->_trace[] = 'find';
	}

	public function save()
	{
		$this->_access++;
		$this->_trace[] = 'save';
	}

	public function getNumberAccess()
	{
		return $this->_access;
	}

	public function getTrace()
	{
		return $this->_trace;
	}

}

class MicroMvcTest extends PHPUnit_Framework_TestCase
{

	public function testMicroClass()
	{

		$handler = new RestHandler($this);

		$app = new Phalcon\Mvc\Micro();

		$app->get('/api/site', array($handler, 'find'));
		$app->post('/api/site/save', array($handler, 'save'));

		$_SERVER['REQUEST_METHOD'] = 'GET';
		$_GET['_url'] = '/api/site';

		$app->handle();

		$this->assertEquals($handler->getNumberAccess(), 1);
		$this->assertEquals($handler->getTrace(), array('find'));

		$_SERVER['REQUEST_METHOD'] = 'POST';
		$_GET['_url'] = '/api/site/save';

		$app->handle();

		$this->assertEquals($handler->getNumberAccess(), 2);
		$this->assertEquals($handler->getTrace(), array('find', 'save'));
	}

}<commit_msg>T169: Wrote test for the 404 handler 	modified:   unit-tests/MicroMvcTest.php<commit_after><?php

/*
  +------------------------------------------------------------------------+
  | Phalcon Framework                                                      |
  +------------------------------------------------------------------------+
  | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file docs/LICENSE.txt.                        |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to <EMAIL> so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Authors: <NAME> <<EMAIL>>                      |
  |          <NAME> <<EMAIL>>                         |
  +------------------------------------------------------------------------+
*/

class RestHandler
{

	protected $_access = 0;

	protected $_trace = array();

	public function find()
	{
		$this->_access++;
		$this->_trace[] = 'find';
	}

	public function save()
	{
		$this->_access++;
		$this->_trace[] = 'save';
	}

	public function getNumberAccess()
	{
		return $this->_access;
	}

	public function getTrace()
	{
		return $this->_trace;
	}

}

class MicroMvcTest extends PHPUnit_Framework_TestCase
{

	public function testMicroClass()
	{

		$handler = new RestHandler($this);

		$app = new Phalcon\Mvc\Micro();

		$app->get('/api/site', array($handler, 'find'));
		$app->post('/api/site/save', array($handler, 'save'));

		$_SERVER['REQUEST_METHOD'] = 'GET';
		$_GET['_url'] = '/api/site';

		$app->handle();

		$this->assertEquals($handler->getNumberAccess(), 1);
		$this->assertEquals($handler->getTrace(), array('find'));

		$_SERVER['REQUEST_METHOD'] = 'POST';
		$_GET['_url'] = '/api/site/save';

		$app->handle();

		$this->assertEquals($handler->getNumberAccess(), 2);
		$this->assertEquals($handler->getTrace(), array('find', 'save'));
	}

    /**
     * Tests the notFound
     *
     * @issue  T169
     * @author <NAME> <<EMAIL>>
     * @since  2012-11-06
     */
    public function testMicroNotFound_T169()
    {
        $handler = new RestHandler($this);
        $app     = new \Phalcon\Mvc\Micro();

        $app->get('/api/site', array($handler, 'find'));
        $app->post('/api/site/save', array($handler, 'save'));

        $app->notFound(
            function () use ($app) {
                $app->response->setStatusCode(404, "Not Found")->sendHeaders();
                echo 'This is crazy, but this page was not found!';
            }
        );

        $_SERVER['REQUEST_METHOD'] = 'GET';
        $_GET['_url'] = '/fourohfour';

        $app->handle();

        $expected = 1;
        $actual   = $handler->getNumberAccess();

        $this->assertEquals(
            $expected,
            $actual,
            'getNumberAccess does not return correct results'
        );
    }
}
{'fraction_non_alphanumeric': 0.27277747101049143, 'fraction_numerical': 0.008466777102889747, 'mean_word_length': 1.4269763287181778, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6584389', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1407, 'n_words': 338}