ProfilerTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\Component\HttpKernel\Tests\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. protected function setUp()
  19. {
  20. if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
  21. $this->markTestSkipped('The "HttpFoundation" component is not available');
  22. }
  23. }
  24. public function testCollect()
  25. {
  26. if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) {
  27. $this->markTestSkipped('This test requires SQLite support in your environment');
  28. }
  29. $request = new Request();
  30. $request->query->set('foo', 'bar');
  31. $response = new Response();
  32. $collector = new RequestDataCollector();
  33. $tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
  34. if (file_exists($tmp)) {
  35. @unlink($tmp);
  36. }
  37. $storage = new SqliteProfilerStorage('sqlite:'.$tmp);
  38. $storage->purge();
  39. $profiler = new Profiler($storage);
  40. $profiler->add($collector);
  41. $profile = $profiler->collect($request, $response);
  42. $profile = $profiler->loadProfile($profile->getToken());
  43. $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
  44. @unlink($tmp);
  45. }
  46. }