createMock(ServerRequestInterface::class); $request->expects($this->once())->method('getHeader')->with($this->equalTo($headerName)) ->will($this->returnValue($headerValue)); $expectedObj = $this->createMock(BaseAccept::class); $expectedObj->expects($this->once())->method('getType')->will($this->returnValue($expected)); $negotiator = $this->createMock($negotiatorClass); $negotiator->expects($this->once())->method('getBest') ->with($this->equalTo(join(', ', $headerValue)), $this->equalTo($priorities)) ->will($this->returnValue($expectedObj)); $trait = $this->getController(['getRequest', 'getNegotiator']); $trait->expects($this->once())->method('getRequest')->will($this->returnValue($request)); $trait->expects($this->once())->method('getNegotiator')->with($this->equalTo($type)) ->will($this->returnValue($negotiator)); $buildClass = $this->callPrivateMethod($trait, 'getNegotiatorName', [$type]); $result = $trait->{$method}($priorities); $this->assertEquals($buildClass, $negotiatorClass, "Obtained wrong negotiator class"); $this->assertEquals($result, $expected, "Obtained result does not match expected result"); } /** * Test negotiation * @dataProvider negotiateProvider * * @param string $method * @param string $negotiatorClass * @param string $type */ public function testGetNegotiator($method, $negotiatorClass, $type) { $controller = $this->getController(); $this->assertInstanceOf($negotiatorClass, $this->callPrivateMethod($controller, 'getNegotiator', [$type])); } /** * Get the controller class * * @return string */ protected function getControllerClass() { return ContentNegotiation::class; } }