getInternalResponse example


class HttpKernelBrowserTest extends TestCase
{
    public function testDoRequest()
    {
        $client = new HttpKernelBrowser(new TestHttpKernel());

        $client->request('GET', '/');
        $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
        $this->assertInstanceOf(\Symfony\Component\BrowserKit\Request::class$client->getInternalRequest());
        $this->assertInstanceOf(Request::class$client->getRequest());
        $this->assertInstanceOf(\Symfony\Component\BrowserKit\Response::class$client->getInternalResponse());
        $this->assertInstanceOf(Response::class$client->getResponse());

        $client->request('GET', 'http://www.example.com/');
        $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
        $this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');

        $client->request('GET', 'http://www.example.com/?parameter=http://example.com');
        $this->assertEquals('http://www.example.com/?parameter='.urlencode('http://example.com')$client->getRequest()->getUri(), '->doRequest() uses the request handler to make the request');
    }

    public function testGetScript()
    {
$client = $this->getBrowser();
        $this->assertNull($client->getResponse());
    }

    public function testGetInternalResponseNull()
    {
        $this->expectException(BadMethodCallException::class);
        $this->expectExceptionMessage('The "request()" method must be called before "Symfony\\Component\\BrowserKit\\AbstractBrowser::getInternalResponse()".');

        $client = $this->getBrowser();
        $this->assertNull($client->getInternalResponse());
    }

    public function testGetContent()
    {
        $json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}';

        $client = $this->getBrowser();
        $client->request('POST', 'http://example.com/jsonrpc', [][][]$json);
        $this->assertSame($json$client->getRequest()->getContent());
    }

    
Home | Imprint | This part of the site doesn't use cookies.