Exemple #1
0
 public function testSerializeUnserialize()
 {
     $day = new Day(Days::MONDAY, [['12:00', '2 pm'], ['14:30', '18:30'], ['09:00', '10 AM']]);
     $serialized = serialize($day);
     $unserialized = unserialize($serialized);
     $this->assertEquals($day->getDayOfWeek(), $unserialized->getDayOfWeek());
     $this->assertEquals(TestUtil::getPropertyValue($day, 'openingIntervals'), TestUtil::getPropertyValue($unserialized, 'openingIntervals'));
 }
Exemple #2
0
 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'));
 }
Exemple #3
0
 public function testSerializeUnserialize()
 {
     $monday = new \DateTime('2015-05-25');
     $day = new SpecialDay(Days::MONDAY, function (\DateTime $date) {
         if ('2015-05-25' == $date->format('Y-m-d')) {
             return [['14:00', '17:00'], ['06:00', '07:00']];
         }
         return [['12:00', '18:00']];
     });
     $serialized = serialize($day);
     $unserialized = unserialize($serialized);
     $this->assertEquals($day->getDayOfWeek(), $unserialized->getDayOfWeek());
     $this->assertEquals(TestUtil::getPropertyValue($day, 'openingIntervalsCache'), TestUtil::getPropertyValue($unserialized, 'openingIntervalsCache'));
     // Instead of comparing closures we check the output is the same
     $this->assertTrue($day->isTimeWithinOpeningHours(new Time('14', '00'), $monday));
     $this->assertFalse($day->isTimeWithinOpeningHours(new Time('08', '00'), $monday));
 }