Business\Tests\BusinessTest::testSerializeUnserialize PHP Method

testSerializeUnserialize() public method

    public function testSerializeUnserialize()
    {
        $holiday = new \DateTime('2015-05-11');
        $business = new Business([new Day(Days::MONDAY, [['09:00', '13:00'], ['14:00', '17:00']]), new SpecialDay(Days::FRIDAY, function (\DateTime $date) {
            return [['10:00', '13:00'], ['14:00', '17:00']];
        })], new Holidays([$holiday]));
        $serialized = serialize($business);
        $unserialized = unserialize($serialized);
        // Instead of comparing days (can contain closures), we verify the output is the same
        $this->assertFalse($unserialized->within($holiday));
        $this->assertTrue($unserialized->within(new \DateTime('2015-06-01 10:00')));
        // Monday
        $this->assertTrue($unserialized->within(new \DateTime('2015-06-05 10:00')));
        // Friday
        $this->assertFalse($unserialized->within(new \DateTime('2015-06-05 17:01')));
        // Friday
        $this->assertEquals(TestUtil::getPropertyValue($business, 'holidays'), TestUtil::getPropertyValue($unserialized, 'holidays'));
        $this->assertEquals(TestUtil::getPropertyValue($business, 'timezone'), TestUtil::getPropertyValue($unserialized, 'timezone'));
    }