ExceptionDataCollectorTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
  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. }