Skip to content

Commit

Permalink
Merge pull request #15 from paynl/unittests
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
woutse authored Feb 3, 2025
2 parents b6822df + cf8e1ba commit 2e2d093
Show file tree
Hide file tree
Showing 20 changed files with 1,274 additions and 840 deletions.
72 changes: 72 additions & 0 deletions Tests/Unit/OrderAbortRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Tests\Unit;

use PayNL\Sdk\Model\Pay\PayOrder;
use PayNL\Sdk\Model\Request\OrderAbortRequest;
use PHPUnit\Framework\TestCase;

class OrderAbortRequestTest extends TestCase
{
/**
* @return void
*/
public function testConstructor(): void
{
$transactionId = '123456';
$orderAbortRequest = new OrderAbortRequest($transactionId);

$this->assertInstanceOf(OrderAbortRequest::class, $orderAbortRequest);
}

/**
* @return void
*/
public function testGetPathParameters(): void
{
$transactionId = '123456';
$orderAbortRequest = new OrderAbortRequest($transactionId);

$pathParameters = $orderAbortRequest->getPathParameters();

$this->assertIsArray($pathParameters);
$this->assertArrayHasKey('transactionId', $pathParameters);
$this->assertSame($transactionId, $pathParameters['transactionId']);
}

/**
* @return void
*/
public function testGetBodyParameters(): void
{
$transactionId = '123456';
$orderAbortRequest = new OrderAbortRequest($transactionId);

$bodyParameters = $orderAbortRequest->getBodyParameters();

$this->assertIsArray($bodyParameters);
$this->assertEmpty($bodyParameters);
}

/**
* @return void
* @throws \PHPUnit\Framework\MockObject\Exception
* @throws \PayNL\Sdk\Exception\PayException
*/
public function testStart(): void
{
$transactionId = '123456';
$orderAbortRequest = $this->getMockBuilder(OrderAbortRequest::class)
->setConstructorArgs([$transactionId])
->onlyMethods(['start'])
->getMock();

$mockPayOrder = $this->createMock(PayOrder::class);

$orderAbortRequest->method('start')->willReturn($mockPayOrder);

$result = $orderAbortRequest->start();

$this->assertInstanceOf(PayOrder::class, $result);
}
}
72 changes: 72 additions & 0 deletions Tests/Unit/OrderApproveRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Tests\Unit;

use PayNL\Sdk\Model\Pay\PayOrder;
use PayNL\Sdk\Model\Request\OrderApproveRequest;
use PHPUnit\Framework\TestCase;

class OrderApproveRequestTest extends TestCase
{
/**
* @return void
*/
public function testConstructor(): void
{
$transactionId = '123456';
$orderApproveRequest = new OrderApproveRequest($transactionId);

$this->assertInstanceOf(OrderApproveRequest::class, $orderApproveRequest);
}

/**
* @return void
*/
public function testGetPathParameters(): void
{
$transactionId = '123456';
$orderApproveRequest = new OrderApproveRequest($transactionId);

$pathParameters = $orderApproveRequest->getPathParameters();

$this->assertIsArray($pathParameters);
$this->assertArrayHasKey('transactionId', $pathParameters);
$this->assertSame($transactionId, $pathParameters['transactionId']);
}

/**
* @return void
*/
public function testGetBodyParameters(): void
{
$transactionId = '123456';
$orderApproveRequest = new OrderApproveRequest($transactionId);

$bodyParameters = $orderApproveRequest->getBodyParameters();

$this->assertIsArray($bodyParameters);
$this->assertEmpty($bodyParameters);
}

/**
* @return void
* @throws \PHPUnit\Framework\MockObject\Exception
* @throws \PayNL\Sdk\Exception\PayException
*/
public function testStart(): void
{
$transactionId = '123456';
$orderApproveRequest = $this->getMockBuilder(OrderApproveRequest::class)
->setConstructorArgs([$transactionId])
->onlyMethods(['start'])
->getMock();

$mockPayOrder = $this->createMock(PayOrder::class);

$orderApproveRequest->method('start')->willReturn($mockPayOrder);

$result = $orderApproveRequest->start();

$this->assertInstanceOf(PayOrder::class, $result);
}
}
124 changes: 124 additions & 0 deletions Tests/Unit/OrderCaptureRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Tests\Unit;

use PayNL\Sdk\Model\Pay\PayOrder;
use PayNL\Sdk\Model\Request\OrderCaptureRequest;
use PHPUnit\Framework\TestCase;

class OrderCaptureRequestTest extends TestCase
{
/**
* @return void
*/
public function testConstructor(): void
{
$transactionId = '123456';
$amount = 100.50;
$orderCaptureRequest = new OrderCaptureRequest($transactionId, $amount);

$this->assertInstanceOf(OrderCaptureRequest::class, $orderCaptureRequest);
}

/**
* @return void
*/
public function testGetPathParameters(): void
{
$transactionId = '123456';
$orderCaptureRequest = new OrderCaptureRequest($transactionId);

$pathParameters = $orderCaptureRequest->getPathParameters();

$this->assertIsArray($pathParameters);
$this->assertArrayHasKey('transactionId', $pathParameters);
$this->assertSame($transactionId, $pathParameters['transactionId']);
}

/**
* @return void
*/
public function testGetBodyParametersWithAmount(): void
{
$transactionId = '123456';
$amount = 150.75;
$orderCaptureRequest = new OrderCaptureRequest($transactionId, $amount);

$bodyParameters = $orderCaptureRequest->getBodyParameters();

$this->assertIsArray($bodyParameters);
$this->assertArrayHasKey('amount', $bodyParameters);
$this->assertSame((int)round($amount * 100), $bodyParameters['amount']);
}

/**
* @return void
*/
public function testSetProduct(): void
{
$transactionId = '123456';
$orderCaptureRequest = new OrderCaptureRequest($transactionId);

$productId = 'prod-001';
$quantity = 2;

$orderCaptureRequest->setProduct($productId, $quantity);

$bodyParameters = $orderCaptureRequest->getBodyParameters();

$this->assertIsArray($bodyParameters);
$this->assertArrayHasKey('products', $bodyParameters);
$this->assertCount(1, $bodyParameters['products']);
$this->assertSame($productId, $bodyParameters['products'][0]['id']);
$this->assertSame($quantity, $bodyParameters['products'][0]['quantity']);
}

/**
* @return void
* @throws \PHPUnit\Framework\MockObject\Exception
* @throws \PayNL\Sdk\Exception\PayException
*/
public function testStartWithAmount(): void
{
$transactionId = '123456';
$amount = 200.00;
$orderCaptureRequest = $this->getMockBuilder(OrderCaptureRequest::class)
->setConstructorArgs([$transactionId, $amount])
->onlyMethods(['start'])
->getMock();

$mockPayOrder = $this->createMock(PayOrder::class);

$orderCaptureRequest->method('start')->willReturn($mockPayOrder);

$result = $orderCaptureRequest->start();

$this->assertInstanceOf(PayOrder::class, $result);
}

/**
* @return void
* @throws \PHPUnit\Framework\MockObject\Exception
* @throws \PayNL\Sdk\Exception\PayException
*/
public function testStartWithProduct(): void
{
$transactionId = '123456';
$orderCaptureRequest = $this->getMockBuilder(OrderCaptureRequest::class)
->setConstructorArgs([$transactionId])
->onlyMethods(['start'])
->getMock();

$productId = 'prod-002';
$quantity = 3;
$orderCaptureRequest->setProduct($productId, $quantity);

$mockPayOrder = $this->createMock(PayOrder::class);

$orderCaptureRequest->method('start')->willReturn($mockPayOrder);

$result = $orderCaptureRequest->start();

$this->assertInstanceOf(PayOrder::class, $result);
}
}
Loading

0 comments on commit 2e2d093

Please sign in to comment.