<commit_before><?php
namespace AcelayaTest\Website\Action;

use Acelaya\Website\Action\Template;
use Doctrine\Common\Cache\Cache;
use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequest;
use Zend\Expressive\Twig\TwigRenderer;

class TemplateTest extends TestCase
{
    /**
     * @var Template
     */
    protected $template;
    /**
     * @var Cache
     */
    protected $cache;
    /**
     * @var array
     */
    protected $templatesContentMap = [
        'foo.html.twig' => '<h1>{{ "Hello!!" }}</h1>',
        'errors/404.html.twig' => 'Error'
    ];

    public function setUp()
    {
        $templates = new TwigRenderer(new \Twig_Environment(new \Twig_Loader_Array($this->templatesContentMap)));
        $this->template = new Template($templates);
    }

    public function testDispatch()
    {
        $request = (new ServerRequest())->withAttribute('template', 'foo.html.twig');
        $resp = $this->template->dispatch($request, $this->prophesize(DelegateInterface::class)->reveal());
        $this->assertEquals('<h1>Hello!!</h1>', $resp->getBody()->__toString());
        $this->assertEquals(200, $resp->getStatusCode());
    }

    public function testDispatchWithoutTemplate()
    {
        $resp = $this->template->dispatch(new ServerRequest(), $this->prophesize(DelegateInterface::class)->reveal());
        $this->assertEquals('Error', $resp->getBody()->__toString());
        $this->assertEquals(404, $resp->getStatusCode());
    }

    public function testDispatchAndProcessAreTheSame()
    {
        $request = (new ServerRequest())->withAttribute('template', 'foo.html.twig');
        $firstResp = $this->template->dispatch($request, $this->prophesize(DelegateInterface::class)->reveal());
        $this->assertEquals('<h1>Hello!!</h1>', $firstResp->getBody()->__toString());
        $this->assertEquals(200, $firstResp->getStatusCode());

        $secondResp = $this->template->process($request, $this->prophesize(DelegateInterface::class)->reveal());
        $this->assertEquals('<h1>Hello!!</h1>', $secondResp->getBody()->__toString());
        $this->assertEquals(200, $secondResp->getStatusCode());
    }
}
<commit_msg>Fixed TemplateTest<commit_after><?php
namespace AcelayaTest\Website\Action;

use Acelaya\Website\Action\Template;
use Doctrine\Common\Cache\Cache;
use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Zend\Diactoros\ServerRequest;
use Zend\Expressive\Template\TemplateRendererInterface;

class TemplateTest extends TestCase
{
    private const TEMPLATES_CONTENT_MAP = [
        'Acelaya::foo' => '<h1>Hello!!</h1>',
        'Acelaya::errors/404' => 'Error'
    ];

    /**
     * @var Template
     */
    protected $template;
    /**
     * @var Cache
     */
    protected $cache;

    public function setUp()
    {
        $templates = $this->prophesize(TemplateRendererInterface::class);
        $templates->render(Argument::cetera())->will(function (array $args) {
            $temnplateName = array_shift($args);
            return self::TEMPLATES_CONTENT_MAP[$temnplateName];
        });
        $this->template = new Template($templates->reveal());
    }

    public function testDispatch()
    {
        $request = (new ServerRequest())->withAttribute('template', 'Acelaya::foo');
        $resp = $this->template->dispatch($request, $this->prophesize(DelegateInterface::class)->reveal());
        $this->assertEquals('<h1>Hello!!</h1>', $resp->getBody()->__toString());
        $this->assertEquals(200, $resp->getStatusCode());
    }

    public function testDispatchWithoutTemplate()
    {
        $resp = $this->template->dispatch(new ServerRequest(), $this->prophesize(DelegateInterface::class)->reveal());
        $this->assertEquals('Error', $resp->getBody()->__toString());
        $this->assertEquals(404, $resp->getStatusCode());
    }

    public function testDispatchAndProcessAreTheSame()
    {
        $request = (new ServerRequest())->withAttribute('template', 'Acelaya::foo');
        $firstResp = $this->template->dispatch($request, $this->prophesize(DelegateInterface::class)->reveal());
        $this->assertEquals('<h1>Hello!!</h1>', $firstResp->getBody()->__toString());
        $this->assertEquals(200, $firstResp->getStatusCode());

        $secondResp = $this->template->process($request, $this->prophesize(DelegateInterface::class)->reveal());
        $this->assertEquals('<h1>Hello!!</h1>', $secondResp->getBody()->__toString());
        $this->assertEquals(200, $secondResp->getStatusCode());
    }
}

{'fraction_non_alphanumeric': 0.1781684027777778, 'fraction_numerical': 0.009982638888888888, 'mean_word_length': 3.861814345991561, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 106, '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': '494718', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1327, 'n_words': 192}