Skip to content

Commit

Permalink
fix tests and MessageList
Browse files Browse the repository at this point in the history
  • Loading branch information
sportlog committed Feb 23, 2021
1 parent 7c870f5 commit 6c62e32
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/Profile/MessageList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Sportlog\FIT\Profile\Messages\FileIdMessage;
use IteratorAggregate;
use RecursiveArrayIterator;
use Sportlog\FIT\Profile\Types\MesgNum;
use Traversable;

/**
Expand All @@ -37,7 +38,7 @@ class MessageList implements IteratorAggregate, Countable
*/
public function getFileType(): ?int
{
$messages = $this->getMessages(MessageNumber::FileId);
$messages = $this->getMessages(MesgNum::FILE_ID);
if (count($messages) !== 1) {
return null;
}
Expand Down
9 changes: 5 additions & 4 deletions tests/TestCase/Decoder/DecodeActivityTruncatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sportlog\FIT\Test\TestCase\FilePath;
use PHPUnit\Framework\TestCase;
use Sportlog\FIT\Profile\MessageNumber;
use Sportlog\FIT\Profile\Types\MesgNum;

/**
* Decodes the file 'activity_truncated.fit'
Expand All @@ -30,11 +31,11 @@ public function testDecodeFile(): void {
$this->assertNotNull($messages);
$this->assertCount(16, $messages);
//$this->assertEquals(FileType::Activity, $messages->getFileType());
$this->assertCount(1, $messages->getMessages(MessageNumber::FileId));
$this->assertCount(1, $messages->getMessages(MessageNumber::Event));
$this->assertCount(14, $messages->getMessages(MessageNumber::Record));
$this->assertCount(1, $messages->getMessages(MesgNum::FILE_ID));
$this->assertCount(1, $messages->getMessages(MesgNum::EVENT));
$this->assertCount(14, $messages->getMessages(MesgNum::RECORD));

$recMessages = $messages->getMessages(MessageNumber::Record);
$recMessages = $messages->getMessages(MesgNum::RECORD);
/** @var RecordMessage $lastRecordMessage */
$lastRecordMessage = $recMessages[count($recMessages)-1];
$this->assertEquals(5.73, $lastRecordMessage->getDistance());
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Decoder/DecodeDeveloperDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Sportlog\FIT\Profile\Message\RecordMessage;
use Sportlog\FIT\Profile\MessageNumber;
use Sportlog\FIT\Profile\Types\MesgNum;

/**
* Decodes the file 'DeveloperData.fit'
Expand All @@ -27,7 +28,7 @@ public function testDecodeFile(): void {
$this->assertNotNull($messages);
$this->assertCount(6, $messages);

$recordMessages = $messages->getMessages(MessageNumber::Record);
$recordMessages = $messages->getMessages(MesgNum::RECORD);
$this->assertEquals(3, count($recordMessages));

$this->assertSame(1, $recordMessages[0]->getFieldValue('doughnuts_earned'));
Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase/Decoder/DecodeMonitoringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sportlog\FIT\Test\TestCase\FilePath;
use PHPUnit\Framework\TestCase;
use Sportlog\FIT\Profile\MessageNumber;
use Sportlog\FIT\Profile\Types\MesgNum;

/**
* Decodes the file 'MonitoringFile.fit'
Expand All @@ -30,10 +31,10 @@ public function testDecodeFile(): void

$this->assertNotNull($messages);

$monitoringMessages = $messages->getMessages(MessageNumber::Monitoring);
$monitoringMessages = $messages->getMessages(MesgNum::MONITORING);
$this->assertCount(337, $monitoringMessages);

$monitoringInfoMessages = $messages->getMessages(MessageNumber::MonitoringInfo);
$monitoringInfoMessages = $messages->getMessages(MesgNum::MONITORING_INFO);
/** @var MonitoringInfoMessage $lastMonitoringInfoMessage */
$lastMonitoringInfoMessage = $monitoringInfoMessages[count($monitoringInfoMessages) - 1];
$this->assertEquals(2042, $lastMonitoringInfoMessage->getRestingMetabolicRate());
Expand Down
11 changes: 6 additions & 5 deletions tests/TestCase/Decoder/DecodeSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Sportlog\FIT\Test\TestCase\FilePath;
use PHPUnit\Framework\TestCase;
use Sportlog\FIT\Profile\MessageNumber;
use Sportlog\FIT\Profile\Types\MesgNum;

/**
* Decodes the file 'Settings.fit'
Expand All @@ -27,17 +28,17 @@ public function testDecodeFile(): void {

$this->assertNotNull($messages);
$this->assertCount(3, $messages);
$this->assertCount(1, $messages->getMessages(MessageNumber::FileId));
$this->assertCount(1, $messages->getMessages(MesgNum::FILE_ID));
// $this->assertEquals(FileType::Settings, $messages->getFileType());
$this->assertCount(1, $messages->getMessages(MessageNumber::UserProfile));
$this->assertCount(1, $messages->getMessages(MessageNumber::HrmProfile));
$this->assertCount(1, $messages->getMessages(MesgNum::USER_PROFILE));
$this->assertCount(1, $messages->getMessages(MesgNum::HRM_PROFILE));

$hrmMessages = $messages->getMessages(MessageNumber::HrmProfile);
$hrmMessages = $messages->getMessages(MesgNum::HRM_PROFILE);
/** @var HrmProfileMessage $lastRecordMessage */
$lastHrmProfileMessage = $hrmMessages[count($hrmMessages)-1];
$this->assertEquals(100, $lastHrmProfileMessage->getHrmAntId());

$userProfileMessages = $messages->getMessages(MessageNumber::UserProfile);
$userProfileMessages = $messages->getMessages(MesgNum::USER_PROFILE);
/** @var UserProfileMessage $lastUserProfileMessage */
$lastUserProfileMessage = $userProfileMessages[count($userProfileMessages)-1];
$this->assertEquals(90, $lastUserProfileMessage->getWeight());
Expand Down

0 comments on commit 6c62e32

Please sign in to comment.