4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\Profiler;
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;
21 class ProfilerTest extends TestCase
26 public function testCollect()
28 $request = new Request();
29 $request->query->set('foo', 'bar');
30 $response = new Response('', 204);
31 $collector = new RequestDataCollector();
33 $profiler = new Profiler($this->storage);
34 $profiler->add($collector);
35 $profile = $profiler->collect($request, $response);
37 $this->assertSame(204, $profile->getStatusCode());
38 $this->assertSame('GET', $profile->getMethod());
39 $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
42 public function testFindWorksWithDates()
44 $profiler = new Profiler($this->storage);
46 $this->assertCount(0, $profiler->find(null, null, null, null, '7th April 2014', '9th April 2014'));
49 public function testFindWorksWithTimestamps()
51 $profiler = new Profiler($this->storage);
53 $this->assertCount(0, $profiler->find(null, null, null, null, '1396828800', '1397001600'));
56 public function testFindWorksWithInvalidDates()
58 $profiler = new Profiler($this->storage);
60 $this->assertCount(0, $profiler->find(null, null, null, null, 'some string', ''));
63 protected function setUp()
65 $this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
66 if (file_exists($this->tmp)) {
70 $this->storage = new FileProfilerStorage('file:'.$this->tmp);
71 $this->storage->purge();
74 protected function tearDown()
76 if (null !== $this->storage) {
77 $this->storage->purge();
78 $this->storage = null;