4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\DataCollector;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Debug\Exception\FlattenException;
16 use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
17 use Symfony\Component\HttpFoundation\Request;
18 use Symfony\Component\HttpFoundation\Response;
20 class ExceptionDataCollectorTest extends TestCase
22 public function testCollect()
24 $e = new \Exception('foo', 500);
25 $c = new ExceptionDataCollector();
26 $flattened = FlattenException::create($e);
27 $trace = $flattened->getTrace();
29 $this->assertFalse($c->hasException());
31 $c->collect(new Request(), new Response(), $e);
33 $this->assertTrue($c->hasException());
34 $this->assertEquals($flattened, $c->getException());
35 $this->assertSame('foo', $c->getMessage());
36 $this->assertSame(500, $c->getCode());
37 $this->assertSame('exception', $c->getName());
38 $this->assertSame($trace, $c->getTrace());
41 public function testCollectWithoutException()
43 $c = new ExceptionDataCollector();
44 $c->collect(new Request(), new Response());
46 $this->assertFalse($c->hasException());
49 public function testReset()
51 $c = new ExceptionDataCollector();
53 $c->collect(new Request(), new Response(), new \Exception());
55 $c->collect(new Request(), new Response());
57 $this->assertFalse($c->hasException());