Ejemplo n.º 1
0
 public function createFromArray(array $config)
 {
     $calendarName = $this->isCalendarNameProvided($config) ? $config[self::FIELD_CALENDAR_NAME] : null;
     if ($this->isSeasonAwareConfig($config)) {
         $builder = new SeasonAwareCalendarBuilder($calendarName);
         $seasons = $config[self::FIELD_SEASONS];
         foreach ($seasons as $seasonData) {
             $name = $seasonData['name'];
             $months = [];
             foreach ($seasonData[self::FIELD_MONTHS] as $monthData) {
                 $months[] = new Month($monthData['name'], $monthData['numberOfDays']);
             }
             $builder->addSeason($name, $months);
         }
         if (isset($config['firstMonth'])) {
             $monthName = $config['firstMonth'];
             $builder->setFirstMonthByName($monthName);
         }
     } elseif ($this->isMonthAwareConfig($config)) {
         $builder = new MonthAwareCalendarBuilder($calendarName);
         $months = $config[self::FIELD_MONTHS];
         foreach ($months as $name => $numberOfDays) {
             $builder->addMonth($name, $numberOfDays);
         }
     } else {
         throw new InvalidConfigurationException('Configuration must provide seasons or months units. ');
     }
     return $builder->buildCalandar();
 }
 public function testAddMonth()
 {
     $builder = new MonthAwareCalendarBuilder();
     $builder->addMonth('example', 10);
     $this->assertCount(1, $builder->buildCalandar()->getMonths());
 }