Skip to content

Commit

Permalink
fix methods and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedbally committed May 8, 2023
1 parent 889d799 commit 5b99160
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": "^7.0|^8.0",
"php": "^7.4|^8.0",
"illuminate/contracts": "^5.1|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "^5.1|^6.0|^7.0|^8.0|^9.0|^10.0",
"league/fractal": "^0.19.0|^0.20"
Expand Down
2 changes: 1 addition & 1 deletion src/FractalTransformFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function parseOptions(array $options, ResourceInterface $resource): ar
], $options);

if (! empty($options['fieldsets'])) {
if (is_null($resourceKey = $resource->getResourceKey())) {
if (empty($resourceKey = $resource->getResourceKey())) {
throw new LogicException('Filtering fields using sparse fieldsets require resource key to be set.');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/ResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ protected function resolveTransformer($data, $transformer)
*/
protected function resolveResourceKey($data, string $resourceKey = null)
{
return isset($resourceKey) ? $resourceKey : $this->resourceKeyResolver->resolve($data);
return ! empty($resourceKey) ? $resourceKey : $this->resourceKeyResolver->resolve($data);
}
}
4 changes: 2 additions & 2 deletions src/Serializers/NoopSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function item($resourceKey, array $data): array
/**
* Serialize null resources.
*
* @return array
* @return null|array
*/
public function null(): array
public function null(): ?array
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Serializers/SuccessSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function item($resourceKey, array $data): array
/**
* Serialize null resources.
*
* @return array
* @return null|array
*/
public function null(): array
public function null(): ?array
{
return ['data' => null];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/TransformResponseDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function transform(Product $product)

class ResourceKeySerializer extends SuccessSerializer
{
public function item($resourceKey, array $data)
public function item($resourceKey, array $data): array
{
return [$resourceKey => $data];
}
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Exceptions/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Translation\Translator;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Eloquent\RelationNotFoundException as BaseRelationNotFoundException;
Expand Down Expand Up @@ -126,7 +127,10 @@ public function testRenderMethodConvertsRelationNotFoundExceptions()
public function testRenderMethodConvertsValidationExceptions()
{
$validator = Mockery::mock(Validator::class);
$validator->shouldReceive('errors')->andReturn(collect(['foo' => 'bar']));
$validator->shouldReceive('errors')->andReturn(collect([['foo' => 'bar']]));
$translator = Mockery::mock(Translator::class);
$translator->shouldReceive('get')->andReturn('foo');
$validator->shouldReceive('getTranslator')->andReturn($translator);
$exception = new ValidationException($validator);
$this->expectException(ValidationFailedException::class);

Expand Down Expand Up @@ -161,9 +165,9 @@ public function testRenderMethodConvertsHttpExceptionsToResponses()
*/
public function testItShouldNotConvertNonHttpExceptions()
{
$this->request->shouldReceive('expectsJson')->andReturn(false);
$request = Request::createFromGlobals();

$result = $this->handler->render($this->request, $exception = new Exception);
$result = $this->handler->render($request, $exception = new Exception);

$this->assertInstanceOf(Response::class, $result);
}
Expand Down

0 comments on commit 5b99160

Please sign in to comment.