From 86d47531b534810adcd04098114917a00f6b224e Mon Sep 17 00:00:00 2001 From: MBaran Date: Thu, 23 Feb 2023 12:58:07 +0100 Subject: [PATCH 1/2] SP-453 - PHP - Allow null selectedWallet --- src/BitPaySDK/Model/Invoice/BuyerProvidedInfo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BitPaySDK/Model/Invoice/BuyerProvidedInfo.php b/src/BitPaySDK/Model/Invoice/BuyerProvidedInfo.php index 3735eae7..bb713765 100644 --- a/src/BitPaySDK/Model/Invoice/BuyerProvidedInfo.php +++ b/src/BitPaySDK/Model/Invoice/BuyerProvidedInfo.php @@ -77,7 +77,7 @@ public function setPhoneNumber($phoneNumber) * * This field contains the name of the cryptocurrency wallet selected by the shopper to complete the payment. * - * @return string the selected wallet + * @return string|null the selected wallet */ public function getSelectedWallet() { @@ -89,9 +89,9 @@ public function getSelectedWallet() * * This field contains the name of the cryptocurrency wallet selected by the shopper to complete the payment. * - * @param string $selectedWallet the selected wallet + * @param string|null $selectedWallet the selected wallet */ - public function setSelectedWallet(string $selectedWallet) + public function setSelectedWallet(?string $selectedWallet) { $this->_selectedWallet = $selectedWallet; } From 64cbe0051ae360584e6daf5e32fe799237f830cf Mon Sep 17 00:00:00 2001 From: MBaran Date: Thu, 23 Feb 2023 15:57:44 +0100 Subject: [PATCH 2/2] SP-453 - Updated tests --- .../Model/Invoice/BuyerProvidedInfoTest.php | 265 +++++++++--------- 1 file changed, 140 insertions(+), 125 deletions(-) diff --git a/test/unit/BitPaySDK/Model/Invoice/BuyerProvidedInfoTest.php b/test/unit/BitPaySDK/Model/Invoice/BuyerProvidedInfoTest.php index 23d7358e..899caa41 100644 --- a/test/unit/BitPaySDK/Model/Invoice/BuyerProvidedInfoTest.php +++ b/test/unit/BitPaySDK/Model/Invoice/BuyerProvidedInfoTest.php @@ -1,133 +1,148 @@ createClassObject(); - $this->assertInstanceOf(BuyerProvidedInfo::class, $buyerProvidedInfo); - } - - public function testGetName() - { - $expectedName = 'Test User'; - - $buyerProvidedInfo = $this->createClassObject(); - $buyerProvidedInfo->setName($expectedName); - $this->assertEquals($expectedName, $buyerProvidedInfo->getName()); - } - - public function testGetPhoneNumber() - { - $expectedPhoneNumber = '1112223333'; - - $buyerProvidedInfo = $this->createClassObject(); - $buyerProvidedInfo->setPhoneNumber($expectedPhoneNumber); - $this->assertEquals($expectedPhoneNumber, $buyerProvidedInfo->getPhoneNumber()); - } - - public function testGetSelectedWallet() - { - $expectedSelectedWallet = 'bitpay'; - - $buyerProvidedInfo = $this->createClassObject(); - $buyerProvidedInfo->setSelectedWallet($expectedSelectedWallet); - $this->assertEquals($expectedSelectedWallet, $buyerProvidedInfo->getSelectedWallet()); - } - - public function testGetEmailAddress() - { - $expectedEmailAddress = 'example@bitpay.com'; - - $buyerProvidedInfo = $this->createClassObject(); - $buyerProvidedInfo->setEmailAddress($expectedEmailAddress); - $this->assertEquals($expectedEmailAddress, $buyerProvidedInfo->getEmailAddress()); - } - - public function testGetSelectedTransactionCurrency() - { - $expectedSelectedTransactionCurrency = 'BTC'; - - $buyerProvidedInfo = $this->createClassObject(); - $buyerProvidedInfo->setSelectedTransactionCurrency($expectedSelectedTransactionCurrency); - $this->assertEquals($expectedSelectedTransactionCurrency, $buyerProvidedInfo->getSelectedTransactionCurrency()); - } - - public function testGetSms() - { - $expectedSms = '4445556666'; - - $buyerProvidedInfo = $this->createClassObject(); - $buyerProvidedInfo->setSms($expectedSms); - $this->assertEquals($expectedSms, $buyerProvidedInfo->getSms()); - } - - public function testGetSmsVerified() - { - $expectedSmsVerified = true; - - $buyerProvidedInfo = $this->createClassObject(); - $buyerProvidedInfo->setSmsVerified($expectedSmsVerified); - $this->assertEquals($expectedSmsVerified, $buyerProvidedInfo->getSmsVerified()); - } - - public function testToArray() - { - $buyerProvidedInfo = $this->createClassObject(); - $this->objectSetters($buyerProvidedInfo); - - $buyerProvidedInfoArray = $buyerProvidedInfo->toArray(); - - $this->assertNotNull($buyerProvidedInfoArray); - $this->assertIsArray($buyerProvidedInfoArray); - - $this->assertArrayHasKey('name', $buyerProvidedInfoArray); - $this->assertArrayHasKey('phoneNumber', $buyerProvidedInfoArray); - $this->assertArrayHasKey('selectedWallet', $buyerProvidedInfoArray); - $this->assertArrayHasKey('emailAddress', $buyerProvidedInfoArray); - $this->assertArrayHasKey('selectedTransactionCurrency', $buyerProvidedInfoArray); - $this->assertArrayHasKey('sms', $buyerProvidedInfoArray); - $this->assertArrayHasKey('smsVerified', $buyerProvidedInfoArray); - - $this->assertEquals($buyerProvidedInfoArray['name'], 'Test User'); - $this->assertEquals($buyerProvidedInfoArray['phoneNumber'], '1112223333'); - $this->assertEquals($buyerProvidedInfoArray['selectedWallet'], 'bitpay'); - $this->assertEquals($buyerProvidedInfoArray['emailAddress'], 'example@bitpay.com'); - $this->assertEquals($buyerProvidedInfoArray['selectedTransactionCurrency'], 'BTC'); - $this->assertEquals($buyerProvidedInfoArray['sms'], '4445556666'); - $this->assertEquals($buyerProvidedInfoArray['smsVerified'], true); - } - - public function testToArrayEmptyKey() - { - $buyerProvidedInfo = $this->createClassObject(); - - $buyerProvidedInfoArray = $buyerProvidedInfo->toArray(); - - $this->assertNotNull($buyerProvidedInfoArray); - $this->assertIsArray($buyerProvidedInfoArray); - - $this->assertArrayNotHasKey('name', $buyerProvidedInfoArray); - } - - private function createClassObject() - { - return new BuyerProvidedInfo(); - } - - private function objectSetters(BuyerProvidedInfo $buyerProvidedInfo) - { - $buyerProvidedInfo->setName('Test User'); - $buyerProvidedInfo->setPhoneNumber('1112223333'); - $buyerProvidedInfo->setSelectedWallet('bitpay'); - $buyerProvidedInfo->setEmailAddress('example@bitpay.com'); - $buyerProvidedInfo->setSelectedTransactionCurrency('BTC'); - $buyerProvidedInfo->setSms('4445556666'); - $buyerProvidedInfo->setSmsVerified(true); - } -} \ No newline at end of file + public function testInstanceOf() + { + $buyerProvidedInfo = $this->createClassObject(); + $this->assertInstanceOf(BuyerProvidedInfo::class, $buyerProvidedInfo); + } + + public function testGetName() + { + $expectedName = 'Test User'; + + $buyerProvidedInfo = $this->createClassObject(); + $buyerProvidedInfo->setName($expectedName); + $this->assertEquals($expectedName, $buyerProvidedInfo->getName()); + } + + public function testGetPhoneNumber() + { + $expectedPhoneNumber = '1112223333'; + + $buyerProvidedInfo = $this->createClassObject(); + $buyerProvidedInfo->setPhoneNumber($expectedPhoneNumber); + $this->assertEquals($expectedPhoneNumber, $buyerProvidedInfo->getPhoneNumber()); + } + + public function testGetSelectedWallet() + { + $expectedSelectedWallet = 'bitpay'; + + $buyerProvidedInfo = $this->createClassObject(); + $buyerProvidedInfo->setSelectedWallet($expectedSelectedWallet); + $this->assertEquals($expectedSelectedWallet, $buyerProvidedInfo->getSelectedWallet()); + } + + /** + * https://github.com/bitpay/php-bitpay-client-v2/issues/212 + * + * @return void + */ + public function testGetSelectedWalletAsNull() + { + $expectedSelectedWallet = null; + + $buyerProvidedInfo = $this->createClassObject(); + $buyerProvidedInfo->setSelectedWallet($expectedSelectedWallet); + + $this->assertNull($buyerProvidedInfo->getSelectedWallet()); + } + + public function testGetEmailAddress() + { + $expectedEmailAddress = 'example@bitpay.com'; + + $buyerProvidedInfo = $this->createClassObject(); + $buyerProvidedInfo->setEmailAddress($expectedEmailAddress); + $this->assertEquals($expectedEmailAddress, $buyerProvidedInfo->getEmailAddress()); + } + + public function testGetSelectedTransactionCurrency() + { + $expectedSelectedTransactionCurrency = 'BTC'; + + $buyerProvidedInfo = $this->createClassObject(); + $buyerProvidedInfo->setSelectedTransactionCurrency($expectedSelectedTransactionCurrency); + $this->assertEquals($expectedSelectedTransactionCurrency, $buyerProvidedInfo->getSelectedTransactionCurrency()); + } + + public function testGetSms() + { + $expectedSms = '4445556666'; + + $buyerProvidedInfo = $this->createClassObject(); + $buyerProvidedInfo->setSms($expectedSms); + $this->assertEquals($expectedSms, $buyerProvidedInfo->getSms()); + } + + public function testGetSmsVerified() + { + $expectedSmsVerified = true; + + $buyerProvidedInfo = $this->createClassObject(); + $buyerProvidedInfo->setSmsVerified($expectedSmsVerified); + $this->assertEquals($expectedSmsVerified, $buyerProvidedInfo->getSmsVerified()); + } + + public function testToArray() + { + $buyerProvidedInfo = $this->createClassObject(); + $this->objectSetters($buyerProvidedInfo); + + $buyerProvidedInfoArray = $buyerProvidedInfo->toArray(); + + $this->assertNotNull($buyerProvidedInfoArray); + $this->assertIsArray($buyerProvidedInfoArray); + + $this->assertArrayHasKey('name', $buyerProvidedInfoArray); + $this->assertArrayHasKey('phoneNumber', $buyerProvidedInfoArray); + $this->assertArrayHasKey('selectedWallet', $buyerProvidedInfoArray); + $this->assertArrayHasKey('emailAddress', $buyerProvidedInfoArray); + $this->assertArrayHasKey('selectedTransactionCurrency', $buyerProvidedInfoArray); + $this->assertArrayHasKey('sms', $buyerProvidedInfoArray); + $this->assertArrayHasKey('smsVerified', $buyerProvidedInfoArray); + + $this->assertEquals($buyerProvidedInfoArray['name'], 'Test User'); + $this->assertEquals($buyerProvidedInfoArray['phoneNumber'], '1112223333'); + $this->assertEquals($buyerProvidedInfoArray['selectedWallet'], 'bitpay'); + $this->assertEquals($buyerProvidedInfoArray['emailAddress'], 'example@bitpay.com'); + $this->assertEquals($buyerProvidedInfoArray['selectedTransactionCurrency'], 'BTC'); + $this->assertEquals($buyerProvidedInfoArray['sms'], '4445556666'); + $this->assertEquals($buyerProvidedInfoArray['smsVerified'], true); + } + + public function testToArrayEmptyKey() + { + $buyerProvidedInfo = $this->createClassObject(); + + $buyerProvidedInfoArray = $buyerProvidedInfo->toArray(); + + $this->assertNotNull($buyerProvidedInfoArray); + $this->assertIsArray($buyerProvidedInfoArray); + + $this->assertArrayNotHasKey('name', $buyerProvidedInfoArray); + } + + private function createClassObject() + { + return new BuyerProvidedInfo(); + } + + private function objectSetters(BuyerProvidedInfo $buyerProvidedInfo) + { + $buyerProvidedInfo->setName('Test User'); + $buyerProvidedInfo->setPhoneNumber('1112223333'); + $buyerProvidedInfo->setSelectedWallet('bitpay'); + $buyerProvidedInfo->setEmailAddress('example@bitpay.com'); + $buyerProvidedInfo->setSelectedTransactionCurrency('BTC'); + $buyerProvidedInfo->setSms('4445556666'); + $buyerProvidedInfo->setSmsVerified(true); + } +}