<commit_before><?php

namespace SparkTests\Responder;

use Spark\Payload;
use Spark\Responder\FormattedResponder;

use Negotiation\Negotiator;
use Zend\Diactoros\Response;

class FormattedResponderTest extends \PHPUnit_Framework_TestCase
{
    private $responder;

    public function setUp()
    {
        $negotiator = new Negotiator;

        $resolver = $this->getMockBuilder('Relay\ResolverInterface')->getMock();
        $resolver->method('__invoke')
                 ->will($this->returnCallback(function ($spec) {
                     return new $spec;
                 }));

        $this->responder = new FormattedResponder($negotiator, $resolver);
    }

    public function testFormatters()
    {
        $formatters = $this->responder->getFormatters();

        $this->assertArrayHasKey('Spark\Formatter\JsonFormatter', $formatters);

        unset($formatters['Spark\Formatter\JsonFormatter']);

        $formatters = $this->responder->withFormatters($formatters)->getFormatters();

        $this->assertArrayNotHasKey('Spark\Formatter\JsonFormatter', $formatters);

        // Append another one with high quality
        $formatters['Spark\Formatter\FakeFormatter'] = 1.0;

        $formatters = $this->responder->withFormatters($formatters)->getFormatters();
        $sortedcopy = $formatters;

        arsort($sortedcopy);

        $this->assertArrayHasKey('Spark\Formatter\FakeFormatter', $formatters);
        $this->assertSame($formatters, $sortedcopy);
    }

    public function testResponse()
    {
        $request = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
        $request->method('getHeader')
                ->with('Accept')
                ->willReturn(['application/json']);

        $response = new Response;
        $payload  = (new Payload)
            ->withStatus(Payload::OK)
            ->withOutput(['test' => 'test']);
<commit_msg>Fix broken formatted responder test<commit_after><?php

namespace SparkTests\Responder;

use Spark\Payload;
use Spark\Responder\FormattedResponder;

use Negotiation\Negotiator;
use Zend\Diactoros\Response;

class FormattedResponderTest extends \PHPUnit_Framework_TestCase
{
    private $responder;

    public function setUp()
    {
        $negotiator = new Negotiator;

        $resolver = $this->getMockBuilder('Relay\ResolverInterface')->getMock();
        $resolver->method('__invoke')
                 ->will($this->returnCallback(function ($spec) {
                     return new $spec;
                 }));

        $this->responder = new FormattedResponder($negotiator, $resolver);
    }

    public function testFormatters()
    {
        $formatters = $this->responder->getFormatters();

        $this->assertArrayHasKey('Spark\Formatter\JsonFormatter', $formatters);

        unset($formatters['Spark\Formatter\JsonFormatter']);

        $formatters = $this->responder->withFormatters($formatters)->getFormatters();

        $this->assertArrayNotHasKey('Spark\Formatter\JsonFormatter', $formatters);

        // Append another one with high quality
        $formatters['Spark\Formatter\FakeFormatter'] = 1.0;

        $formatters = $this->responder->withFormatters($formatters)->getFormatters();
        $sortedcopy = $formatters;

        arsort($sortedcopy);

        $this->assertArrayHasKey('Spark\Formatter\FakeFormatter', $formatters);
        $this->assertSame($formatters, $sortedcopy);
    }

    public function testResponse()
    {
        $request = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
        $request
            ->expects($this->once())
            ->method('getHeaderLine')
            ->with('Accept')
            ->willReturn('application/json');

        $response = new Response;
        $payload  = (new Payload)
            ->withStatus(Payload::OK)
            ->withOutput(['test' => 'test']);

{'fraction_non_alphanumeric': 0.1384020618556701, 'fraction_numerical': 0.0010309278350515464, 'mean_word_length': 2.948118006103764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '4728593', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1052, 'n_words': 168}