ExceptionDataCollectorTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\DataCollector;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Debug\Exception\FlattenException;
  13. use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. class ExceptionDataCollectorTest extends TestCase
  17. {
  18. public function testCollect()
  19. {
  20. $e = new \Exception('foo', 500);
  21. $c = new ExceptionDataCollector();
  22. $flattened = FlattenException::create($e);
  23. $trace = $flattened->getTrace();
  24. $this->assertFalse($c->hasException());
  25. $c->collect(new Request(), new Response(), $e);
  26. $this->assertTrue($c->hasException());
  27. $this->assertEquals($flattened, $c->getException());
  28. $this->assertSame('foo', $c->getMessage());
  29. $this->assertSame(500, $c->getCode());
  30. $this->assertSame('exception', $c->getName());
  31. $this->assertSame($trace, $c->getTrace());
  32. }
  33. }