Skip to content

Commit

Permalink
Merge pull request #23 from mnastalski/multiple-channels
Browse files Browse the repository at this point in the history
Add method to ease adding of transaction channels together
  • Loading branch information
mnastalski authored Jul 13, 2024
2 parents e5a56f5 + 6b62445 commit 757331f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Enums/TransactionChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ enum TransactionChannel: int
case CARDS_ONLY = 4096;
case BLIK = 8192;
case ALL_EXCEPT_BLIK = 16384;

public static function multiple(array $channels): int
{
return array_sum(
array_map(fn (TransactionChannel $channel): int => $channel->value, $channels)
);
}
}
20 changes: 20 additions & 0 deletions tests/Enums/TransactionChannelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Przelewy24\Tests\Enums;

use PHPUnit\Framework\TestCase;
use Przelewy24\Enums\TransactionChannel;

class TransactionChannelTest extends TestCase
{
public function testMultiple(): void
{
$multiple = TransactionChannel::multiple([
TransactionChannel::CARDS,
TransactionChannel::TRADITIONAL_TRANSFER,
TransactionChannel::BLIK,
]);

$this->assertEquals(1 + 4 + 8192, $multiple);
}
}

0 comments on commit 757331f

Please sign in to comment.