mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
continue on collection create logic
This commit is contained in:
@@ -69,10 +69,10 @@ class Collection
|
|||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authAsUser(string $email, string $password): string
|
public function authAsUser(string $email, string $password): array
|
||||||
{
|
{
|
||||||
$result = $this->doRequest($this->url . "/api/collections/users/auth-with-password", 'POST', ['identity' => $email, 'password' => $password]);
|
$result = $this->doRequest($this->url . "/api/collections/users/auth-with-password", 'POST', ['identity' => $email, 'password' => $password]);
|
||||||
var_dump($result);
|
$result = json_decode($result, JSON_FORCE_OBJECT);
|
||||||
if (!empty($result['token'])) {
|
if (!empty($result['token'])) {
|
||||||
self::$token = $result['token'];
|
self::$token = $result['token'];
|
||||||
}
|
}
|
||||||
@@ -106,6 +106,7 @@ class Collection
|
|||||||
|
|
||||||
public function create(array $bodyParams = [], array $queryParams = []): string
|
public function create(array $bodyParams = [], array $queryParams = []): string
|
||||||
{
|
{
|
||||||
|
// TODO query params ?
|
||||||
return $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records", 'POST', $bodyParams);
|
return $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records", 'POST', $bodyParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,6 +193,4 @@ class Collection
|
|||||||
$this->collection = $collection;
|
$this->collection = $collection;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,20 @@ class CollectionCreateTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateCollectionItem(){
|
public function testCreateCollectionItem(){
|
||||||
// $this->expectException(ClientException::class);
|
$this->expectException(ClientException::class);
|
||||||
// $this->collection->create(['name' => 'Hallo Welt']);
|
$this->expectExceptionCode(403);
|
||||||
|
$this->collection->create(['name' => 'Hallo Welt']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateCollectionItemAuthed(){
|
public function testCreateCollectionItemAuthed(){
|
||||||
$this->collection->authAsUser('admin@jmartz.de', 'rockt123?!');
|
$this->collection->authAsUser('admin@jmartz.de', 'rockt123?!');#
|
||||||
self::assertNotEmpty($this->collection);
|
self::assertNotEmpty($this->collection->getAuthToken());
|
||||||
// $response = $this->collection->create(['name' => 'Hallo Welt']);
|
}
|
||||||
// var_dump($response);
|
|
||||||
|
public function testCreateCollectionItemAuthedAdmin(){
|
||||||
|
$this->collection->authAsAdmin('admin@jonathan-martz.de', 'rockt123?!');
|
||||||
|
$response = $this->collection->create(['email' => 'test@jonathan-martz.de','password' => 'rockt123?!','passwordConfirm' => 'rockt123?!']);
|
||||||
|
var_dump($response);
|
||||||
|
self::assertNotEmpty($this->collection->getAuthToken());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user