mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
refactoring code, add doRequest via httpClient
This commit is contained in:
38
tests/AuthTest.php
Normal file
38
tests/AuthTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Pb\Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class AuthTest extends TestCase
|
||||
{
|
||||
|
||||
private Collection $collection;
|
||||
private ?string $url;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->url = getenv('POCKETBASE_URL') ?: 'https://admin.pocketbase.dev';
|
||||
$this->collection = new Collection($this->url, 'users');
|
||||
}
|
||||
public function testAuthUser(): void
|
||||
{
|
||||
$this->expectException(ClientException::class);
|
||||
$this->collection->authAsUser('support@jonathan-martz.de', 'rockt');
|
||||
}
|
||||
|
||||
public function testAuthSuperUser(): void
|
||||
{
|
||||
$this->collection = new Collection($this->url, '_superusers');
|
||||
$this->expectException(ClientException::class);
|
||||
$this->collection->authAsAdmin('admin@jonathan-martz.de', 'rockt');
|
||||
}
|
||||
|
||||
public function testAuthSuperUser2(): void
|
||||
{
|
||||
$this->collection = new Collection($this->url, '_superusers');
|
||||
|
||||
$this->expectException(ClientException::class);
|
||||
$this->collection->authAsAdmin('admin@jmartz.de', 'rockt123?!');
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Pb\Collection;
|
||||
use Pb\Exception\FirstListItemNotFoundException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class CollectionGetFirstListItemTest extends TestCase
|
||||
@@ -13,43 +14,22 @@ final class CollectionGetFirstListItemTest extends TestCase
|
||||
$this->collection = new Collection($url, 'users');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FirstListItemNotFoundException
|
||||
*/
|
||||
public function test_getOne(): void
|
||||
{
|
||||
$id = '6588yk36406qqv1';
|
||||
$actual = $this->collection->getFirstListItem('id="'.$id.'"');
|
||||
$expected = [
|
||||
'avatar' => '',
|
||||
'collectionId' => '_pb_users_auth_',
|
||||
'collectionName' => 'users',
|
||||
'created' => '2025-01-21 21:22:47.002Z',
|
||||
'emailVisibility' => false,
|
||||
'id' => '6588yk36406qqv1',
|
||||
'name' => 'Jonathan Martz',
|
||||
'updated' => '2025-01-21 21:22:47.002Z',
|
||||
'verified' => true
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
$this->assertEquals($id, $actual['id']);
|
||||
$this->assertCount(9, $actual);
|
||||
}
|
||||
|
||||
public function test_getOneWrongId(): void
|
||||
{
|
||||
$id = '6588yk36406qqva';
|
||||
$actual = $this->collection->getFirstListItem('id="'.$id.'"');
|
||||
$expected = [
|
||||
'avatar' => '',
|
||||
'collectionId' => '_pb_users_auth_',
|
||||
'collectionName' => 'users',
|
||||
'created' => '2025-01-21 21:22:47.002Z',
|
||||
'emailVisibility' => false,
|
||||
'id' => '6588yk36406qqv1',
|
||||
'name' => 'Jonathan Martz',
|
||||
'updated' => '2025-01-21 21:22:47.002Z',
|
||||
'verified' => true
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
$this->assertCount(9,$actual);
|
||||
$id = '6588yk36406qqvb';
|
||||
$this->expectException(FirstListItemNotFoundException::class);
|
||||
$this->collection->getFirstListItem('id="'.$id.'"');
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Pb\Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -18,33 +19,17 @@ final class CollectionGetOneTest extends TestCase
|
||||
{
|
||||
$id = '6588yk36406qqv1';
|
||||
$actual = $this->collection->getOne($id);
|
||||
$expected = [
|
||||
'avatar' => '',
|
||||
'collectionId' => '_pb_users_auth_',
|
||||
'collectionName' => 'users',
|
||||
'created' => '2025-01-21 21:22:47.002Z',
|
||||
'emailVisibility' => false,
|
||||
'id' => '6588yk36406qqv1',
|
||||
'name' => 'Jonathan Martz',
|
||||
'updated' => '2025-01-21 21:22:47.002Z',
|
||||
'verified' => true
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
$this->assertEquals($id, $actual['id']);
|
||||
$this->assertCount(9, $actual);
|
||||
}
|
||||
|
||||
public function test_getOneWrongId(): void
|
||||
{
|
||||
$id = '6588yk36406qqva';
|
||||
$actual = $this->collection->getOne($id);
|
||||
$expected = [
|
||||
'data' => [],
|
||||
'message' => "The requested resource wasn't found.",
|
||||
'status' => 404,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
$this->assertCount(3,$actual);
|
||||
$this->expectException(ClientException::class);
|
||||
|
||||
$this->collection->getOne($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user