function it_should_get_endurance_session_for_half_m(SessionManager $sessionManager, EnduranceSession $enduranceSession1, EnduranceSession $enduranceSession2)
 {
     $enduranceSession1->hasTrainingType(21)->willReturn(true);
     $enduranceSession2->hasTrainingType(21)->willReturn(false);
     $sessionManager->findByType('endurance')->willReturn(array($enduranceSession1, $enduranceSession2));
     $this->pickSession('endurance', 21)->shouldReturn($enduranceSession1);
 }
 /**
  * @param string $type
  * @param string $trainingType
  *
  * @return array
  */
 public function pickSession($type, $trainingType)
 {
     $sessions = $this->sessionManager->findByType($type);
     $sessionsByTrainingType = array();
     foreach ($sessions as $session) {
         if ($session->hasTrainingType($trainingType)) {
             $sessionsByTrainingType[] = $session;
         }
     }
     $rand = rand(0, count($sessionsByTrainingType) - 1);
     if (array_key_exists($rand, $sessionsByTrainingType)) {
         return $sessionsByTrainingType[$rand];
     }
     return array();
 }