Skip to content

Commit

Permalink
SP-735 Type Review: PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarzybok-sumoheavy committed Dec 11, 2023
1 parent aa200c7 commit fab422b
Show file tree
Hide file tree
Showing 10 changed files with 564 additions and 164 deletions.
30 changes: 15 additions & 15 deletions src/BitPaySDK/Model/Invoice/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class Invoice
protected bool $extendedNotifications = false;
protected ?bool $isCancelled = null;
protected ?string $transactionCurrency = null;
protected ?int $underpaidAmount = null;
protected ?int $overpaidAmount = null;
protected ?int $amountPaid = null;
protected ?float $underpaidAmount = null;
protected ?float $overpaidAmount = null;
protected ?float $amountPaid = null;
protected ?string $displayAmountPaid = null;
protected ?array $exchangeRates = null;
protected ?bool $bitpayIdRequired = null;
Expand Down Expand Up @@ -1455,9 +1455,9 @@ public function setPaymentCodes(?array $paymentCodes)
* It equals to the absolute difference between amountPaid
* and paymentTotals for the corresponding transactionCurrency used.
*
* @return int|null
* @return float|null
*/
public function getUnderpaidAmount(): ?int
public function getUnderpaidAmount(): ?float
{
return $this->underpaidAmount;
}
Expand All @@ -1470,9 +1470,9 @@ public function getUnderpaidAmount(): ?int
* It equals to the absolute difference between amountPaid
* and paymentTotals for the corresponding transactionCurrency used.
*
* @param int $underpaidAmount the underpaid amount
* @param float|null $underpaidAmount the underpaid amount
*/
public function setUnderpaidAmount(int $underpaidAmount): void
public function setUnderpaidAmount(?float $underpaidAmount): void
{
$this->underpaidAmount = $underpaidAmount;
}
Expand All @@ -1485,9 +1485,9 @@ public function setUnderpaidAmount(int $underpaidAmount): void
* It equals to the absolute difference between amountPaid
* and paymentTotals for the corresponding transactionCurrency used.
*
* @return int|null
* @return float|null
*/
public function getOverpaidAmount(): ?int
public function getOverpaidAmount(): ?float
{
return $this->overpaidAmount;
}
Expand All @@ -1500,9 +1500,9 @@ public function getOverpaidAmount(): ?int
* It equals to the absolute difference between amountPaid
* and paymentTotals for the corresponding transactionCurrency used.
*
* @param int $overpaidAmount the overpaid amount
* @param float|null $overpaidAmount the overpaid amount
*/
public function setOverpaidAmount(int $overpaidAmount): void
public function setOverpaidAmount(?float $overpaidAmount): void
{
$this->overpaidAmount = $overpaidAmount;
}
Expand Down Expand Up @@ -1714,9 +1714,9 @@ public function setTransactionCurrency(string $transactionCurrency): void
* The total amount paid to the invoice in terms of the invoice transactionCurrency indicated
* in the smallest possible unit for the corresponding transactionCurrency (e.g satoshis for BTC and BCH)
*
* @return int|null
* @return float|null
*/
public function getAmountPaid(): ?int
public function getAmountPaid(): ?float
{
return $this->amountPaid;
}
Expand All @@ -1727,9 +1727,9 @@ public function getAmountPaid(): ?int
* The total amount paid to the invoice in terms of the invoice transactionCurrency indicated
* in the smallest possible unit for the corresponding transactionCurrency (e.g satoshis for BTC and BCH)
*
* @param int $amountPaid The total amount paid to the invoice
* @param float|null $amountPaid The total amount paid to the invoice
*/
public function setAmountPaid(int $amountPaid): void
public function setAmountPaid(?float $amountPaid): void
{
$this->amountPaid = $amountPaid;
}
Expand Down
6 changes: 3 additions & 3 deletions src/BitPaySDK/Model/Invoice/InvoiceWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class InvoiceWebhook
protected ?array $paymentSubtotals;
protected ?array $paymentTotals;
protected ?array $exchangeRates;
protected ?int $amountPaid;
protected ?float $amountPaid;
protected ?string $orderId;
protected ?string $transactionCurrency;

Expand Down Expand Up @@ -163,12 +163,12 @@ public function setExchangeRates(?array $exchangeRates): void
$this->exchangeRates = $exchangeRates;
}

public function getAmountPaid(): ?int
public function getAmountPaid(): ?float
{
return $this->amountPaid;
}

public function setAmountPaid(?int $amountPaid): void
public function setAmountPaid(?float $amountPaid): void
{
$this->amountPaid = $amountPaid;
}
Expand Down
6 changes: 3 additions & 3 deletions src/BitPaySDK/Model/Invoice/RefundWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RefundWebhook
protected ?string $invoice = null;
protected ?string $supportRequest = null;
protected ?string $status = null;
protected ?int $amount = null;
protected ?float $amount = null;
protected ?string $currency = null;
protected ?string $lastRefundNotification = null;
protected ?float $refundFee = null;
Expand Down Expand Up @@ -70,12 +70,12 @@ public function setStatus(?string $status): void
$this->status = $status;
}

public function getAmount(): ?int
public function getAmount(): ?float
{
return $this->amount;
}

public function setAmount(?int $amount): void
public function setAmount(?float $amount): void
{
$this->amount = $amount;
}
Expand Down
8 changes: 8 additions & 0 deletions test/unit/BitPaySDK/Model/CurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ public function testGetDecimals()
self::assertEquals($expected, $currency->getDecimals());
}

public function testModifyChain(): void
{
$testedClass = $this->createClassObject();
$expected = 'someValue';
$testedClass->setChain($expected);

self::assertEquals($expected, $testedClass->getChain());
}

private function createClassObject(): Currency
{
Expand Down
1 change: 0 additions & 1 deletion test/unit/BitPaySDK/Model/Invoice/BuyerFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public function testManipulateBuyerZip(): void
self::assertEquals($expected, $testedClass->getBuyerZip());
}


private function getTestedClass(): BuyerFields
{
return new BuyerFields();
Expand Down
145 changes: 145 additions & 0 deletions test/unit/BitPaySDK/Model/Invoice/InvoiceWebhookTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

declare(strict_types=1);

namespace BitPaySDK\Test\Model\Invoice;

use BitPaySDK\Model\Invoice\BuyerFields;
use BitPaySDK\Model\Invoice\InvoiceWebhook;
use PHPUnit\Framework\TestCase;

class InvoiceWebhookTest extends TestCase
{
public function testManipulateAmountPaid(): void
{
$testedClass = $this->getTestedClass();
$expected = 12.23;
$testedClass->setAmountPaid($expected);
self::assertEquals($expected, $testedClass->getamountPaid());
}

public function testManipulateBuyerFields(): void
{
$testedClass = $this->getTestedClass();
$expected = new BuyerFields();
$testedClass->setBuyerFields($expected);
self::assertEquals($expected, $testedClass->getbuyerFields());
}

public function testManipulateCurrency(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setCurrency($expected);
self::assertEquals($expected, $testedClass->getCurrency());
}

public function testManipulateCurrencyTime(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setCurrencyTime($expected);
self::assertEquals($expected, $testedClass->getCurrencyTime());
}

public function testManipulateExceptionStatus(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setExceptionStatus($expected);
self::assertEquals($expected, $testedClass->getExceptionStatus());
}

public function testManipulateExchangeRates(): void
{
$testedClass = $this->getTestedClass();
$expected = [];
$testedClass->setExchangeRates($expected);
self::assertEquals($expected, $testedClass->getExchangeRates());
}

public function testManipulateId(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setid($expected);
self::assertEquals($expected, $testedClass->getId());
}

public function testManipulateInvoiceTime(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setInvoiceTime($expected);
self::assertEquals($expected, $testedClass->getInvoiceTime());
}

public function testManipulateOrderId(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setOrderId($expected);
self::assertEquals($expected, $testedClass->getOrderId());
}

public function testManipulate_paymentSubtotals(): void
{
$testedClass = $this->getTestedClass();
$expected = [];
$testedClass->setPaymentSubtotals($expected);
self::assertEquals($expected, $testedClass->getPaymentSubtotals());
}

public function testManipulatePaymentTotals(): void
{
$testedClass = $this->getTestedClass();
$expected = [];
$testedClass->setPaymentTotals($expected);
self::assertEquals($expected, $testedClass->getPaymentTotals());
}

public function testManipulatePosData(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setPosData($expected);
self::assertEquals($expected, $testedClass->getPosData());
}

public function testManipulatePrice(): void
{
$testedClass = $this->getTestedClass();
$expected = 123.78;
$testedClass->setPrice($expected);
self::assertEquals($expected, $testedClass->getPrice());
}

public function testManipulateStatus(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setStatus($expected);
self::assertEquals($expected, $testedClass->getStatus());
}

public function testManipulateTransactionCurrency(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setTransactionCurrency($expected);
self::assertEquals($expected, $testedClass->getTransactionCurrency());
}

public function testManipulateUrl(): void
{
$testedClass = $this->getTestedClass();
$expected = 'someValue';
$testedClass->setUrl($expected);
self::assertEquals($expected, $testedClass->getUrl());
}

private function getTestedClass(): InvoiceWebhook
{
return new InvoiceWebhook();
}
}
Loading

0 comments on commit fab422b

Please sign in to comment.