This commit is contained in:
Toby Zerner 2021-01-07 11:17:31 +10:00
parent 5fe8558993
commit 644078b517
9 changed files with 12 additions and 20 deletions

View File

@ -7,6 +7,8 @@ This `scope` method allows you to modify the query builder object provided by th
For example, to make it so the authenticated user can only see their own posts:
```php
use Tobyz\JsonApiServer\Context;
$type->scope(function ($query, Context $context) {
$query->where('user_id', $context->getRequest()->getAttribute('userId'));
});

View File

@ -30,7 +30,6 @@ final class Type
private $countable = true;
private $listable = true;
private $defaultSort;
private $defaultFilter;
private $saveCallback;
private $newModelCallback;
private $creatable = false;

View File

@ -15,7 +15,6 @@ use DateTime;
use DateTimeInterface;
use JsonApiPhp\JsonApi as Structure;
use RuntimeException;
use Tobyz\JsonApiServer\Context;
final class Serializer
{

View File

@ -2,13 +2,11 @@
namespace Tobyz\Tests\JsonApiServer;
use Closure;
use Tobyz\JsonApiServer\Adapter\AdapterInterface;
use Tobyz\JsonApiServer\Schema\Attribute;
use Tobyz\JsonApiServer\Schema\Field;
use Tobyz\JsonApiServer\Schema\HasMany;
use Tobyz\JsonApiServer\Schema\HasOne;
use Tobyz\JsonApiServer\Schema\Relationship;
class MockAdapter implements AdapterInterface
{

View File

@ -30,7 +30,7 @@ class CountabilityTest extends AbstractTestCase
public function setUp(): void
{
$this->api = new JsonApi('http://example.com');
$this->api = new JsonApi('/');
$models = [];
for ($i = 1; $i <= 100; $i++) {

View File

@ -11,7 +11,6 @@
namespace Tobyz\Tests\JsonApiServer\feature;
use Psr\Http\Message\ServerRequestInterface;
use Tobyz\JsonApiServer\Adapter\AdapterInterface;
use Tobyz\JsonApiServer\Exception\ForbiddenException;
use Tobyz\JsonApiServer\JsonApi;
@ -29,7 +28,7 @@ class CreateTest extends AbstractTestCase
public function setUp(): void
{
$this->api = new JsonApi('http://example.com');
$this->api = new JsonApi('/');
}
protected function createResource(array $data = [])

View File

@ -12,7 +12,6 @@
namespace Tobyz\Tests\JsonApiServer\feature;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Tobyz\JsonApiServer\JsonApi;
use Tobyz\JsonApiServer\Schema\Type;
use Tobyz\Tests\JsonApiServer\AbstractTestCase;
@ -39,7 +38,7 @@ class FieldVisibilityTest extends AbstractTestCase
]);
}
public function test_attributes_are_visible_by_default()
public function test_fields_are_visible_by_default()
{
$this->api->resource('users', new MockAdapter, function (Type $type) {
$type->attribute('visible');
@ -55,7 +54,7 @@ class FieldVisibilityTest extends AbstractTestCase
$this->assertArrayHasKey('visible', $attributes);
}
public function test_attributes_can_be_explicitly_visible()
public function test_fields_can_be_explicitly_visible()
{
$this->markTestIncomplete();
@ -119,7 +118,7 @@ class FieldVisibilityTest extends AbstractTestCase
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
}
public function test_attribute_visible_callback_receives_correct_parameters()
public function test_field_visible_callback_receives_correct_parameters()
{
$this->markTestIncomplete();
@ -149,7 +148,7 @@ class FieldVisibilityTest extends AbstractTestCase
$this->assertEquals(3, $called);
}
public function test_attributes_can_be_explicitly_hidden()
public function test_fields_can_be_explicitly_hidden()
{
$this->markTestIncomplete();
@ -172,7 +171,7 @@ class FieldVisibilityTest extends AbstractTestCase
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
}
public function test_attributes_can_be_conditionally_hidden()
public function test_fields_can_be_conditionally_hidden()
{
$this->markTestIncomplete();
@ -213,7 +212,7 @@ class FieldVisibilityTest extends AbstractTestCase
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
}
public function test_attribute_hidden_callback_receives_correct_parameters()
public function test_field_hidden_callback_receives_correct_parameters()
{
$this->markTestIncomplete();
@ -242,6 +241,4 @@ class FieldVisibilityTest extends AbstractTestCase
$this->assertEquals(3, $called);
}
// to_one, to_many...
}

View File

@ -255,6 +255,4 @@ class FieldWritabilityTest extends AbstractTestCase
->withParsedBody($payload)
);
}
// to_one, to_many...
}

View File

@ -25,7 +25,7 @@ class TypeTest extends TestCase
$fields = $type->getFields();
$this->assertSame($attribute, $attributeAgain);
$this->assertEquals(1, count($fields));
$this->assertCount(1, $fields);
}
public function test_overwrites_an_existing_field_with_the_same_name_of_a_different_type()
@ -37,7 +37,7 @@ class TypeTest extends TestCase
$fields = $type->getFields();
$this->assertNotSame($attribute, $hasOne);
$this->assertEquals(1, count($fields));
$this->assertCount(1, $fields);
$this->assertSame($hasOne, $fields['dogs']);
}
}