/** * @param Plan $plan * * @return Plan */ public function build(Plan $plan) { $this->checkTrainingType($plan); for ($i = 0; $i < $plan->getNbWeek(); $i++) { if (0 == ($i + 1) % 4 && 0 != $i && $plan->getNbWeek() - 1 != $i) { $week = $this->weekBuilder->build('week_recovery', $plan->getTrainingType()); } else { if ($plan->getNbWeek() - 1 == $i && $i != 0) { $week = $this->weekBuilder->build('week_last', $plan->getTrainingType()); } else { $week = $this->weekBuilder->build($plan->getWeekType(), $plan->getTrainingType()); } } $plan->addWeek($week); } return $plan; }
function it_build_a_plan(Plan $plan, TrainingTypeManager $trainingTypeManager, WeekBuilder $weekBuilder, Week $week, AbstractSession $session) { $plan->getTrainingType()->willReturn(10); $plan->getNbWeek()->willReturn(1); $plan->getWeekType()->willReturn('week_3'); $week->getSessions()->willReturn(array($session)); $weekBuilder->build('week_3', 10)->willReturn($week); $plan->addWeek($week)->shouldBeCalled(); $trainingTypeManager->findAll()->willReturn(array(10, 21, 42)); $this->build($plan); }