Clean up
This commit is contained in:
parent
5fe8558993
commit
644078b517
|
|
@ -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:
|
For example, to make it so the authenticated user can only see their own posts:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
use Tobyz\JsonApiServer\Context;
|
||||||
|
|
||||||
$type->scope(function ($query, Context $context) {
|
$type->scope(function ($query, Context $context) {
|
||||||
$query->where('user_id', $context->getRequest()->getAttribute('userId'));
|
$query->where('user_id', $context->getRequest()->getAttribute('userId'));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ final class Type
|
||||||
private $countable = true;
|
private $countable = true;
|
||||||
private $listable = true;
|
private $listable = true;
|
||||||
private $defaultSort;
|
private $defaultSort;
|
||||||
private $defaultFilter;
|
|
||||||
private $saveCallback;
|
private $saveCallback;
|
||||||
private $newModelCallback;
|
private $newModelCallback;
|
||||||
private $creatable = false;
|
private $creatable = false;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ use DateTime;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use JsonApiPhp\JsonApi as Structure;
|
use JsonApiPhp\JsonApi as Structure;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Tobyz\JsonApiServer\Context;
|
|
||||||
|
|
||||||
final class Serializer
|
final class Serializer
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,11 @@
|
||||||
|
|
||||||
namespace Tobyz\Tests\JsonApiServer;
|
namespace Tobyz\Tests\JsonApiServer;
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use Tobyz\JsonApiServer\Adapter\AdapterInterface;
|
use Tobyz\JsonApiServer\Adapter\AdapterInterface;
|
||||||
use Tobyz\JsonApiServer\Schema\Attribute;
|
use Tobyz\JsonApiServer\Schema\Attribute;
|
||||||
use Tobyz\JsonApiServer\Schema\Field;
|
use Tobyz\JsonApiServer\Schema\Field;
|
||||||
use Tobyz\JsonApiServer\Schema\HasMany;
|
use Tobyz\JsonApiServer\Schema\HasMany;
|
||||||
use Tobyz\JsonApiServer\Schema\HasOne;
|
use Tobyz\JsonApiServer\Schema\HasOne;
|
||||||
use Tobyz\JsonApiServer\Schema\Relationship;
|
|
||||||
|
|
||||||
class MockAdapter implements AdapterInterface
|
class MockAdapter implements AdapterInterface
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class CountabilityTest extends AbstractTestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->api = new JsonApi('http://example.com');
|
$this->api = new JsonApi('/');
|
||||||
|
|
||||||
$models = [];
|
$models = [];
|
||||||
for ($i = 1; $i <= 100; $i++) {
|
for ($i = 1; $i <= 100; $i++) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
namespace Tobyz\Tests\JsonApiServer\feature;
|
namespace Tobyz\Tests\JsonApiServer\feature;
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Tobyz\JsonApiServer\Adapter\AdapterInterface;
|
use Tobyz\JsonApiServer\Adapter\AdapterInterface;
|
||||||
use Tobyz\JsonApiServer\Exception\ForbiddenException;
|
use Tobyz\JsonApiServer\Exception\ForbiddenException;
|
||||||
use Tobyz\JsonApiServer\JsonApi;
|
use Tobyz\JsonApiServer\JsonApi;
|
||||||
|
|
@ -29,7 +28,7 @@ class CreateTest extends AbstractTestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->api = new JsonApi('http://example.com');
|
$this->api = new JsonApi('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createResource(array $data = [])
|
protected function createResource(array $data = [])
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
namespace Tobyz\Tests\JsonApiServer\feature;
|
namespace Tobyz\Tests\JsonApiServer\feature;
|
||||||
|
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Tobyz\JsonApiServer\JsonApi;
|
use Tobyz\JsonApiServer\JsonApi;
|
||||||
use Tobyz\JsonApiServer\Schema\Type;
|
use Tobyz\JsonApiServer\Schema\Type;
|
||||||
use Tobyz\Tests\JsonApiServer\AbstractTestCase;
|
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) {
|
$this->api->resource('users', new MockAdapter, function (Type $type) {
|
||||||
$type->attribute('visible');
|
$type->attribute('visible');
|
||||||
|
|
@ -55,7 +54,7 @@ class FieldVisibilityTest extends AbstractTestCase
|
||||||
$this->assertArrayHasKey('visible', $attributes);
|
$this->assertArrayHasKey('visible', $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_attributes_can_be_explicitly_visible()
|
public function test_fields_can_be_explicitly_visible()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
|
|
||||||
|
|
@ -119,7 +118,7 @@ class FieldVisibilityTest extends AbstractTestCase
|
||||||
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
|
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_attribute_visible_callback_receives_correct_parameters()
|
public function test_field_visible_callback_receives_correct_parameters()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
|
|
||||||
|
|
@ -149,7 +148,7 @@ class FieldVisibilityTest extends AbstractTestCase
|
||||||
$this->assertEquals(3, $called);
|
$this->assertEquals(3, $called);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_attributes_can_be_explicitly_hidden()
|
public function test_fields_can_be_explicitly_hidden()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
|
|
||||||
|
|
@ -172,7 +171,7 @@ class FieldVisibilityTest extends AbstractTestCase
|
||||||
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
|
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_attributes_can_be_conditionally_hidden()
|
public function test_fields_can_be_conditionally_hidden()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
|
|
||||||
|
|
@ -213,7 +212,7 @@ class FieldVisibilityTest extends AbstractTestCase
|
||||||
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
|
$this->assertArrayNotHasKey('hiddenHasMany', $relationships);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_attribute_hidden_callback_receives_correct_parameters()
|
public function test_field_hidden_callback_receives_correct_parameters()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
|
|
||||||
|
|
@ -242,6 +241,4 @@ class FieldVisibilityTest extends AbstractTestCase
|
||||||
|
|
||||||
$this->assertEquals(3, $called);
|
$this->assertEquals(3, $called);
|
||||||
}
|
}
|
||||||
|
|
||||||
// to_one, to_many...
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -255,6 +255,4 @@ class FieldWritabilityTest extends AbstractTestCase
|
||||||
->withParsedBody($payload)
|
->withParsedBody($payload)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// to_one, to_many...
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class TypeTest extends TestCase
|
||||||
$fields = $type->getFields();
|
$fields = $type->getFields();
|
||||||
|
|
||||||
$this->assertSame($attribute, $attributeAgain);
|
$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()
|
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();
|
$fields = $type->getFields();
|
||||||
|
|
||||||
$this->assertNotSame($attribute, $hasOne);
|
$this->assertNotSame($attribute, $hasOne);
|
||||||
$this->assertEquals(1, count($fields));
|
$this->assertCount(1, $fields);
|
||||||
$this->assertSame($hasOne, $fields['dogs']);
|
$this->assertSame($hasOne, $fields['dogs']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue