22
22
use InvalidArgumentException ;
23
23
24
24
use function get_class ;
25
+ use function json_decode ;
25
26
26
27
/**
27
28
* @covers \BitFrame\Parser\MediaParserNegotiator
@@ -66,6 +67,11 @@ public function parse(string $input)
66
67
$ negotiator = new MediaParserNegotiator ($ request );
67
68
$ negotiator ->add ($ parserName , get_class ($ parser ));
68
69
70
+ $ this ->assertSame ('foo(bar) ' , $ negotiator ->parse ('bar ' ));
71
+ }
72
+
73
+ public function testParse (): void
74
+ {
69
75
/** @var \PHPUnit\Framework\MockObject\MockObject|ServerRequestInterface $request */
70
76
$ request = $ this ->getMockBuilder (ServerRequestInterface::class)
71
77
->onlyMethods (['getHeader ' ])
@@ -74,9 +80,20 @@ public function parse(string $input)
74
80
$ request
75
81
->method ('getHeader ' )
76
82
->with ('accept ' )
77
- ->willReturn (['text/made-up ' ]);
83
+ ->willReturn (['application/json ' ]);
78
84
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 ' ));
80
97
}
81
98
82
99
public function testAddNewInvalidParserShouldThrowException (): void
0 commit comments