<commit_before><?php

namespace Tests\Middlewares;

use App\Middlewares\CacheMiddleware;
use Fig\Http\Message\StatusCodeInterface;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Slim\Psr7\Headers;
use Slim\Psr7\Response;
use Tests\TestCase;

/** @covers \App\Middlewares\CacheMiddleware */
class CacheMiddlewareTest extends TestCase
{
    /** @var RequestHandlerInterface&MockObject */
    protected $handler;

    protected function setUp(): void
    {
        parent::setUp();

        $this->request = $this->createMock(ServerRequestInterface::class);
        $this->handler = $this->createMock(RequestHandlerInterface::class);
    }

    public function test_it_adds_a_response_cache_header_with_age_of_zero_by_defualt(): void
    {
        $this->handler->expects($this->once())->method('handle')->willReturn(
            new Response(StatusCodeInterface::STATUS_OK, new Headers([
                'Content-Type' => 'text/html',
            ]))
        );

        $response = (new CacheMiddleware($this->config))($this->request, $this->handler);

        $this->assertEquals(['max-age=0, must-revalidate'], $response->getHeader('Cache-Control'));
    }

    public function test_it_adds_a_response_cache_header_for_a_pre_configured_http_cache_option(): void
    {
        $this->handler->expects($this->once())->method('handle')->willReturn(
            new Response(StatusCodeInterface::STATUS_OK, new Headers([
                'Content-Type' => 'application/json',
            ]))
        );

        $response = (new CacheMiddleware($this->config))($this->request, $this->handler);

        $this->assertEquals(['max-age=300'], $response->getHeader('Cache-Control'));
    }
}
<commit_msg>Fixed failing test<commit_after><?php

namespace Tests\Middlewares;

use App\Middlewares\CacheMiddleware;
use Fig\Http\Message\StatusCodeInterface;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Slim\Psr7\Headers;
use Slim\Psr7\Response;
use Tests\TestCase;

/** @covers \App\Middlewares\CacheMiddleware */
class CacheMiddlewareTest extends TestCase
{
    /** @var RequestHandlerInterface&MockObject */
    protected $handler;

    protected function setUp(): void
    {
        parent::setUp();

        $this->request = $this->createMock(ServerRequestInterface::class);
        $this->handler = $this->createMock(RequestHandlerInterface::class);
    }

    public function test_it_adds_a_response_cache_header_with_age_of_zero_by_defualt(): void
    {
        $this->handler->expects($this->once())->method('handle')->willReturn(
            new Response(StatusCodeInterface::STATUS_OK, new Headers([
                'Content-Type' => 'text/html',
            ]))
        );

        $response = (new CacheMiddleware($this->config))($this->request, $this->handler);

        $this->assertEquals(['max-age=0'], $response->getHeader('Cache-Control'));
    }

    public function test_it_adds_a_response_cache_header_for_a_pre_configured_http_cache_option(): void
    {
        $this->handler->expects($this->once())->method('handle')->willReturn(
            new Response(StatusCodeInterface::STATUS_OK, new Headers([
                'Content-Type' => 'application/json',
            ]))
        );

        $response = (new CacheMiddleware($this->config))($this->request, $this->handler);

        $this->assertEquals(['max-age=300'], $response->getHeader('Cache-Control'));
    }
}

{'fraction_non_alphanumeric': 0.14646464646464646, 'fraction_numerical': 0.003367003367003367, 'mean_word_length': 3.7093791281373845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '7138344', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1031, 'n_words': 147}