From d733fda62798f1dee78cf0f96e9a81276d8643c9 Mon Sep 17 00:00:00 2001 From: Jonathan Martz Date: Sun, 12 Jan 2025 13:06:21 +0100 Subject: [PATCH] add tests for simple user and users with filter by name --- tests/CollectionTest.php | 42 +++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index 0284f51..f508f34 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -3,14 +3,38 @@ use PHPUnit\Framework\TestCase; final class CollectionTest extends TestCase { - public function test(): void + private $url; + + protected function setUp(): void { - $expected = []; - - $url = 'https://admin.pocketbase.dev'; - $collection = new \Pb\Collection($url, 'users'); - $actual = $collection->getList(1,10); - - $this->assertSame($expected, $actual); + $this->url = getenv('POCKETBASE_URL') ?: 'https://admin.pocketbase.dev'; } -} + + public function test_givenUrlAndCollectionNameUsers_thenCheckEmptyResult(): void + { + $collection = new \Pb\Collection($this->url, 'users'); + $actual = $collection->getList(1, 10); + + $this->assertTrue(array_key_exists('items', $actual), 'Key "items" does not exist in the response.'); + $this->assertTrue(array_key_exists('page', $actual), 'Key "page" does not exist in the response.'); + $this->assertTrue(array_key_exists('perPage', $actual), 'Key "perPage" does not exist in the response.'); + $this->assertTrue(array_key_exists('totalItems', $actual), 'Key "totalItems" does not exist in the response.'); + $this->assertTrue(array_key_exists('totalPages', $actual), 'Key "totalPages" does not exist in the response.'); + $this->assertCount(0, $actual['items'], 'Expected no items in the response.'); + } + + public function test_givenFilterByName_thenCheckEmptyResult(): void + { + $collection = new \Pb\Collection($this->url, 'users', [ + 'filter' => 'name ~ "%Jonathan%"' + ]); + $actual = $collection->getList(1, 10); + + $this->assertTrue(array_key_exists('items', $actual), 'Key "items" does not exist in the response.'); + $this->assertTrue(array_key_exists('page', $actual), 'Key "page" does not exist in the response.'); + $this->assertTrue(array_key_exists('perPage', $actual), 'Key "perPage" does not exist in the response.'); + $this->assertTrue(array_key_exists('totalItems', $actual), 'Key "totalItems" does not exist in the response.'); + $this->assertTrue(array_key_exists('totalPages', $actual), 'Key "totalPages" does not exist in the response.'); + $this->assertCount(0, $actual['items'], 'Expected no items in the response.'); + } +} \ No newline at end of file