ProfilerTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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('sqlite:'.$tmp);
  29. $storage->purge();
  30. $profiler = new Profiler($storage);
  31. $profiler->add($collector);
  32. $profile = $profiler->collect($request, $response);
  33. $profile = $profiler->loadProfile($profile->getToken());
  34. $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
  35. @unlink($tmp);
  36. }
  37. }