Skip to content

Commit

Permalink
Merge pull request #26 from Chemaclass/feature/25-add-transaction-mes…
Browse files Browse the repository at this point in the history
…sage-all-segments

Add TransactionMessage::allSegments()
  • Loading branch information
Chemaclass committed Oct 31, 2022
2 parents 88aac4f + 83fa539 commit a225f18
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/TransactionMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public static function groupSegmentsByMessage(SegmentInterface ...$segments): ar
return self::hasUnhSegment(...$messages);
}

/**
* @return array<string, array<string,SegmentInterface>>
*/
public function allSegments(): array
{
return $this->groupedSegments;
}

/**
* @return array<string,SegmentInterface>
*/
Expand Down
29 changes: 29 additions & 0 deletions tests/Unit/TransactionMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,35 @@ public function message_not_created_if_unt_doesnt_have_unh_or_vice_versa(): void
self::assertEquals([], $this->transactionMessages($fileContent));
}

/**
* @test
*/
public function all_segments(): void
{
$fileContent = <<<EDI
UNA:+.? '
UNH+1+anything'
CNT+5:0.1:KGM'
UNT+10+2'
UNZ+2+3'
EDI;
$messages = $this->transactionMessages($fileContent);
/** @var TransactionMessage $firstMessage */
$firstMessage = reset($messages);

self::assertEquals([
'UNH' => [
'1' => new UNHMessageHeader(['UNH', '1', 'anything']),
],
'CNT' => [
'5' => new CNTControl(['CNT', ['5', '0.1', 'KGM']]),
],
'UNT' => [
'10' => new UNTMessageFooter(['UNT', '10', '2']),
],
], $firstMessage->allSegments());
}

/**
* @test
*/
Expand Down

0 comments on commit a225f18

Please sign in to comment.