Version 1
[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
21 class ProfilerTest extends TestCase
22 {
23     private $tmp;
24     private $storage;
25
26     public function testCollect()
27     {
28         $request = new Request();
29         $request->query->set('foo', 'bar');
30         $response = new Response('', 204);
31         $collector = new RequestDataCollector();
32
33         $profiler = new Profiler($this->storage);
34         $profiler->add($collector);
35         $profile = $profiler->collect($request, $response);
36
37         $this->assertSame(204, $profile->getStatusCode());
38         $this->assertSame('GET', $profile->getMethod());
39         $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
40     }
41
42     public function testFindWorksWithDates()
43     {
44         $profiler = new Profiler($this->storage);
45
46         $this->assertCount(0, $profiler->find(null, null, null, null, '7th April 2014', '9th April 2014'));
47     }
48
49     public function testFindWorksWithTimestamps()
50     {
51         $profiler = new Profiler($this->storage);
52
53         $this->assertCount(0, $profiler->find(null, null, null, null, '1396828800', '1397001600'));
54     }
55
56     public function testFindWorksWithInvalidDates()
57     {
58         $profiler = new Profiler($this->storage);
59
60         $this->assertCount(0, $profiler->find(null, null, null, null, 'some string', ''));
61     }
62
63     protected function setUp()
64     {
65         $this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
66         if (file_exists($this->tmp)) {
67             @unlink($this->tmp);
68         }
69
70         $this->storage = new FileProfilerStorage('file:'.$this->tmp);
71         $this->storage->purge();
72     }
73
74     protected function tearDown()
75     {
76         if (null !== $this->storage) {
77             $this->storage->purge();
78             $this->storage = null;
79
80             @unlink($this->tmp);
81         }
82     }
83 }