diff --git a/composer.json b/composer.json index 1fd51da..6722e2e 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,9 @@ "require": { "php": ">=7.0.4" }, + "require-dev": { + "phpunit/phpunit": "dev-master" + }, "autoload": { "psr-4": { "Waddle\\": "src/" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..f92bb7e --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,8 @@ + + + + + tests/ + + + \ No newline at end of file diff --git a/tests/ConverterTest.php b/tests/ConverterTest.php new file mode 100644 index 0000000..d31267f --- /dev/null +++ b/tests/ConverterTest.php @@ -0,0 +1,41 @@ +assertEquals(2.23694, \Waddle\Converter::convertMetresPerSecondToMilesPerHour(1)); + } + + public function testConvertMetresPerSecondToKilometresPerHour(){ + $this->assertEquals(3.6, \Waddle\Converter::convertMetresPerSecondToKilometresPerHour(1)); + } + + public function testConvertMetresToKilometres(){ + $this->assertEquals(1, \Waddle\Converter::convertMetresToKilometres(1000)); + } + + public function testConvertMetresToMiles(){ + $this->assertEquals(1, \Waddle\Converter::convertMetresToMiles(1609.34)); + } + + public function testConvertMetresToFeet(){ + $this->assertEquals(3.28084, \Waddle\Converter::convertMetresToFeet(1)); + } + + public function testConvertMilesToMetres(){ + $this->assertEquals(1609.34, \Waddle\Converter::convertMilesToMetres(1)); + } + + public function testConvertKilometresToMetres(){ + $this->assertEquals(1000, \Waddle\Converter::convertKilometresToMetres(1)); + } + + public function testHumanReadableSeconds(){ + $this->assertEquals('05:04:54', \Waddle\Converter::convertSecondsToHumanReadable(18294)); + } + + +} \ No newline at end of file diff --git a/tests/Parsers/TCXParserTest.php b/tests/Parsers/TCXParserTest.php new file mode 100644 index 0000000..b28c938 --- /dev/null +++ b/tests/Parsers/TCXParserTest.php @@ -0,0 +1,77 @@ +parser = new \Waddle\Parsers\TCXParser(); + $this->activity = $this->parser->parse( __DIR__ . '/../run.tcx' ); + } + + public function testActivityStartTime(){ + $this->assertEquals('2017-05-27 09:13:01', $this->activity->getStartTime('Y-m-d H:i:s')); + } + + public function testActivityLaps(){ + $this->assertEquals(1, count($this->activity->getLaps())); + } + + public function testActivityTotalDistance(){ + $this->assertEquals(4824.94, $this->activity->getTotalDistance()); + } + + public function testActivityTotalDuration(){ + $this->assertEquals(1424, $this->activity->getTotalDuration()); + } + + public function testActivityAveragePacePerMile(){ + $this->assertEquals('00:07:54', $this->activity->getAveragePacePerMile()); + } + + public function testActivityAveragePacePerKilometre(){ + $this->assertEquals('00:04:55', $this->activity->getAveragePacePerKilometre()); + } + + public function testActivityAverageSpeedMPH(){ + $this->assertEquals('7.58', round($this->activity->getAverageSpeedInMPH(), 2)); + } + + public function testActivityAverageSpeedKPH(){ + $this->assertEquals('12.20', round($this->activity->getAverageSpeedInKPH(), 2)); + } + + public function testActivityTotalCalories(){ + $this->assertEquals(372, $this->activity->getTotalCalories()); + } + + public function testActivityMaxSpeedMPH(){ + $this->assertEquals('10.45', round($this->activity->getMaxSpeedInMPH(), 2)); + } + + public function testActivityMaxSpeedKPH(){ + $this->assertEquals('16.81', round($this->activity->getMaxSpeedInKPH(), 2)); + } + + public function testActivityTotalAscent(){ + $result = $this->activity->getTotalAscentDescent(); + $this->assertEquals(50.9, $result['ascent']); + } + + public function testActivityTotalDescent(){ + $result = $this->activity->getTotalAscentDescent(); + $this->assertEquals(50.2, $result['descent']); + } + + public function testActivitySplitsInMiles(){ + $this->assertEquals(3, count($this->activity->getSplits('mi'))); + } + + public function testActivitySplitsInKilometres(){ + $this->assertEquals(5, count($this->activity->getSplits('k'))); + } + +} \ No newline at end of file diff --git a/tests/index.php b/tests/index.php deleted file mode 100644 index 0c4be19..0000000 --- a/tests/index.php +++ /dev/null @@ -1,54 +0,0 @@ -parse('run.tcx'); - -echo "dist:"; -var_dump( $activity->getTotalDistance() ); -var_dump( \Waddle\Converter::convertMetresToMiles($activity->getTotalDistance()) . ' mi') ; -var_dump( \Waddle\Converter::convertMetresToKilometres($activity->getTotalDistance()) . ' k') ; - - -echo "dur:"; -var_dump( $activity->getTotalDuration() ); -var_dump( \Waddle\Converter::convertSecondsToHumanReadable($activity->getTotalDuration()) ); - -echo "pace:"; -var_dump( $activity->getAveragePacePerMile() ); -var_dump( $activity->getAveragePacePerKilometre() ); - -echo "cal:"; -var_dump( $activity->getTotalCalories() ); - -echo "avg speed:"; -var_dump( $activity->getAverageSpeedInMPH() . ' mph') ; -var_dump( $activity->getAverageSpeedInKPH(). ' kph') ; - -echo "max speed:"; -var_dump( $activity->getMaxSpeedInMPH() . ' mph') ; -var_dump( $activity->getMaxSpeedInKPH() . ' kph') ; - -echo "elevation:"; -$elv = $activity->getTotalAscentDescent(); -var_dump( 'up ' . \Waddle\Converter::convertMetresToFeet( $elv['ascent'] ) . ' ft'); -var_dump( 'down ' . \Waddle\Converter::convertMetresToFeet( $elv['descent'] ) . ' ft'); - -echo "splits:"; -var_dump( $activity->getSplits('mi') ); -var_dump( $activity->getSplits('k') ); - - - -echo "
"; -var_dump($parser); - \ No newline at end of file