b24873d4b29b14ef9edba85a43884ee4b95d9fc3
[yaffs-website] / vendor / symfony / http-kernel / Tests / Profiler / ProfilerTest.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\Profiler;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
16 use Symfony\Component\HttpKernel\Profiler\FileProfilerStorage;
17 use Symfony\Component\HttpKernel\Profiler\Profiler;
18 use Symfony\Component\HttpFoundation\Request;
19 use Symfony\Component\HttpFoundation\Response;
20 use Symfony\Component\VarDumper\Cloner\Data;
21
22 class ProfilerTest extends TestCase
23 {
24     private $tmp;
25     private $storage;
26
27     public function testCollect()
28     {
29         $request = new Request();
30         $request->query->set('foo', 'bar');
31         $response = new Response('', 204);
32         $collector = new RequestDataCollector();
33
34         $profiler = new Profiler($this->storage);
35         $profiler->add($collector);
36         $profile = $profiler->collect($request, $response);
37
38         $this->assertSame(204, $profile->getStatusCode());
39         $this->assertSame('GET', $profile->getMethod());
40         $this->assertInstanceOf(Data::class, $profiler->get('request')->getRequestQuery()->all()['foo']);
41     }
42
43     public function testFindWorksWithDates()
44     {
45         $profiler = new Profiler($this->storage);
46
47         $this->assertCount(0, $profiler->find(null, null, null, null, '7th April 2014', '9th April 2014'));
48     }
49
50     public function testFindWorksWithTimestamps()
51     {
52         $profiler = new Profiler($this->storage);
53
54         $this->assertCount(0, $profiler->find(null, null, null, null, '1396828800', '1397001600'));
55     }
56
57     public function testFindWorksWithInvalidDates()
58     {
59         $profiler = new Profiler($this->storage);
60
61         $this->assertCount(0, $profiler->find(null, null, null, null, 'some string', ''));
62     }
63
64     public function testFindWorksWithStatusCode()
65     {
66         $profiler = new Profiler($this->storage);
67
68         $this->assertCount(0, $profiler->find(null, null, null, null, null, null, '204'));
69     }
70
71     protected function setUp()
72     {
73         $this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
74         if (file_exists($this->tmp)) {
75             @unlink($this->tmp);
76         }
77
78         $this->storage = new FileProfilerStorage('file:'.$this->tmp);
79         $this->storage->purge();
80     }
81
82     protected function tearDown()
83     {
84         if (null !== $this->storage) {
85             $this->storage->purge();
86             $this->storage = null;
87
88             @unlink($this->tmp);
89         }
90     }
91 }