ProfilerTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
  15. use Symfony\Component\HttpKernel\Profiler\FileProfilerStorage;
  16. use Symfony\Component\HttpKernel\Profiler\Profiler;
  17. class ProfilerTest extends TestCase
  18. {
  19. private $tmp;
  20. private $storage;
  21. public function testCollect()
  22. {
  23. $request = new Request();
  24. $request->query->set('foo', 'bar');
  25. $response = new Response('', 204);
  26. $collector = new RequestDataCollector();
  27. $profiler = new Profiler($this->storage);
  28. $profiler->add($collector);
  29. $profile = $profiler->collect($request, $response);
  30. $this->assertSame(204, $profile->getStatusCode());
  31. $this->assertSame('GET', $profile->getMethod());
  32. $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
  33. }
  34. public function testFindWorksWithDates()
  35. {
  36. $profiler = new Profiler($this->storage);
  37. $this->assertCount(0, $profiler->find(null, null, null, null, '7th April 2014', '9th April 2014'));
  38. }
  39. public function testFindWorksWithTimestamps()
  40. {
  41. $profiler = new Profiler($this->storage);
  42. $this->assertCount(0, $profiler->find(null, null, null, null, '1396828800', '1397001600'));
  43. }
  44. public function testFindWorksWithInvalidDates()
  45. {
  46. $profiler = new Profiler($this->storage);
  47. $this->assertCount(0, $profiler->find(null, null, null, null, 'some string', ''));
  48. }
  49. protected function setUp()
  50. {
  51. $this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
  52. if (file_exists($this->tmp)) {
  53. @unlink($this->tmp);
  54. }
  55. $this->storage = new FileProfilerStorage('file:'.$this->tmp);
  56. $this->storage->purge();
  57. }
  58. protected function tearDown()
  59. {
  60. if (null !== $this->storage) {
  61. $this->storage->purge();
  62. $this->storage = null;
  63. @unlink($this->tmp);
  64. }
  65. }
  66. }