ImboUnitTest\Http\Response\ResponseFormatterTest::testCanWrapJsonDataInSpecifiedCallback PHP Method

testCanWrapJsonDataInSpecifiedCallback() public method

public testCanWrapJsonDataInSpecifiedCallback ( $param, $callback, $contentType, $valid = true )
    public function testCanWrapJsonDataInSpecifiedCallback($param, $callback, $contentType, $valid = true)
    {
        $json = '{"key":"value"}';
        $expectedContent = $json;
        if ($valid) {
            $expectedContent = sprintf('%s(%s)', $callback, $json);
        }
        $model = $this->getMock('Imbo\\Model\\ModelInterface');
        $this->formatter->expects($this->once())->method('format')->with($model)->will($this->returnValue($json));
        $this->formatter->expects($this->once())->method('getContentType')->will($this->returnValue($contentType));
        $query = new ParameterBag([$param => $callback]);
        $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('GET'));
        $this->request->query = $query;
        $this->response->headers = $this->getMock('Symfony\\Component\\HttpFoundation\\HeaderBag');
        $this->response->headers->expects($this->once())->method('add')->with(['Content-Type' => $contentType, 'Content-Length' => strlen($expectedContent)]);
        $this->response->expects($this->once())->method('setContent')->with($expectedContent);
        $this->response->expects($this->once())->method('getStatusCode')->will($this->returnValue(200));
        $this->response->expects($this->once())->method('getModel')->will($this->returnValue($model));
        $this->responseFormatter->format($this->event);
    }