mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
Compare commits
1 Commits
v2.0.0-bet
...
2.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
414bf4fe45 |
@@ -1,48 +1,46 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Pb\Client;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Pb\Collection;
|
|
||||||
use Pb\Settings;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use PocketBase\Client;
|
||||||
|
use PocketBase\Collection;
|
||||||
|
use PocketBase\HttpClient;
|
||||||
|
|
||||||
final class ClientTest extends TestCase
|
final class ClientTest extends TestCase
|
||||||
{
|
{
|
||||||
private Collection $collection;
|
|
||||||
private ?string $url;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
private Collection $collection;
|
||||||
{
|
private ?Client $client = null;
|
||||||
$this->url = getenv('POCKETBASE_URL') ?: 'https://admin.pocketbase.dev';
|
public ?HttpClient $http = null;
|
||||||
$this->collection = new Collection($this->url, 'users');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_collection(): void
|
public function test_collection(): void
|
||||||
{
|
{
|
||||||
$pb = new Client($this->url);
|
$this->client = new Client();
|
||||||
|
$this->collection = $this->client->collection('_superusers');
|
||||||
$actual = $pb->collection('users');
|
$this->assertEquals(Collection::class, get_class($this->collection));
|
||||||
|
|
||||||
$this->assertEquals($actual, $this->collection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_settings(): void
|
public function test_authAsUser(): void
|
||||||
{
|
{
|
||||||
$pb = new Client($this->url);
|
$this->client = new Client();
|
||||||
|
$this->collection = $this->client->collection('users');
|
||||||
|
$this->collection->setPath('/api/collections/users/auth-with-password');
|
||||||
|
|
||||||
$actual = $pb->settings();
|
$token = $this->collection->authAsUser('admin@jonathan-martz.de', 'Password123');
|
||||||
|
$this->assertNotEmpty($token);
|
||||||
$this->assertEquals($actual, new Settings($this->url));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_setToken(){
|
/**
|
||||||
$token = 'test123';
|
* @throws \PHPUnit\Framework\MockObject\Exception
|
||||||
|
*/
|
||||||
|
// @sk
|
||||||
|
public function test_authAsAdmin(): void
|
||||||
|
{
|
||||||
|
$this->client = new Client();
|
||||||
|
$this->collection = $this->client->collection('_superusers');
|
||||||
|
$this->collection->setPath('/api/collections/' . $this->collection->getName() . '/auth-with-password');
|
||||||
|
|
||||||
$pb = new Client($this->url);
|
$token = $this->collection->authAsUser('admin@jonathan-martz.de', 'Password123');
|
||||||
$pb->setAuthToken($token);
|
$this->assertNotEmpty($token);
|
||||||
|
|
||||||
$this->assertEquals($token, $pb->getAuthToken());
|
|
||||||
$this->assertEquals($token, $pb->token);
|
|
||||||
$pb->token = 'test456';
|
|
||||||
$this->assertEquals('test456', $pb->getAuthToken());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user