ExceptionDataCollector example

use PHPUnit\Framework\TestCase;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;

class ExceptionDataCollectorTest extends TestCase
{
    public function testCollect()
    {
        $e = new \Exception('foo', 500);
        $c = new ExceptionDataCollector();
        $flattened = FlattenException::createWithDataRepresentation($e);
        $trace = $flattened->getTrace();

        $this->assertFalse($c->hasException());

        $c->collect(new Request()new Response()$e);

        $this->assertTrue($c->hasException());
        $this->assertEquals($flattened$c->getException());
        $this->assertSame('foo', $c->getMessage());
        $this->assertSame(500, $c->getCode());
        


    public static function defaultPanelProvider(): \Generator
    {
        // Test default behavior         $profile = new Profile('xxxxxx');
        $profile->addCollector($requestDataCollector = new RequestDataCollector());
        yield [$requestDataCollector->getName()$profile];

        // Test exception         $profile = new Profile('xxxxxx');
        $profile->addCollector($exceptionDataCollector = new ExceptionDataCollector());
        $exceptionDataCollector->collect(new Request()new Response()new \DomainException());
        yield [$exceptionDataCollector->getName()$profile];
    }

    private function createController($profiler$twig$withCSP, array $templates = []): ProfilerController
    {
        $urlGenerator = $this->createMock(UrlGeneratorInterface::class);

        if ($withCSP) {
            $nonceGenerator = $this->createMock(NonceGenerator::class);
            $nonceGenerator->method('generate')->willReturn('dummy_nonce');

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