ExceptionDataCollectorTest.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. public function testCollectWithoutException()
  34. {
  35. $c = new ExceptionDataCollector();
  36. $c->collect(new Request(), new Response());
  37. $this->assertFalse($c->hasException());
  38. }
  39. public function testReset()
  40. {
  41. $c = new ExceptionDataCollector();
  42. $c->collect(new Request(), new Response(), new \Exception());
  43. $c->reset();
  44. $c->collect(new Request(), new Response());
  45. $this->assertFalse($c->hasException());
  46. }
  47. }