Skip to content

Commit

Permalink
Merge pull request z38#36 from sprain/iid-fl
Browse files Browse the repository at this point in the history
Expand IID extraction to IBANs from Liechtenstein
  • Loading branch information
z38 authored Jan 5, 2020
2 parents 199d7c6 + e54f886 commit 719da67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Z38/SwissPayment/IID.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function __construct($iid)
*
* @param IBAN $iban
*
* @throws \InvalidArgumentException When the supplied IBAN is not from Switzerland
* @throws \InvalidArgumentException When the supplied IBAN is not from a supported country.
*/
public static function fromIBAN(IBAN $iban)
{
if ($iban->getCountry() !== 'CH') {
throw new InvalidArgumentException('IID can only be extracted from Swiss IBANs.');
if (!in_array($iban->getCountry(), ['CH', 'LI'])) {
throw new InvalidArgumentException('IID can only be extracted from Swiss and Lichtenstein IBANs.');
}

return new self(substr($iban->normalize(), 4, 5));
Expand Down
15 changes: 12 additions & 3 deletions tests/Z38/SwissPayment/Tests/IIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,21 @@ public function testFormat()
}

/**
* @dataProvider fromIBANSamples
* @covers ::fromIBAN
*/
public function testFromIBAN()
public function testFromIBAN($iban, $iid)
{
$instance = IID::fromIBAN(new IBAN('CH31 8123 9000 0012 4568 9'));
$this->assertSame('81239', $instance->format());
$instance = IID::fromIBAN(new IBAN($iban));
$this->assertSame($iid, $instance->format());
}

public function fromIBANSamples()
{
return [
['CH31 8123 9000 0012 4568 9', '81239'],
['LI21 0881 0000 2324 013A A', '08810'],
];
}

/**
Expand Down

0 comments on commit 719da67

Please sign in to comment.