assertResponseFormatSame example

public function testAssertResponseRedirectsWithLocationAndStatusCode()
    {
        $this->getResponseTester(new Response('', 302, ['Location' => 'https://example.com/']))->assertResponseRedirects('https://example.com/', 302);
        $this->expectException(AssertionFailedError::class);
        $this->expectExceptionMessageMatches('#(:?\( )?is redirected and has header "Location" with value "https://example\.com/" (:?\) )?and status code is 301\.#');
        $this->getResponseTester(new Response('', 302))->assertResponseRedirects('https://example.com/', 301);
    }

    public function testAssertResponseFormat()
    {
        $this->getResponseTester(new Response('', 200, ['Content-Type' => 'application/vnd.myformat']))->assertResponseFormatSame('custom');
        $this->getResponseTester(new Response('', 200, ['Content-Type' => 'application/ld+json']))->assertResponseFormatSame('jsonld');
        $this->getResponseTester(new Response())->assertResponseFormatSame(null);
        $this->expectException(AssertionFailedError::class);
        $this->expectExceptionMessage("Failed asserting that the Response format is jsonld.\nHTTP/1.0 200 OK");
        $this->getResponseTester(new Response())->assertResponseFormatSame('jsonld');
    }

    public function testAssertResponseHasHeader()
    {
        $this->getResponseTester(new Response())->assertResponseHasHeader('Date');
        $this->expectException(AssertionFailedError::class);
        
Home | Imprint | This part of the site doesn't use cookies.