public function AbstractProfilerStorageTest::testStoreTime

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/AbstractProfilerStorageTest.php, line 156

Class

AbstractProfilerStorageTest

Namespace

Symfony\Component\HttpKernel\Tests\Profiler

Code

public function testStoreTime() {
  $dt = new \DateTime('now');
  $start = $dt
    ->getTimestamp();
  for ($i = 0; $i < 3; $i++) {
    $dt
      ->modify('+1 minute');
    $profile = new Profile('time_' . $i);
    $profile
      ->setIp('127.0.0.1');
    $profile
      ->setUrl('http://foo.bar');
    $profile
      ->setTime($dt
      ->getTimestamp());
    $profile
      ->setMethod('GET');
    $this
      ->getStorage()
      ->write($profile);
  }
  $records = $this
    ->getStorage()
    ->find('', '', 3, 'GET', $start, time() + 3 * 60);
  $this
    ->assertCount(3, $records, '->find() returns all previously added records');
  $this
    ->assertEquals($records[0]['token'], 'time_2', '->find() returns records ordered by time in descendant order');
  $this
    ->assertEquals($records[1]['token'], 'time_1', '->find() returns records ordered by time in descendant order');
  $this
    ->assertEquals($records[2]['token'], 'time_0', '->find() returns records ordered by time in descendant order');
  $records = $this
    ->getStorage()
    ->find('', '', 3, 'GET', $start, time() + 2 * 60);
  $this
    ->assertCount(2, $records, '->find() should return only first two of the previously added records');
}