<commit_before><?php

namespace spec\Moccalotto\Hayttp\Mock;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

/**
 * Test.
 *
 * @codingStandardsIgnoreStart
 */
class EndpointSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->beConstructedWith(
            'get|post',
            '{scheme}://{domain}/path',
            function () { return null; }
        );

        $this->shouldHaveType('Moccalotto\Hayttp\Mock\Endpoint');
    }

    function it_can_detect_if_it_can_handle_a_request()
    {
        $this->beConstructedWith('get|post', '{anything}/path', function () { return null; });

        $this->handles(hayttp()->get('https://foo.bar/path'))->shouldBe(true);
        $this->handles(hayttp()->get('https://foo.bar/404'))->shouldBe(false);
    }

    function it_can_handle_a_request()
    {
        $handler = function($request, $route) {
            return hayttp()->createMockResponse($request)
                ->withJsonBody($route->params());
        };

        $this->beConstructedWith('get', '{scheme}://{domain}.{tld}/{path1}/{path2}', $handler);

        $response = $this->handle(hayttp()->get('https://foo.bar/baz/bing'));<commit_msg>FIX: ensure correct params for mock response creation<commit_after><?php

namespace spec\Moccalotto\Hayttp\Mock;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

/**
 * Test.
 *
 * @codingStandardsIgnoreStart
 */
class EndpointSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->beConstructedWith(
            'get|post',
            '{scheme}://{domain}/path',
            function () { return null; }
        );

        $this->shouldHaveType('Moccalotto\Hayttp\Mock\Endpoint');
    }

    function it_can_detect_if_it_can_handle_a_request()
    {
        $this->beConstructedWith('get|post', '{anything}/path', function () { return null; });

        $this->handles(hayttp()->get('https://foo.bar/path'))->shouldBe(true);
        $this->handles(hayttp()->get('https://foo.bar/404'))->shouldBe(false);
    }

    function it_can_handle_a_request()
    {
        $handler = function($request, $route) {
            return hayttp()->createMockResponse($request, $route)
                ->withJsonBody($route->params());
        };

        $this->beConstructedWith('get', '{scheme}://{domain}.{tld}/{path1}/{path2}', $handler);

        $response = $this->handle(hayttp()->get('https://foo.bar/baz/bing'));
{'fraction_non_alphanumeric': 0.1790983606557377, 'fraction_numerical': 0.004098360655737705, 'mean_word_length': 2.9820554649265905, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 6, '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': '924087', 'n_tokens_mistral': 784, 'n_tokens_neox': 755, 'n_words': 95}