<commit_before><?php

namespace PHPFastCGI\Test\Slimmer;

use PHPFastCGI\Adapter\Slim\AppWrapper;
use PHPFastCGI\FastCGIDaemon\Http\Request;
use Slim\App;
use Zend\Diactoros\Response\HtmlResponse;

/**
 * Tests the app wrapper.
 */
class AppWrapperTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Tests that requests are passed through the wrapper correctly.
     */
    public function testHandleRequest()
    {
        // Create the Slim app
        $app = new App();

        // Add a simple route to the app
        $app->get('/hello/{name}', function ($request, $response, $args) {
            $response->write('Hello, ' . $args['name']);
            return $response;
        });

        // Create a kernel for the FastCGI daemon using the Slim app
        $kernel = new AppWrapper($app);

        // Create a request to test the route set up for the app
        $stream = fopen('php://temp', 'r');
        $request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);

        // Get the response from the kernel that is wrapping the app
        $response = $kernel->handleRequest($request);

        // Check that the app has been wrapper properly by comparing to expected response
        $this->assertSame('Hello, Andrew', (string) $response->getBody());

        fclose($stream);
    }
}
<commit_msg>Reverted commit to master<commit_after><?php

namespace PHPFastCGI\Test\Slimmer;

use PHPFastCGI\Adapter\Slim\AppWrapper;
use PHPFastCGI\FastCGIDaemon\Http\Request;
use Slim\App;
use Slim\Exception\Exception as SlimException;
use Zend\Diactoros\Response\HtmlResponse;

/**
 * Tests the app wrapper.
 */
class AppWrapperTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Tests that requests are passed through the wrapper correctly.
     */
    public function testHandleRequest()
    {
        // Create the Slim app
        $app = new App();

        // Add a simple route to the app
        $app->get('/hello/{name}', function ($request, $response, $args) {
            $response->write('Hello, ' . $args['name']);
            return $response;
        });

        // Create a kernel for the FastCGI daemon using the Slim app
        $kernel = new AppWrapper($app);

        // Create a request to test the route set up for the app
        $stream  = fopen('php://temp', 'r');
        $request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);

        // Get the response from the kernel that is wrapping the app
        $response = $kernel->handleRequest($request);

        // Check that the app has been wrapper properly by comparing to expected response
        $this->assertSame('Hello, Andrew', (string) $response->getBody());

        fclose($stream);
    }

    /**
     * Tests that slim exception is handled correctly
     */
    public function testSlimException()
    {
        // Create the Slim app
        $app = new App();

        // Create a Slim Exception to throw
        $expectedResponse = new HtmlResponse('<h1>Error</h1>');
        $slimException = new SlimException($expectedResponse);

        // Add a simple route to the app that throws the exception
        $app->get('/hello/{name}', function ($request, $response, $args) use ($slimException) {
            throw $slimException;
        });

        // Create a kernel for the FastCGI daemon using the Slim app
        $kernel = new AppWrapper($app);

        // Create a request to test the route set up for the app
        $stream  = fopen('php://temp', 'r');
        $request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);

        // Get the response from the kernel that is wrapping the app
        $response = $kernel->handleRequest($request);

        // Check that the app has been wrapper properly by comparing to expected response
        $this->assertEquals((string) $expectedResponse->getBody(), (string) $response->getBody());

        fclose($stream);
    }

    /**
     * Tests that an exception is handled correctly
     */
    public function testException()
    {
        // Create the Slim app
        $app = new App();

        // Add a simple route to the app that throws a general exception
        $app->get('/hello/{name}', function ($request, $response, $args) {
            throw new \Exception;
        });

        // Create a kernel for the FastCGI daemon using the Slim app
        $kernel = new AppWrapper($app);

        // Create a request to test the route set up for the app
        $stream  = fopen('php://temp', 'r');
        $request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);

        // Get the response from the kernel that is wrapping the app
        $response = $kernel->handleRequest($request);

        // Check that the app has returned a valid response
        $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);

        fclose($stream);
    }

    /**
     * Tests that content headers are stripped on 204/304 messages
     */
    public function testStrippedContentHeaders()
    {
        // Create the Slim app
        $app = new App();

        // Add a simple route to the app that throws a general exception
        $app->get('/hello/{name}', function ($request, $response, $args) {
            $response = new HtmlResponse('Hello');

            return $response
                ->withStatus(204)
                ->withAddedHeader('Content-Type', 'text/plain')
                ->withAddedHeader('Content-Length', (string) 10);
        });

        // Create a kernel for the FastCGI daemon using the Slim app
        $kernel = new AppWrapper($app);

        // Create a request to test the route set up for the app
        $stream  = fopen('php://temp', 'r');
        $request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);

        // Get the response from the kernel that is wrapping the app
        $response = $kernel->handleRequest($request);

        // Check that the app has returned a valid response
        $this->assertEquals('Hello', (string) $response->getBody());
        $this->assertFalse($response->hasHeader('Content-Type'));
        $this->assertFalse($response->hasHeader('Content-Length'));

        fclose($stream);
    }
}

{'fraction_non_alphanumeric': 0.12378954163976759, 'fraction_numerical': 0.0020981278244028407, 'mean_word_length': 2.403075233388248, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, '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': '4297974', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1623, 'n_words': 564}