<commit_before><?php

namespace Stratify\Framework\Test;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Puli\Repository\Api\ResourceRepository;
use Puli\Repository\FilesystemRepository;
use Stratify\Framework\Application;
use Stratify\Framework\Test\Mock\FakeResponseEmitter;
use Zend\Diactoros\Request;
use Zend\Diactoros\Response\EmitterInterface;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\ServerRequest;
use function Stratify\Router\route;
use function Stratify\Framework\pipe;
use function Stratify\Framework\prefix;
use function Stratify\Framework\router;

class ApplicationTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var FakeResponseEmitter
     */
    private $responseEmitter;

    public function setUp()
    {
        $this->responseEmitter = new FakeResponseEmitter;
    }

    /**
     * @test
     */
    public function calls_middleware()
    {
        $http = function (RequestInterface $request, ResponseInterface $response) {
            $response->getBody()->write('Hello world!');
            return $response;
        };
        $this->runHttp($http);
        $this->assertEquals('Hello world!', $this->responseEmitter->output);
    }

    /**
     * @test
     */
    public function calls_middleware_pipe()
    {
        $http = pipe([
            function (RequestInterface $request, ResponseInterface $response, callable $next) {
                $response->getBody()->write('Hello');
                return $next($request, $response);
            },
            function (RequestInterface $request, ResponseInterface $response) {
                $response->getBody()->write(' world!');
                return $response;
            },
            function () {
                throw new \Exception;
            },
        ]);<commit_msg>Improve test<commit_after><?php

namespace Stratify\Framework\Test;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Puli\Repository\Api\ResourceRepository;
use Puli\Repository\FilesystemRepository;
use Stratify\Framework\Application;
use Stratify\Framework\Test\Mock\FakeResponseEmitter;
use Zend\Diactoros\Request;
use Zend\Diactoros\Response\EmitterInterface;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\ServerRequest;
use function Stratify\Router\route;
use function Stratify\Framework\pipe;
use function Stratify\Framework\prefix;
use function Stratify\Framework\router;

class ApplicationTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var FakeResponseEmitter
     */
    private $responseEmitter;

    public function setUp()
    {
        $this->responseEmitter = new FakeResponseEmitter;
    }

    /**
     * @test
     */
    public function calls_middleware()
    {
        $http = function (RequestInterface $request, ResponseInterface $response, callable $next) {
            $response->getBody()->write('Hello world!');
            return $response;
        };
        $this->runHttp($http);
        $this->assertEquals('Hello world!', $this->responseEmitter->output);
    }

    /**
     * @test
     */
    public function calls_middleware_pipe()
    {
        $http = pipe([
            function (RequestInterface $request, ResponseInterface $response, callable $next) {
                $response->getBody()->write('Hello');
                return $next($request, $response);
            },
            function (RequestInterface $request, ResponseInterface $response) {
                $response->getBody()->write(' world!');
                return $response;
            },
            function () {
                throw new \Exception;
            },
        ]);
{'fraction_non_alphanumeric': 0.11461926240382064, 'fraction_numerical': 0.0, 'mean_word_length': 2.7475149105367795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '1847822', 'n_tokens_mistral': 1023, 'n_tokens_neox': 991, 'n_words': 201}