Skip to content

Commit

Permalink
add CursorCollectionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Oct 30, 2023
1 parent 1e54ac4 commit 68c204e
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions tests/Mollie/API/Resources/CursorCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Tests\Mollie\API\Resources;

use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\OrderCollection;
use PHPUnit\Framework\TestCase;

class CursorCollectionTest extends TestCase
{
public function testCanGetNextCollectionResultWhenNextLinkIsAvailable()
{
$mockedClient = $this->createMock(MollieApiClient::class);
$mockedClient->expects($this->once())
->method('performHttpCallToFullUrl')
->willReturn((object) [
'count' => 1,
'_links' => (object) [
'self' => [
'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS',
],
],
'_embedded' => (object) [
'orders' => [
(object) ['id' => 'ord_stTC2WHAuS'],
],
],
]);

$collection = new OrderCollection(
$mockedClient,
1,
(object) [
'next' => (object) [
'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS',
],
]
);

$this->assertTrue($collection->hasNext());

$nextPage = $collection->next();

$this->assertEquals('ord_stTC2WHAuS', $nextPage[0]->id);

$this->assertFalse($nextPage->hasNext());
}

public function testWillReturnNullIfNoNextResultIsAvailable()
{
$mockedClient = $this->createMock(MollieApiClient::class);
$collection = new OrderCollection(
$mockedClient,
1,
(object) []
);

$this->assertFalse($collection->hasNext());
$this->assertNull($collection->next());
}

public function testCanGetPreviousCollectionResultWhenPreviousLinkIsAvailable()
{
$mockedClient = $this->createMock(MollieApiClient::class);
$mockedClient->expects($this->once())
->method('performHttpCallToFullUrl')
->willReturn((object) [
'count' => 1,
'_links' => (object) [
'self' => [
'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS',
],
],
'_embedded' => (object) [
'orders' => [
(object) ['id' => 'ord_stTC2WHAuS'],
],
],
]);

$collection = new OrderCollection(
$mockedClient,
1,
(object) [
'previous' => (object) [
'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS',
],
]
);

$this->assertTrue($collection->hasPrevious());

$previousPage = $collection->previous();

$this->assertEquals('ord_stTC2WHAuS', $previousPage[0]->id);

$this->assertFalse($previousPage->hasPrevious());
}

public function testWillReturnNullIfNoPreviousResultIsAvailable()
{
$mockedClient = $this->createMock(MollieApiClient::class);
$collection = new OrderCollection(
$mockedClient,
1,
(object) []
);

$this->assertFalse($collection->hasPrevious());
$this->assertNull($collection->previous());
}
}

0 comments on commit 68c204e

Please sign in to comment.