Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/BitPaySDK/Model/Invoice/BuyerProvidedInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
}
Expand Down
265 changes: 140 additions & 125 deletions test/unit/BitPaySDK/Model/Invoice/BuyerProvidedInfoTest.php
Original file line number Diff line number Diff line change
@@ -1,133 +1,148 @@
<?php

namespace BitPaySDK\Test;
namespace BitPaySDK\Test\Model\Invoice;

use BitPaySDK\Model\Invoice\BuyerProvidedInfo;
use PHPUnit\Framework\TestCase;

class BuyerProvidedInfoTest extends TestCase
{
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());
}

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);
}
}
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);
}
}