-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f74b97e
commit d070642
Showing
7 changed files
with
452 additions
and
456 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
tests/ToStringIbanTraitTest.php → tests/Helper/ToStringIbanTraitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,86 @@ | ||
<?php | ||
|
||
namespace rikudou\EuQrPayment\Tests; | ||
|
||
use InvalidArgumentException; | ||
use PHPUnit\Framework\TestCase; | ||
use rikudou\EuQrPayment\Helper\Utils; | ||
use rikudou\EuQrPayment\Iban\IBAN; | ||
use rikudou\EuQrPayment\Tests\Data\ConstantsClass; | ||
use stdClass; | ||
|
||
class UtilsTest extends TestCase | ||
{ | ||
public function testGetConstants() | ||
{ | ||
$this->assertEquals([], Utils::getConstants(stdClass::class)); | ||
$this->assertEquals([ | ||
'NAME1' => 'value1', | ||
'NAME2' => 'value2', | ||
], Utils::getConstants(ConstantsClass::class)); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
Utils::getConstants('NonExistentClass'); | ||
} | ||
|
||
public function testGetType() | ||
{ | ||
$tmpFile = tempnam(sys_get_temp_dir(), 'qrPaymentEuTest'); | ||
|
||
$string = 'string'; | ||
$int = 1; | ||
$bool = true; | ||
$null = null; | ||
$array = []; | ||
$class1 = new stdClass(); | ||
$class2 = new IBAN('CZ5530300000001325090010'); | ||
$stream = fopen($tmpFile, 'r'); | ||
|
||
$this->assertEquals('string', Utils::getType($string)); | ||
$this->assertEquals('integer', Utils::getType($int)); | ||
$this->assertEquals('boolean', Utils::getType($bool)); | ||
$this->assertEquals('NULL', Utils::getType($null)); | ||
$this->assertEquals('array', Utils::getType($array)); | ||
$this->assertEquals('stdClass', Utils::getType($class1)); | ||
$this->assertEquals("rikudou\EuQrPayment\Iban\IBAN", Utils::getType($class2)); | ||
$this->assertEquals('resource (stream)', Utils::getType($stream)); | ||
|
||
fclose($stream); | ||
unlink($tmpFile); | ||
} | ||
|
||
public function testBcmod() | ||
{ | ||
for ($i = 0; $i <= 1; $i++) { | ||
$forceCustomImplementation = !!$i; | ||
|
||
$this->assertEquals('1', Utils::bcmod(11, 2, $forceCustomImplementation)); | ||
$this->assertEquals('3', Utils::bcmod('8728932001983192837219398127471', 7, $forceCustomImplementation)); | ||
$this->assertEquals('663577', Utils::bcmod('87289320019831928372193981274715795247', 1145678, $forceCustomImplementation)); | ||
} | ||
} | ||
|
||
public function testBcmodNonNumericDividend() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
Utils::bcmod('test', 123); | ||
} | ||
|
||
public function testBcmodNonNumericDivisor() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
Utils::bcmod(123, 't'); | ||
} | ||
|
||
public function testBcmodTooBigDivisor() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
Utils::bcmod(1, '87289320019831928372193981274715795247', true); | ||
} | ||
|
||
public function testBcmodNegativeNumber() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
Utils::bcmod(-5, 1, true); | ||
} | ||
} | ||
<?php | ||
|
||
namespace rikudou\EuQrPayment\Tests\Helper; | ||
|
||
use InvalidArgumentException; | ||
use rikudou\EuQrPayment\Helper\Utils; | ||
use PHPUnit\Framework\TestCase; | ||
use rikudou\EuQrPayment\Iban\IBAN; | ||
use rikudou\EuQrPayment\Tests\Data\ConstantsClass; | ||
use stdClass; | ||
|
||
class UtilsTest extends TestCase | ||
{ | ||
public function testGetConstants() | ||
{ | ||
$this->assertEquals([], Utils::getConstants(stdClass::class)); | ||
$this->assertEquals([ | ||
'NAME1' => 'value1', | ||
'NAME2' => 'value2', | ||
], Utils::getConstants(ConstantsClass::class)); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
Utils::getConstants('NonExistentClass'); | ||
} | ||
|
||
public function testGetType() | ||
{ | ||
$tmpFile = tempnam(sys_get_temp_dir(), 'qrPaymentEuTest'); | ||
|
||
$string = 'string'; | ||
$int = 1; | ||
$bool = true; | ||
$null = null; | ||
$array = []; | ||
$class1 = new stdClass(); | ||
$class2 = new IBAN('CZ5530300000001325090010'); | ||
$stream = fopen($tmpFile, 'r'); | ||
|
||
$this->assertEquals('string', Utils::getType($string)); | ||
$this->assertEquals('integer', Utils::getType($int)); | ||
$this->assertEquals('boolean', Utils::getType($bool)); | ||
$this->assertEquals('NULL', Utils::getType($null)); | ||
$this->assertEquals('array', Utils::getType($array)); | ||
$this->assertEquals('stdClass', Utils::getType($class1)); | ||
$this->assertEquals("rikudou\EuQrPayment\Iban\IBAN", Utils::getType($class2)); | ||
$this->assertEquals('resource (stream)', Utils::getType($stream)); | ||
|
||
fclose($stream); | ||
unlink($tmpFile); | ||
} | ||
|
||
public function testBcmod() | ||
{ | ||
for ($i = 0; $i <= 1; $i++) { | ||
$forceCustomImplementation = !!$i; | ||
|
||
$this->assertEquals('1', Utils::bcmod(11, 2, $forceCustomImplementation)); | ||
$this->assertEquals('3', Utils::bcmod('8728932001983192837219398127471', 7, $forceCustomImplementation)); | ||
$this->assertEquals('663577', Utils::bcmod('87289320019831928372193981274715795247', 1145678, $forceCustomImplementation)); | ||
} | ||
} | ||
|
||
public function testBcmodNonNumericDividend() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
Utils::bcmod('test', 123); | ||
} | ||
|
||
public function testBcmodNonNumericDivisor() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
Utils::bcmod(123, 't'); | ||
} | ||
|
||
public function testBcmodTooBigDivisor() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
Utils::bcmod(1, '87289320019831928372193981274715795247', true); | ||
} | ||
|
||
public function testBcmodNegativeNumber() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
Utils::bcmod(-5, 1, true); | ||
} | ||
} |
172 changes: 86 additions & 86 deletions
172
tests/CzechIbanAdapterTest.php → tests/Iban/CzechIbanAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,86 @@ | ||
<?php | ||
|
||
namespace rikudou\EuQrPayment\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use rikudou\EuQrPayment\Iban\CzechIbanAdapter; | ||
use rikudou\EuQrPayment\Iban\Validator\ValidatorInterface; | ||
|
||
class CzechIbanAdapterTest extends TestCase | ||
{ | ||
public function testAccountsWithoutPrefix() | ||
{ | ||
$accounts = [ | ||
'CZ55 3030 0000 0013 2509 0010' => [ | ||
'acc' => '1325090010', | ||
'bank' => '3030', | ||
], | ||
'CZ36 3030 0000 0013 2509 0061' => [ | ||
'acc' => '1325090061', | ||
'bank' => '3030', | ||
], | ||
'CZ91 0300 0000 0002 8111 5217' => [ | ||
'acc' => '281115217', | ||
'bank' => '0300', | ||
], | ||
'CZ52 0300 0000 0000 0398 3815' => [ | ||
'acc' => '3983815', | ||
'bank' => '0300', | ||
], | ||
'CZ13 2700 0000 0005 0011 4004' => [ | ||
'acc' => '500114004', | ||
'bank' => '2700', | ||
], | ||
]; | ||
|
||
foreach ($accounts as $iban => $accountData) { | ||
$iban = str_replace(' ', '', $iban); | ||
$this->assertEquals($iban, $this->getIban($accountData['acc'], $accountData['bank'])->asString()); | ||
$this->assertEquals($iban, strval($this->getIban($accountData['acc'], $accountData['bank']))); | ||
} | ||
} | ||
|
||
public function testAccountsWithPrefix() | ||
{ | ||
$accounts = [ | ||
'CZ03 0710 0010 1100 1792 9051' => [ | ||
'acc' => '17929051', | ||
'bank' => '0710', | ||
'prefix' => '1011', | ||
], | ||
'CZ47 0710 0210 1200 2792 4051' => [ | ||
'acc' => '27924051', | ||
'bank' => '0710', | ||
'prefix' => '21012', | ||
], | ||
]; | ||
|
||
foreach ($accounts as $iban => $accountData) { | ||
$iban = str_replace(' ', '', $iban); | ||
$this->assertEquals($iban, $this->getIban($accountData['acc'], $accountData['bank'], $accountData['prefix'])->asString()); | ||
$this->assertEquals($iban, strval($this->getIban($accountData['acc'], $accountData['bank'], $accountData['prefix']))); | ||
} | ||
} | ||
|
||
public function testGetValidator() | ||
{ | ||
$this->assertInstanceOf(ValidatorInterface::class, $this->getIban(1325090010, 3030)->getValidator()); | ||
} | ||
|
||
/** | ||
* @param string|int $account | ||
* @param string|int $bankCode | ||
* @param string|int|null $prefix | ||
* | ||
* @return CzechIbanAdapter | ||
*/ | ||
private function getIban($account, $bankCode, $prefix = null): CzechIbanAdapter | ||
{ | ||
if (!is_null($prefix)) { | ||
$account = "{$prefix}-{$account}"; | ||
} | ||
$ibanAdapter = new CzechIbanAdapter($account, $bankCode); | ||
|
||
return $ibanAdapter; | ||
} | ||
} | ||
<?php | ||
|
||
namespace rikudou\EuQrPayment\Tests\Iban; | ||
|
||
use rikudou\EuQrPayment\Iban\CzechIbanAdapter; | ||
use PHPUnit\Framework\TestCase; | ||
use rikudou\EuQrPayment\Iban\Validator\ValidatorInterface; | ||
|
||
class CzechIbanAdapterTest extends TestCase | ||
{ | ||
public function testAccountsWithoutPrefix() | ||
{ | ||
$accounts = [ | ||
'CZ55 3030 0000 0013 2509 0010' => [ | ||
'acc' => '1325090010', | ||
'bank' => '3030', | ||
], | ||
'CZ36 3030 0000 0013 2509 0061' => [ | ||
'acc' => '1325090061', | ||
'bank' => '3030', | ||
], | ||
'CZ91 0300 0000 0002 8111 5217' => [ | ||
'acc' => '281115217', | ||
'bank' => '0300', | ||
], | ||
'CZ52 0300 0000 0000 0398 3815' => [ | ||
'acc' => '3983815', | ||
'bank' => '0300', | ||
], | ||
'CZ13 2700 0000 0005 0011 4004' => [ | ||
'acc' => '500114004', | ||
'bank' => '2700', | ||
], | ||
]; | ||
|
||
foreach ($accounts as $iban => $accountData) { | ||
$iban = str_replace(' ', '', $iban); | ||
$this->assertEquals($iban, $this->getIban($accountData['acc'], $accountData['bank'])->asString()); | ||
$this->assertEquals($iban, strval($this->getIban($accountData['acc'], $accountData['bank']))); | ||
} | ||
} | ||
|
||
public function testAccountsWithPrefix() | ||
{ | ||
$accounts = [ | ||
'CZ03 0710 0010 1100 1792 9051' => [ | ||
'acc' => '17929051', | ||
'bank' => '0710', | ||
'prefix' => '1011', | ||
], | ||
'CZ47 0710 0210 1200 2792 4051' => [ | ||
'acc' => '27924051', | ||
'bank' => '0710', | ||
'prefix' => '21012', | ||
], | ||
]; | ||
|
||
foreach ($accounts as $iban => $accountData) { | ||
$iban = str_replace(' ', '', $iban); | ||
$this->assertEquals($iban, $this->getIban($accountData['acc'], $accountData['bank'], $accountData['prefix'])->asString()); | ||
$this->assertEquals($iban, strval($this->getIban($accountData['acc'], $accountData['bank'], $accountData['prefix']))); | ||
} | ||
} | ||
|
||
public function testGetValidator() | ||
{ | ||
$this->assertInstanceOf(ValidatorInterface::class, $this->getIban(1325090010, 3030)->getValidator()); | ||
} | ||
|
||
/** | ||
* @param string|int $account | ||
* @param string|int $bankCode | ||
* @param string|int|null $prefix | ||
* | ||
* @return CzechIbanAdapter | ||
*/ | ||
private function getIban($account, $bankCode, $prefix = null): CzechIbanAdapter | ||
{ | ||
if (!is_null($prefix)) { | ||
$account = "{$prefix}-{$account}"; | ||
} | ||
$ibanAdapter = new CzechIbanAdapter($account, $bankCode); | ||
|
||
return $ibanAdapter; | ||
} | ||
} |
Oops, something went wrong.