public function testShouldResolveDateTime() { $mappingManager = new MappingManager(); $mappingManager->add(new DateTimeMapping()); $now = new \DateTime('now'); $fake = new FakeDate(); $fake->createdAt = time(); $this->assertEquals($now->format(DateTime::$globalDefaultFormat), $fake->readMapped('createdAt')); $this->assertInstanceOf('\\Vegas\\Util\\DateTime', $fake->readMapped('createdAt')); $this->assertSame($fake->createdAt, (int) $fake->readMapped('createdAt')->format('U')); $fake->createdAt = $now->format('m/d/Y'); $this->assertInstanceOf('\\Vegas\\Util\\DateTime', $fake->readMapped('createdAt')); $this->assertEquals($now->format('m/d/Y'), $fake->readMapped('createdAt')->format('m/d/Y')); $this->assertSame($fake->createdAt, $fake->readMapped('createdAt')->format('m/d/Y')); $fake->createdAt = $now->format('d/m/Y'); if ($now->format('j') > 12) { $this->assertNotInstanceOf('\\Vegas\\Util\\DateTime', $fake->readMapped('createdAt')); $this->assertEquals($now->format('d/m/Y'), $fake->readMapped('createdAt')); $this->assertInternalType('string', $fake->readMapped('createdAt')); } else { $this->assertInstanceOf('\\Vegas\\Util\\DateTime', $fake->readMapped('createdAt')); $this->assertNotEquals($now->format('d/m/Y'), $fake->readMapped('createdAt')->format('d/m/Y')); } }
public function testShouldSerializeDateTimeObjectToJson() { $now = new \DateTime('now'); $dateTime = DateTime::createFromFormat('Y-m-d H:i:s', $now->format('Y-m-d H:i:s')); $this->assertEquals(json_encode($now->format(\DateTime::ISO8601)), json_encode($dateTime)); }