ProfilerTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) {
  21. $this->markTestSkipped('This test requires SQLite support in your environment');
  22. }
  23. $request = new Request();
  24. $request->query->set('foo', 'bar');
  25. $response = new Response();
  26. $collector = new RequestDataCollector();
  27. $tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
  28. if (file_exists($tmp)) {
  29. @unlink($tmp);
  30. }
  31. $storage = new SqliteProfilerStorage('sqlite:'.$tmp);
  32. $storage->purge();
  33. $profiler = new Profiler($storage);
  34. $profiler->add($collector);
  35. $profile = $profiler->collect($request, $response);
  36. $profile = $profiler->loadProfile($profile->getToken());
  37. $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
  38. @unlink($tmp);
  39. }
  40. }