From 644078b517cafeb244876c6fe423409e9bdfd750 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 7 Jan 2021 11:17:31 +1000 Subject: [PATCH] Clean up --- docs/scopes.md | 2 ++ src/Schema/Type.php | 1 - src/Serializer.php | 1 - tests/MockAdapter.php | 2 -- tests/feature/CountabilityTest.php | 2 +- tests/feature/CreateTest.php | 3 +-- tests/feature/FieldVisibilityTest.php | 15 ++++++--------- tests/feature/FieldWritabilityTest.php | 2 -- tests/unit/Schema/TypeTest.php | 4 ++-- 9 files changed, 12 insertions(+), 20 deletions(-) diff --git a/docs/scopes.md b/docs/scopes.md index 1455a47..728e0cc 100644 --- a/docs/scopes.md +++ b/docs/scopes.md @@ -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')); }); diff --git a/src/Schema/Type.php b/src/Schema/Type.php index 0da6b1c..3d939f0 100644 --- a/src/Schema/Type.php +++ b/src/Schema/Type.php @@ -30,7 +30,6 @@ final class Type private $countable = true; private $listable = true; private $defaultSort; - private $defaultFilter; private $saveCallback; private $newModelCallback; private $creatable = false; diff --git a/src/Serializer.php b/src/Serializer.php index 46d3828..bc17126 100644 --- a/src/Serializer.php +++ b/src/Serializer.php @@ -15,7 +15,6 @@ use DateTime; use DateTimeInterface; use JsonApiPhp\JsonApi as Structure; use RuntimeException; -use Tobyz\JsonApiServer\Context; final class Serializer { diff --git a/tests/MockAdapter.php b/tests/MockAdapter.php index 10349f1..dbd056a 100644 --- a/tests/MockAdapter.php +++ b/tests/MockAdapter.php @@ -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 { diff --git a/tests/feature/CountabilityTest.php b/tests/feature/CountabilityTest.php index cf6217f..85598cd 100644 --- a/tests/feature/CountabilityTest.php +++ b/tests/feature/CountabilityTest.php @@ -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++) { diff --git a/tests/feature/CreateTest.php b/tests/feature/CreateTest.php index 12ce6ef..b70605e 100644 --- a/tests/feature/CreateTest.php +++ b/tests/feature/CreateTest.php @@ -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 = []) diff --git a/tests/feature/FieldVisibilityTest.php b/tests/feature/FieldVisibilityTest.php index dd81770..cba84c6 100644 --- a/tests/feature/FieldVisibilityTest.php +++ b/tests/feature/FieldVisibilityTest.php @@ -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... } diff --git a/tests/feature/FieldWritabilityTest.php b/tests/feature/FieldWritabilityTest.php index 725facd..77875e0 100644 --- a/tests/feature/FieldWritabilityTest.php +++ b/tests/feature/FieldWritabilityTest.php @@ -255,6 +255,4 @@ class FieldWritabilityTest extends AbstractTestCase ->withParsedBody($payload) ); } - - // to_one, to_many... } diff --git a/tests/unit/Schema/TypeTest.php b/tests/unit/Schema/TypeTest.php index ff119fa..8d84db3 100644 --- a/tests/unit/Schema/TypeTest.php +++ b/tests/unit/Schema/TypeTest.php @@ -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']); } }