cff133c1aaa7c22a996f8cbfea6468d13022109a
[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\HttpFoundation\Request;
16 use Symfony\Component\HttpFoundation\Response;
17 use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
18 use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
19 use Symfony\Component\HttpKernel\Profiler\FileProfilerStorage;
20 use Symfony\Component\HttpKernel\Profiler\Profiler;
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         $profiler->saveProfile($profile);
38
39         $this->assertSame(204, $profile->getStatusCode());
40         $this->assertSame('GET', $profile->getMethod());
41         $this->assertSame('bar', $profile->getCollector('request')->getRequestQuery()->all()['foo']->getValue());
42     }
43
44     public function testReset()
45     {
46         $collector = $this->getMockBuilder(DataCollectorInterface::class)
47             ->setMethods(array('collect', 'getName', 'reset'))
48             ->getMock();
49         $collector->expects($this->any())->method('getName')->willReturn('mock');
50         $collector->expects($this->once())->method('reset');
51
52         $profiler = new Profiler($this->storage);
53         $profiler->add($collector);
54         $profiler->reset();
55     }
56
57     public function testFindWorksWithDates()
58     {
59         $profiler = new Profiler($this->storage);
60
61         $this->assertCount(0, $profiler->find(null, null, null, null, '7th April 2014', '9th April 2014'));
62     }
63
64     public function testFindWorksWithTimestamps()
65     {
66         $profiler = new Profiler($this->storage);
67
68         $this->assertCount(0, $profiler->find(null, null, null, null, '1396828800', '1397001600'));
69     }
70
71     public function testFindWorksWithInvalidDates()
72     {
73         $profiler = new Profiler($this->storage);
74
75         $this->assertCount(0, $profiler->find(null, null, null, null, 'some string', ''));
76     }
77
78     public function testFindWorksWithStatusCode()
79     {
80         $profiler = new Profiler($this->storage);
81
82         $this->assertCount(0, $profiler->find(null, null, null, null, null, null, '204'));
83     }
84
85     protected function setUp()
86     {
87         $this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
88         if (file_exists($this->tmp)) {
89             @unlink($this->tmp);
90         }
91
92         $this->storage = new FileProfilerStorage('file:'.$this->tmp);
93         $this->storage->purge();
94     }
95
96     protected function tearDown()
97     {
98         if (null !== $this->storage) {
99             $this->storage->purge();
100             $this->storage = null;
101
102             @unlink($this->tmp);
103         }
104     }
105 }