Brak opisu

ProfilerTest.php 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\FileProfilerStorage;
  13. use Symfony\Component\HttpKernel\Profiler\Profiler;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\VarDumper\Cloner\Data;
  17. class ProfilerTest extends \PHPUnit_Framework_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->assertInstanceOf(Data::class, $profiler->get('request')->getRequestQuery()->all()['foo']);
  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. public function testFindWorksWithStatusCode()
  50. {
  51. $profiler = new Profiler($this->storage);
  52. $this->assertCount(0, $profiler->find(null, null, null, null, null, null, '204'));
  53. }
  54. protected function setUp()
  55. {
  56. $this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
  57. if (file_exists($this->tmp)) {
  58. @unlink($this->tmp);
  59. }
  60. $this->storage = new FileProfilerStorage('file:'.$this->tmp);
  61. $this->storage->purge();
  62. }
  63. protected function tearDown()
  64. {
  65. if (null !== $this->storage) {
  66. $this->storage->purge();
  67. $this->storage = null;
  68. @unlink($this->tmp);
  69. }
  70. }
  71. }