示例#1
0
 /**
  * @covers YAYOG\Parser::parseTextFile
  */
 public function testParseTextFile()
 {
     $workout = new Workout();
     $workout->setProgram('Basic')->setDay(3);
     $parser = $this->getMock('YAYOG\\Parser', array('getWorkout'));
     $parser->expects($this->exactly(9))->method('getWorkout')->will($this->returnValue($workout));
     $history = $parser->parseTextFile(file_get_contents(__DIR__ . '/../../files/multiple.txt'));
     $this->assertInstanceOf('YAYOG\\History', $history);
     $workouts = $history->getWorkouts();
     $this->assertContainsOnlyInstancesOf('YAYOG\\Workout', $workouts);
     $this->assertCount(9, $workouts);
 }
示例#2
0
文件: Parser.php 项目: micheh/yayog
 /**
  * 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;
 }
示例#3
0
 /**
  * @covers YAYOG\History::addWorkout
  */
 public function testAddWorkoutAddsExercises()
 {
     $workout = new Workout();
     $exercises = array(new Exercise(), new Exercise(), new Exercise());
     foreach ($exercises as $exercise) {
         $workout->addExercise($exercise);
     }
     $history = $this->getMock('YAYOG\\History', array('addExercises'));
     $history->expects($this->once())->method('addExercises')->with($exercises);
     $history->addWorkout($workout);
 }
示例#4
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;
 }
示例#5
0
 /**
  * @covers YAYOG\Workout::getLabel
  * @depends testGetLabel
  * @depends testSetProgramNr
  */
 public function testGetLabelWithProgramNr()
 {
     $this->workout->setProgram('Basic')->setDay(12)->setProgramNr(6);
     $this->assertEquals('Basic #6 – Day 12', $this->workout->getLabel());
 }