Exemplo n.º 1
0
 /**
  * @covers YAYOG\Parser::getExercise
  */
 public function testGetExercise()
 {
     $method = $this->getMethod('getExercise');
     $parsedExercise = $method->invoke($this->parser, '339,Tabatas,Beat Your Boots,Default,240,40,12');
     $expectedExercise = new Exercise();
     $expectedExercise->setNr(339)->setType('Tabatas')->setName('Beat Your Boots')->setVariation('Default')->setSeconds(240)->setReps(40);
     $this->assertEquals($expectedExercise, $parsedExercise);
 }
Exemplo n.º 2
0
 /**
  * Parses a single line of the log file, which contains one exercise.
  *
  * @param string $content Log file content for one exercise
  * @throws InvalidArgumentException If the string could not be converted to an exercise object
  * @return Exercise The exercise object created from the provided string
  */
 protected function getExercise($content)
 {
     $parts = str_getcsv($content);
     if (count($parts) != 7) {
         throw new InvalidArgumentException('Could not convert string to an exercise object');
     }
     $exercise = new Exercise();
     $exercise->setNr($parts[0])->setType($parts[1])->setName($parts[2])->setVariation($parts[3])->setSeconds($parts[4])->setReps($parts[5]);
     return $exercise;
 }
Exemplo n.º 3
0
 /**
  * @param Exercise $exercise
  * @return Workout
  */
 public function addExercise(Exercise $exercise)
 {
     $this->exercises[] = $exercise;
     $this->totalSeconds += $exercise->getSeconds();
     $this->totalReps += $exercise->getReps();
     if (!$this->type) {
         $this->type = str_replace(array(' Primary', ' Secondary', ' 6 reps', ' 8 reps', ' 10 reps'), '', $exercise->getType());
     }
     $exercise->setWorkout($this);
     return $this;
 }
Exemplo n.º 4
0
 /**
  * @covers YAYOG\History::addExercises
  */
 public function testAddExercises()
 {
     $method = new ReflectionMethod('YAYOG\\History', 'addExercises');
     $method->setAccessible(true);
     $exercise1 = new Exercise();
     $exercise1->setType('Ladders')->setName('Squats')->setVariation('Slow');
     $exercise2 = new Exercise();
     $exercise2->setType('Ladders')->setName('Squats')->setVariation('Fast');
     $exercise3 = new Exercise();
     $exercise3->setType('Ladders')->setName('Squats')->setVariation('Slow');
     $exercise4 = new Exercise();
     $exercise4->setType('Ladders')->setName('Squats')->setVariation('Slow');
     $exercise5 = new Exercise();
     $exercise5->setType('Ladders')->setName('Squats')->setVariation('Slow');
     $exercise6 = new Exercise();
     $exercise6->setType('Ladders')->setName('Swimmers')->setVariation('Slow');
     $exercise7 = new Exercise();
     $exercise7->setType('Ladders')->setName('Squats')->setVariation('Fast');
     $exercise8 = new Exercise();
     $exercise8->setType('Ladders')->setName('Squats')->setVariation('Fast');
     $method->invoke($this->history, array($exercise1, $exercise2, $exercise3));
     $method->invoke($this->history, array($exercise4, $exercise5, $exercise6, $exercise7));
     $method->invoke($this->history, array($exercise8));
     $this->assertEmpty($exercise1->getPreviousExercises(), 'First exercise does not have any previous exercises');
     $this->assertEmpty($exercise2->getPreviousExercises(), 'Different variation is considered');
     $this->assertEmpty($exercise3->getPreviousExercises(), 'Same workout is considered');
     $this->assertSame(array($exercise1), $exercise4->getPreviousExercises(), 'Same number is considered');
     $this->assertSame(array($exercise3), $exercise5->getPreviousExercises(), 'Same number is considered even if they do not have the same order');
     $this->assertEmpty($exercise6->getPreviousExercises(), 'Exercise, which was not in the first workout, has no previous exercises');
     $this->assertSame(array($exercise2), $exercise7->getPreviousExercises(), 'Previous exercise is added even if there is only one');
     $this->assertSame(array($exercise7, $exercise2), $exercise8->getPreviousExercises(), 'Multiple previous exercises are added too');
 }
Exemplo n.º 5
0
 /**
  * Helper method to create a configured exercise (to test the renderPreviousExercises method).
  *
  * @return Exercise
  */
 protected function getExercise()
 {
     $exercise = new Exercise();
     $workout = new Workout();
     $workout->setDate(new DateTime());
     $exercise->setWorkout($workout);
     return $exercise;
 }
Exemplo n.º 6
0
 /**
  * @covers YAYOG\Workout::addExercise
  * @covers YAYOG\Workout::getType
  */
 public function testAddExerciseSetsType()
 {
     $exercise1 = new Exercise();
     $exercise1->setType('Stappers 8 reps');
     $this->workout->addExercise($exercise1);
     $this->assertEquals('Stappers', $this->workout->getType());
 }
Exemplo n.º 7
0
 /**
  * Creates and returns the HTML for the previous exercises.
  *
  * @param Exercise $currentExercise The current exercise
  * @param int $amount How many previous exercises should be rendered
  * @return string HTML of the previous exercises
  */
 protected function renderPreviousExercises(Exercise $currentExercise, $amount = 5)
 {
     $previousExercises = $currentExercise->getPreviousExercises();
     if (empty($previousExercises)) {
         return '';
     }
     $html = '<li class="list-group-item list-previous-exercises"><ul class="list-unstyled">';
     $date = $currentExercise->getWorkout()->getDate();
     foreach ($previousExercises as $previousExercise) {
         $previousWorkout = $previousExercise->getWorkout();
         $html .= sprintf('<li>%s&ensp; <a class="workout-link" href="#workout-%d" title="Jump to this workout">' . '%s</a> <span class="text-muted">(%s): %d reps</span></li>', $this->renderRepsDelta($currentExercise->getReps(), $previousExercise->getReps()), $previousWorkout->getId(), $previousWorkout->getLabel(), $this->renderRelativeDate($previousWorkout->getDate(), $date), $previousExercise->getReps());
         if (--$amount == 0) {
             break;
         }
     }
     return $html . '</ul></li>';
 }