Skip to content

Commit

Permalink
Fix getAllPrefixes returning int for some keys
Browse files Browse the repository at this point in the history
Make tests nicer
  • Loading branch information
ariselseng committed Jun 28, 2020
1 parent 7ca8f39 commit 2f3c654
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "ariselseng/norwegianbanks",
"description": "Library to get information about norwegian banks and validate accounts",
"license": "MIT",
"version": "0.6",
"minimum-stability": "stable",
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/NorwegianBanks.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function validateAccountNumber(string $account, bool $validateBankPrefix

public function getAllPrefixes()
{
return array_keys($this->prefixToBankCode);
return array_map('strval', array_keys($this->prefixToBankCode));
}

public function getAllBanks()
Expand Down
22 changes: 12 additions & 10 deletions tests/NorwegianBanksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

class NorwegianBanksTest extends TestCase
{
private $norwegianBanks;
protected $notRealAccountNumber = '1234.56.78903';
protected $notRealAccountNumberWithSpaces = '1234 56 78903';
protected $notRealAccountNumberUnformatted = '12345678903';
protected $accountNumberWithZeroCheckDigit = '0101.01.04900';
private NorwegianBanks $norwegianBanks;
protected string $notRealAccountNumber = '1234.56.78903';
protected string $notRealAccountNumberWithSpaces = '1234 56 78903';
protected string $notRealAccountNumberUnformatted = '12345678903';
protected string $accountNumberWithZeroCheckDigit = '0101.01.04900';

protected $accounts = [
protected array $accounts = [
[
'bankCode' => 'DNBANOKK',
'number' => '1594 22 87248'
Expand Down Expand Up @@ -53,8 +53,8 @@ public function testGetBankByAccountNumber()
{

foreach ($this->accounts as $account) {
$this->assertAttributeEquals($account['bankCode'], 'bankCode', $this->norwegianBanks->getBankByAccountNumber($account['number']));
$this->assertAttributeEquals($account['bankCode'], 'bankCode', NorwegianBanksStatic::getBankByAccountNumber($account['number']));
$this->assertEquals($account['bankCode'], $this->norwegianBanks->getBankByAccountNumber($account['number'])->bankCode);
$this->assertEquals($account['bankCode'], NorwegianBanksStatic::getBankByAccountNumber($account['number'])->bankCode);
}

$this->assertEquals(null, $this->norwegianBanks->getBankByAccountNumber($this->notRealAccountNumber));
Expand All @@ -75,8 +75,10 @@ public function testValidate()
public function testGetAllPrefixes() {
$prefixes = $this->norwegianBanks->getAllPrefixes();
$this->assertIsArray($prefixes);
$this->assertNotContains('Bank identifier', $prefixes);
$this->assertContains('1594', $prefixes);
$this->assertNotCount(0, $prefixes);
$this->assertContainsOnly('string', $prefixes);
$this->assertFalse(in_array('Bank identifier', $prefixes, true));
$this->assertTrue(in_array('1594', $prefixes, true));
}

public function testGetAllBanks() {
Expand Down

0 comments on commit 2f3c654

Please # to comment.