From 2f3c6541ff68a598a213b0318f3564d1fc6ff385 Mon Sep 17 00:00:00 2001 From: Ari Selseng Date: Sun, 28 Jun 2020 21:38:50 +0200 Subject: [PATCH] Fix getAllPrefixes returning int for some keys Make tests nicer --- composer.json | 1 - composer.lock | 2 +- src/NorwegianBanks.php | 2 +- tests/NorwegianBanksTest.php | 22 ++++++++++++---------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 639c393..f35dac7 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index 40236f5..08c7d6e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3973d7f39e3bbc6d36da295d619e5b04", + "content-hash": "f8e17f9feccc9d102e2a6d974e231e95", "packages": [ { "name": "desarrolla2/cache", diff --git a/src/NorwegianBanks.php b/src/NorwegianBanks.php index 5558282..70e273d 100644 --- a/src/NorwegianBanks.php +++ b/src/NorwegianBanks.php @@ -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() diff --git a/tests/NorwegianBanksTest.php b/tests/NorwegianBanksTest.php index fb9d3a4..0aaa7e1 100644 --- a/tests/NorwegianBanksTest.php +++ b/tests/NorwegianBanksTest.php @@ -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' @@ -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)); @@ -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() {