TimeDataCollectorTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\DataCollector;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
  15. /**
  16. * @group time-sensitive
  17. */
  18. class TimeDataCollectorTest extends TestCase
  19. {
  20. public function testCollect()
  21. {
  22. $c = new TimeDataCollector();
  23. $request = new Request();
  24. $request->server->set('REQUEST_TIME', 1);
  25. $c->collect($request, new Response());
  26. $this->assertEquals(0, $c->getStartTime());
  27. $request->server->set('REQUEST_TIME_FLOAT', 2);
  28. $c->collect($request, new Response());
  29. $this->assertEquals(2000, $c->getStartTime());
  30. $request = new Request();
  31. $c->collect($request, new Response());
  32. $this->assertEquals(0, $c->getStartTime());
  33. $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
  34. $kernel->expects($this->once())->method('getStartTime')->will($this->returnValue(123456));
  35. $c = new TimeDataCollector($kernel);
  36. $request = new Request();
  37. $request->server->set('REQUEST_TIME', 1);
  38. $c->collect($request, new Response());
  39. $this->assertEquals(123456000, $c->getStartTime());
  40. }
  41. }