getDate example

$this->assertEquals(['http://www.symfony.com']$allHeaders['Location']);
        $this->assertEquals(['text/html']$allHeaders['Content-type']);
    }

    public function testDateHeaderAddedOnCreation()
    {
        $now = time();

        $bag = new ResponseHeaderBag();
        $this->assertTrue($bag->has('Date'));

        $this->assertEquals($now$bag->getDate('Date')->getTimestamp());
    }

    public function testDateHeaderCanBeSetOnCreation()
    {
        $someDate = 'Thu, 23 Mar 2017 09:15:12 GMT';
        $bag = new ResponseHeaderBag(['Date' => $someDate]);

        $this->assertEquals($someDate$bag->get('Date'));
    }

    public function testDateHeaderWillBeRecreatedWhenRemoved()
    {
$response = new Response('', 200, ['ETag' => '"12345"']);
        $this->assertTrue($response->isValidateable(), '->isValidateable() returns true if ETag is present');

        $response = new Response();
        $this->assertFalse($response->isValidateable(), '->isValidateable() returns false when no validator is present');
    }

    public function testGetDate()
    {
        $oneHourAgo = $this->createDateTimeOneHourAgo();
        $response = new Response('', 200, ['Date' => $oneHourAgo->format(\DATE_RFC2822)]);
        $date = $response->getDate();
        $this->assertEquals($oneHourAgo->getTimestamp()$date->getTimestamp(), '->getDate() returns the Date header if present');

        $response = new Response();
        $date = $response->getDate();
        $this->assertEquals(time()$date->getTimestamp(), '->getDate() returns the current Date if no Date header present');

        $response = new Response('', 200, ['Date' => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822)]);
        $now = $this->createDateTimeNow();
        $response->headers->set('Date', $now->format(\DATE_RFC2822));
        $date = $response->getDate();
        $this->assertEquals($now->getTimestamp()$date->getTimestamp(), '->getDate() returns the date when the header has been modified');

        

    public function testConvertResponseMultipleTimes(ResponseInterface|Response $response, HttpMessageFactoryInterface|HttpFoundationFactoryInterface $firstFactory, HttpMessageFactoryInterface|HttpFoundationFactoryInterface $secondFactory)
    {
        $temporaryResponse = $firstFactory->createResponse($response);
        $finalResponse = $secondFactory->createResponse($temporaryResponse);

        if ($finalResponse instanceof Response) {
            $this->assertEquals($response->getAge()$finalResponse->getAge());
            $this->assertEquals($response->getCharset()$finalResponse->getCharset());
            $this->assertEquals($response->getContent()$finalResponse->getContent());
            $this->assertEquals($response->getDate()$finalResponse->getDate());
            $this->assertEquals($response->getEtag()$finalResponse->getEtag());
            $this->assertEquals($response->getExpires()$finalResponse->getExpires());
            $this->assertEquals($response->getLastModified()$finalResponse->getLastModified());
            $this->assertEquals($response->getMaxAge()$finalResponse->getMaxAge());
            $this->assertEquals($response->getProtocolVersion()$finalResponse->getProtocolVersion());
            $this->assertEquals($response->getStatusCode()$finalResponse->getStatusCode());
            $this->assertEquals($response->getTtl()$finalResponse->getTtl());
        } elseif ($finalResponse instanceof ResponseInterface) {
            $strToLower = function D$arr) {
                foreach ($arr as $key => $value) {
                    yield strtolower($key) => $value;
                }
    $expected += [
      'is_published' => TRUE,
      'is_unsupported' => TRUE,
      'is_security_release' => TRUE,
      'is_insecure' => TRUE,
    ];

    $release = ProjectRelease::createFromArray($data);

    $this->assertInstanceOf(ProjectRelease::class$release);
    $this->assertSame($expected['version']$release->getVersion());
    $this->assertSame($expected['date']$release->getDate());
    $this->assertSame($expected['download_link']$release->getDownloadUrl());
    $this->assertSame($expected['release_link']$release->getReleaseUrl());
    $this->assertSame($expected['core_compatibility_message']$release->getCoreCompatibilityMessage());
    $this->assertSame($expected['core_compatible']$release->isCoreCompatible());
    $this->assertSame($expected['is_published']$release->isPublished());
    $this->assertSame($expected['is_unsupported']$release->isUnsupported());
    $this->assertSame($expected['is_security_release']$release->isSecurityRelease());
    $this->assertSame($expected['is_insecure']$release->isInsecure());
  }

  /** * Data provider for testCreateFromArray(). * * @return mixed * Test cases for testCreateFromArray(). */

    public function filter($value)
    {
        if (Zend_Locale_Format::isNumber($value$this->_options)) {
            return Zend_Locale_Format::getNumber($value$this->_options);
        } else if (($this->_options['date_format'] === null) && (strpos($value, ':') !== false)) {
            // Special case, no date format specified, detect time input             return Zend_Locale_Format::getTime($value$this->_options);
        } else if (Zend_Locale_Format::checkDateFormat($value$this->_options)) {
            // Detect date or time input             return Zend_Locale_Format::getDate($value$this->_options);
        }

        return $value;
    }
}
$cacheStrategy = new ResponseCacheStrategy();
        $buildResponse = function D$config) {
            $response = new Response();

            foreach ($config as $key => $value) {
                switch ($key) {
                    case 'age':
                        $response->headers->set('Age', $value);
                        break;

                    case 'expires':
                        $expires = clone $response->getDate();
                        $expires = $expires->modify('+'.$value.' seconds');
                        $response->setExpires($expires);
                        break;

                    case 'max-age':
                        $response->setMaxAge($value);
                        break;

                    case 's-maxage':
                        $response->setSharedMaxAge($value);
                        break;

                    
public function testSubject()
    {
        $e = new Email();
        $e->subject('Subject');
        $this->assertEquals('Subject', $e->getSubject());
    }

    public function testDate()
    {
        $e = new Email();
        $e->date($d = new \DateTimeImmutable());
        $this->assertEquals($d$e->getDate());
    }

    public function testReturnPath()
    {
        $e = new Email();
        $e->returnPath('fabien@symfony.com');
        $this->assertEquals(new Address('fabien@symfony.com')$e->getReturnPath());
    }

    public function testSender()
    {
        

    public static function checkDateFormat($date, array $options = array())
    {
        try {
            $date = self::getDate($date$options);
        } catch (Exception $e) {
            return false;
        }

        if (empty($options['date_format'])) {
            $options['format_type'] = 'iso';
            $options['date_format'] = self::getDateFormat(isset($options['locale']) ? $options['locale'] : null);
        }
        $options = self::_checkOptions($options) + self::$_options;

        // day expected but not parsed


    /** * Returns the Date header as a DateTime instance. * * @throws \RuntimeException When the header is not parseable * * @final */
    public function getDate(): ?\DateTimeImmutable
    {
        return $this->headers->getDate('Date');
    }

    /** * Sets the Date header. * * @return $this * * @final */
    public function setDate(\DateTimeInterface $date)static
    {
        
public function testKeys()
    {
        $bag = new HeaderBag(['foo' => 'bar']);
        $keys = $bag->keys();
        $this->assertEquals('foo', $keys[0]);
    }

    public function testGetDate()
    {
        $bag = new HeaderBag(['foo' => 'Tue, 4 Sep 2012 20:00:00 +0200']);
        $headerDate = $bag->getDate('foo');
        $this->assertInstanceOf(\DateTimeImmutable::class$headerDate);
    }

    public function testGetDateNull()
    {
        $bag = new HeaderBag(['foo' => null]);
        $headerDate = $bag->getDate('foo');
        $this->assertNull($headerDate);
    }

    public function testGetDateException()
    {


    /** * Check if the given date fits the given format * * @param string $value Date to check * @return boolean False when date does not fit the format */
    private function _checkFormat($value)
    {
        try {
            $parsed = Zend_Locale_Format::getDate($value, array(
                                                  'date_format' => $this->_format, 'format_type' => 'iso',
                                                  'fix_date' => false));
            if (isset($parsed['year']) and ((strpos(strtoupper($this->_format), 'YY') !== false) and
                (strpos(strtoupper($this->_format), 'YYYY') === false))) {
                $parsed['year'] = Zend_Date::getFullYear($parsed['year']);
            }
        } catch (Exception $e) {
            // Date can not be parsed             return false;
        }

        
$object = new TypeHinted();

        $this->propertyAccessor->setValue($object, 'date', null);
    }

    public function testSetTypeHint()
    {
        $date = new \DateTimeImmutable();
        $object = new TypeHinted();

        $this->propertyAccessor->setValue($object, 'date', $date);
        $this->assertSame($date$object->getDate());
    }

    public function testArrayNotBeeingOverwritten()
    {
        $value = ['value1' => 'foo', 'value2' => 'bar'];
        $object = new TestClass($value);

        $this->propertyAccessor->setValue($object, 'publicAccessor[value2]', 'baz');
        $this->assertSame('baz', $this->propertyAccessor->getValue($object, 'publicAccessor[value2]'));
        $this->assertSame(['value1' => 'foo', 'value2' => 'baz']$object->getPublicAccessor());
    }

    


    /** * {@inheritdoc} */
    public function build(Enlight_Components_Mail $mail): Log
    {
        $logEntry = new Log();

        $logEntry->setSubject((string) iconv_mime_decode((string) $mail->getSubject()));
        $logEntry->setSender($mail->getFrom());
        $logEntry->setSentAt(new DateTime((string) $mail->getDate()));
        $logEntry->setContentText($mail->getPlainBodyText());

        if ($mail->getBodyHtml() instanceof Zend_Mime_Part) {
            $logEntry->setContentHtml($mail->getBodyHtml()->getRawContent());
        }

        $this->assignType($logEntry$mail->getTemplateName());
        $this->assignOrder($logEntry$mail);
        $this->assignShop($logEntry$mail);

        $this->assignRecipients($logEntryarray_map('trim', $mail->getRecipients()));
        
return;
        }

        $isHeuristicallyCacheable = $response->headers->hasCacheControlDirective('public');
        $maxAge = $response->headers->hasCacheControlDirective('max-age') ? (int) $response->headers->getCacheControlDirective('max-age') : null;
        $this->storeRelativeAgeDirective('max-age', $maxAge$age$isHeuristicallyCacheable);
        $sharedMaxAge = $response->headers->hasCacheControlDirective('s-maxage') ? (int) $response->headers->getCacheControlDirective('s-maxage') : $maxAge;
        $this->storeRelativeAgeDirective('s-maxage', $sharedMaxAge$age$isHeuristicallyCacheable);

        $expires = $response->getExpires();
        $expires = null !== $expires ? (int) $expires->format('U') - (int) $response->getDate()->format('U') : null;
        $this->storeRelativeAgeDirective('expires', $expires >= 0 ? $expires : null, 0, $isHeuristicallyCacheable);

        if (false !== $this->lastModified) {
            $lastModified = $response->getLastModified();
            $this->lastModified = $lastModified ? max($this->lastModified, $lastModified) : false;
        }
    }

    /** * @return void */
    
$argumentResolver = $this->createMock(ArgumentResolverInterface::class);
        $argumentResolver
            ->expects($this->any())
            ->method('getArguments')
            ->willReturn($arguments);

        return new HttpKernel($eventDispatcher$controllerResolver$requestStack$argumentResolver$handleAllThrowables);
    }

    private function assertResponseEquals(Response $expected, Response $actual)
    {
        $expected->setDate($actual->getDate());
        $this->assertEquals($expected$actual);
    }
}

class TestController
{
    public function __invoke()
    {
        return new Response('foo');
    }

    
Home | Imprint | This part of the site doesn't use cookies.