178f1f01a3fc07fdf6d7c92c302e174e561e33a7
[yaffs-website] / vendor / symfony / http-kernel / Tests / DataCollector / ExceptionDataCollectorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\DataCollector;
13
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;
19
20 class ExceptionDataCollectorTest extends TestCase
21 {
22     public function testCollect()
23     {
24         $e = new \Exception('foo', 500);
25         $c = new ExceptionDataCollector();
26         $flattened = FlattenException::create($e);
27         $trace = $flattened->getTrace();
28
29         $this->assertFalse($c->hasException());
30
31         $c->collect(new Request(), new Response(), $e);
32
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());
39     }
40
41     public function testCollectWithoutException()
42     {
43         $c = new ExceptionDataCollector();
44         $c->collect(new Request(), new Response());
45
46         $this->assertFalse($c->hasException());
47     }
48
49     public function testReset()
50     {
51         $c = new ExceptionDataCollector();
52
53         $c->collect(new Request(), new Response(), new \Exception());
54         $c->reset();
55         $c->collect(new Request(), new Response());
56
57         $this->assertFalse($c->hasException());
58     }
59 }