You are here

public function ResponseTest::testGetDate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Tests/ResponseTest.php \Symfony\Component\HttpFoundation\Tests\ResponseTest::testGetDate()

File

vendor/symfony/http-foundation/Tests/ResponseTest.php, line 258

Class

ResponseTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testGetDate() {
  $oneHourAgo = $this
    ->createDateTimeOneHourAgo();
  $response = new Response('', 200, array(
    'Date' => $oneHourAgo
      ->format(DATE_RFC2822),
  ));
  $this
    ->assertEquals(0, $oneHourAgo
    ->diff($response
    ->getDate())
    ->format('%s'), '->getDate() returns the Date header if present');
  $response = new Response();
  $date = $response
    ->getDate();
  $this
    ->assertLessThan(1, $date
    ->diff(new \DateTime(), true)
    ->format('%s'), '->getDate() returns the current Date if no Date header present');
  $response = new Response('', 200, array(
    'Date' => $this
      ->createDateTimeOneHourAgo()
      ->format(DATE_RFC2822),
  ));
  $now = $this
    ->createDateTimeNow();
  $response->headers
    ->set('Date', $now
    ->format(DATE_RFC2822));
  $this
    ->assertLessThanOrEqual(1, $now
    ->diff($response
    ->getDate())
    ->format('%s'), '->getDate() returns the date when the header has been modified');
  $response = new Response('', 200);
  $response->headers
    ->remove('Date');
  $this
    ->assertInstanceOf('\\DateTime', $response
    ->getDate());
}