/** * Parses one workout with the exercises. The rest exercises will be omitted, only actual * exercises are created. * * @param string $content Log file content for one workout * @throws InvalidArgumentException If the string could not be converted to a workout object * @return Workout The workout object with the exercises */ protected function getWorkout($content) { $lines = explode("\n\n", $content); $parts = str_getcsv(array_shift($lines)); if (count($parts) != 4 || !count($lines)) { throw new InvalidArgumentException('Could not convert string to a workout object'); } $workout = new Workout(); $workout->setDate(new DateTime($parts[0] . ', ' . $parts[1]))->setProgram(substr($parts[2], 0, -8))->setDay(substr($parts[3], 4)); foreach ($lines as $line) { $exercise = $this->getExercise($line); if ($exercise->getType() != 'Rest') { $workout->addExercise($exercise); } } return $workout; }
/** * 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; }
/** * @covers YAYOG\Workout::setDate * @covers YAYOG\Workout::getDate */ public function testSetDate() { $date = new DateTime(); $this->workout->setDate($date); $this->assertEquals($date, $this->workout->getDate()); }