Skip to content

Commit 51024d2

Browse files
committed
Added test + Clean-up
1 parent 23f2ec6 commit 51024d2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

test/Parser/MediaParserNegotiatorTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use InvalidArgumentException;
2323

2424
use function get_class;
25+
use function json_decode;
2526

2627
/**
2728
* @covers \BitFrame\Parser\MediaParserNegotiator
@@ -66,6 +67,11 @@ public function parse(string $input)
6667
$negotiator = new MediaParserNegotiator($request);
6768
$negotiator->add($parserName, get_class($parser));
6869

70+
$this->assertSame('foo(bar)', $negotiator->parse('bar'));
71+
}
72+
73+
public function testParse(): void
74+
{
6975
/** @var \PHPUnit\Framework\MockObject\MockObject|ServerRequestInterface $request */
7076
$request = $this->getMockBuilder(ServerRequestInterface::class)
7177
->onlyMethods(['getHeader'])
@@ -74,9 +80,20 @@ public function parse(string $input)
7480
$request
7581
->method('getHeader')
7682
->with('accept')
77-
->willReturn(['text/made-up']);
83+
->willReturn(['application/json']);
7884

79-
$this->assertSame('foo(bar)', $negotiator->parse('bar'));
85+
$parser = new class implements MediaParserInterface {
86+
public const MIMES = ['application/json'];
87+
public function parse(string $input)
88+
{
89+
return json_decode('{"arg":"' . $input . '"}', true);
90+
}
91+
};
92+
93+
$negotiator = new MediaParserNegotiator($request);
94+
$negotiator->add(MediaParserNegotiator::CONTENT_TYPE_JSON, get_class($parser));
95+
96+
$this->assertSame(['arg' => 'bar'], $negotiator->parse('bar'));
8097
}
8198

8299
public function testAddNewInvalidParserShouldThrowException(): void

0 commit comments

Comments
 (0)