ProfilerTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\HttpKernel\Profiler;
  11. use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
  12. use Symfony\Component\HttpKernel\Profiler\SQLiteProfilerStorage;
  13. use Symfony\Component\HttpKernel\Profiler\Profiler;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. class ProfilerTest extends \PHPUnit_Framework_TestCase
  17. {
  18. public function testCollect()
  19. {
  20. $request = new Request();
  21. $request->query->set('foo', 'bar');
  22. $response = new Response();
  23. $collector = new RequestDataCollector();
  24. $tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
  25. if (file_exists($tmp)) {
  26. @unlink($tmp);
  27. }
  28. $storage = new SQLiteProfilerStorage($tmp);
  29. $storage->purge(true);
  30. $profiler = new Profiler($storage);
  31. $profiler->add($collector);
  32. $profiler->setToken('foobar');
  33. $profiler->collect($request, $response);
  34. $profiler = new Profiler($storage);
  35. $profiler->setToken('foobar');
  36. $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
  37. @unlink($tmp);
  38. }
  39. }