Skip to content
Open
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
53 changes: 53 additions & 0 deletions Tests/Unit/Model/AmountTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Tests\Unit\Model;

use PayNL\Sdk\Model\Amount;
use PHPUnit\Framework\TestCase;

class AmountTest extends TestCase
{
/**
* @return void
* @throws \Exception
*/
public function testConstructFromFloat(): void
{
$money = Amount::fromFloat(123.45);
$this->assertEquals(12345, $money->getValue());
$this->assertEquals('EUR', $money->getCurrency());
}

/**
* @return void
* @throws \Exception
*/
public function testConstructFromFloatWithCurrency(): void
{
$money = Amount::fromFloat(123, 'USD');
$this->assertEquals(12300, $money->getValue());
$this->assertEquals('USD', $money->getCurrency());
}

/**
* @return void
* @throws \Exception
*/
public function testConstructFromCents(): void
{
$money = Amount::fromCents(12345);
$this->assertEquals(12345, $money->getValue());
$this->assertEquals('EUR', $money->getCurrency());
}

/**
* @return void
* @throws \Exception
*/
public function testConstructFromCentsWithCurrency(): void
{
$money = Amount::fromCents(123, 'USD');
$this->assertEquals(123, $money->getValue());
$this->assertEquals('USD', $money->getCurrency());
}
}
20 changes: 20 additions & 0 deletions Tests/Unit/OrderCreateRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Unit;

use PayNL\Sdk\Model\Amount;
use PayNL\Sdk\Model\Customer;
use PayNL\Sdk\Model\Order;
use PayNL\Sdk\Model\Request\OrderCreateRequest;
Expand Down Expand Up @@ -62,6 +63,25 @@ public function testSetAmount(): void
$this->assertEquals(12345, $amountProperty->getValue($request));
}

/**
* @return void
*/
public function testSetAmountUsingObject(): void
{
$request = new OrderCreateRequest();
$request->setAmount(new Amount(12345, 'EUR'));

$reflection = new \ReflectionClass($request);
$amountProperty = $reflection->getProperty('amount');
$amountProperty->setAccessible(true);

$currencyProperty = $reflection->getProperty('currency');
$currencyProperty->setAccessible(true);

$this->assertEquals(12345, $amountProperty->getValue($request));
$this->assertEquals('EUR', $currencyProperty->getValue($request));
}

/**
* @return void
* @throws \Exception
Expand Down
Loading