From 7961f44d54e0e77fa2d746a25043af32eeb17f18 Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Sat, 30 Dec 2023 08:35:02 +0000 Subject: [PATCH] enhance the serializer tests (#597) * fix: enhance the serializer tests * Fix styling * fix: wip --------- Co-authored-by: binaryk --- pint.json | 6 ++++++ src/Bootstrap/RoutesDefinition.php | 2 +- src/Commands/PublishAuthCommand.php | 2 +- src/Eager/Related.php | 2 +- src/Exceptions/RepositoryException.php | 4 ++-- src/Fields/BelongsTo.php | 2 +- src/Fields/BelongsToMany.php | 2 +- src/Fields/EagerField.php | 4 ++-- src/Fields/Field.php | 8 ++++---- src/Fields/File.php | 8 ++++---- src/Fields/HasMany.php | 4 ++-- src/Fields/HasOne.php | 2 +- src/Fields/Image.php | 2 +- src/Filters/AdvancedFilter.php | 2 +- src/Filters/RelatedDto.php | 2 +- src/Filters/RelatedQuery.php | 2 +- src/Filters/SortableFilter.php | 2 +- .../Requests/Concerns/InteractWithRepositories.php | 8 ++++---- src/Models/ActionLog.php | 10 +++++----- src/Repositories/Concerns/Testing.php | 10 +++++----- src/Repositories/Repository.php | 6 +++--- src/Repositories/Serializer.php | 2 +- src/Repositories/ValidatingTrait.php | 12 ++++++------ src/Repositories/WithRoutePrefix.php | 2 +- src/Transaction.php | 2 +- src/helpers.php | 2 +- tests/Assertables/AssertableModel.php | 4 ++-- .../RepositoryLoadedFromServiceProviderTest.php | 2 +- tests/Fixtures/Comment/CommentPolicy.php | 2 +- tests/Fixtures/Company/CompanyPolicy.php | 2 +- tests/Fixtures/MailTracking.php | 12 ++++++------ tests/Fixtures/Post/Getters/PostsShowGetter.php | 2 +- tests/Fixtures/Post/PostPolicy.php | 2 +- tests/IntegrationTestCase.php | 2 +- tests/Prototypes/Prototypeable.php | 10 +++++----- tests/Repositories/RepositorySerializerTest.php | 2 ++ 36 files changed, 79 insertions(+), 71 deletions(-) create mode 100644 pint.json diff --git a/pint.json b/pint.json new file mode 100644 index 00000000..0c6c8be9 --- /dev/null +++ b/pint.json @@ -0,0 +1,6 @@ +{ + "preset": "laravel", + "rules": { + "nullable_type_declaration_for_default_null_value": false + } +} diff --git a/src/Bootstrap/RoutesDefinition.php b/src/Bootstrap/RoutesDefinition.php index 9567f835..42ebd9a5 100644 --- a/src/Bootstrap/RoutesDefinition.php +++ b/src/Bootstrap/RoutesDefinition.php @@ -13,7 +13,7 @@ class RoutesDefinition { private array $excludedMiddleware = []; - public function __invoke(string $uriKey = null) + public function __invoke(?string $uriKey = null) { $prefix = $uriKey ?: '{repository}'; diff --git a/src/Commands/PublishAuthCommand.php b/src/Commands/PublishAuthCommand.php index b7b8eb5b..5f789d92 100644 --- a/src/Commands/PublishAuthCommand.php +++ b/src/Commands/PublishAuthCommand.php @@ -149,7 +149,7 @@ protected function getRouteStubs(): string return $routeStubs; } - protected function getRemainingActionsString(array $actions = null): string + protected function getRemainingActionsString(?array $actions = null): string { $allActions = ['login', 'register', 'resetPassword', 'forgotPassword', 'verifyEmail']; diff --git a/src/Eager/Related.php b/src/Eager/Related.php index 6b78311f..62e1f436 100644 --- a/src/Eager/Related.php +++ b/src/Eager/Related.php @@ -39,7 +39,7 @@ class Related implements JsonSerializable public ?RelatedQuery $relatedQuery = null; - public function __construct(string $relation, EagerField $field = null) + public function __construct(string $relation, ?EagerField $field = null) { $this->relation = $relation; $this->field = $field; diff --git a/src/Exceptions/RepositoryException.php b/src/Exceptions/RepositoryException.php index e2b7150f..c25481a1 100644 --- a/src/Exceptions/RepositoryException.php +++ b/src/Exceptions/RepositoryException.php @@ -11,14 +11,14 @@ public static function missingKey(string $class = 'Repository key missing.'): se return new self($class); } - public static function unauthorized(string $class = null): self + public static function unauthorized(?string $class = null): self { return new self(__('Unauthorized to view repository :name. Check "allowRestify" policy.', [ 'name' => $class, ]), code: 403); } - public static function routeUnauthorized(string $uri = null): self + public static function routeUnauthorized(?string $uri = null): self { return new self(__('Unauthorized to use the route :name. Check prefix.', [ 'name' => $uri, diff --git a/src/Fields/BelongsTo.php b/src/Fields/BelongsTo.php index 066a1cbd..69f9f575 100644 --- a/src/Fields/BelongsTo.php +++ b/src/Fields/BelongsTo.php @@ -16,7 +16,7 @@ class BelongsTo extends EagerField implements Sortable public ?array $searchablesAttributes = null; - public function fillAttribute(RestifyRequest $request, $model, int $bulkRow = null) + public function fillAttribute(RestifyRequest $request, $model, ?int $bulkRow = null) { /** * @var Model $relatedModel */ $relatedModel = $model->{$this->relation}()->getModel(); diff --git a/src/Fields/BelongsToMany.php b/src/Fields/BelongsToMany.php index ba13a333..6d3b8700 100644 --- a/src/Fields/BelongsToMany.php +++ b/src/Fields/BelongsToMany.php @@ -29,7 +29,7 @@ class BelongsToMany extends EagerField */ public $detachCallback; - public function __construct($relation, string $parentRepository = null) + public function __construct($relation, ?string $parentRepository = null) { parent::__construct($relation, $parentRepository); diff --git a/src/Fields/EagerField.php b/src/Fields/EagerField.php index 18e3cbee..b92793f9 100644 --- a/src/Fields/EagerField.php +++ b/src/Fields/EagerField.php @@ -28,7 +28,7 @@ class EagerField extends Field private RelatedQuery $relatedQuery; - public function __construct($attribute, string $parentRepository = null) + public function __construct($attribute, ?string $parentRepository = null) { parent::__construct(attribute: $attribute); @@ -101,7 +101,7 @@ public function resolve($repository, $attribute = null) } public function getRelation( - Repository $repository = null + ?Repository $repository = null ): Relation { $repository = $repository ?? $this->parentRepository; diff --git a/src/Fields/Field.php b/src/Fields/Field.php index f71b1732..b5980019 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -133,7 +133,7 @@ class Field extends OrganicField implements JsonSerializable * @param string|callable|null $attribute * @param callable|null $resolveCallback */ - public function __construct($attribute, callable|Closure $resolveCallback = null) + public function __construct($attribute, callable|Closure|null $resolveCallback = null) { $this->attribute = $attribute; @@ -210,7 +210,7 @@ public function fillCallback(callable|Closure $callback) * * @return mixed|void */ - public function fillAttribute(RestifyRequest $request, $model, int $bulkRow = null) + public function fillAttribute(RestifyRequest $request, $model, ?int $bulkRow = null) { $this->resolveValueBeforeUpdate($request, $model); @@ -258,7 +258,7 @@ public function fillAttribute(RestifyRequest $request, $model, int $bulkRow = nu /** * Fill the model with value from the request. */ - protected function fillAttributeFromRequest(RestifyRequest $request, $model, $attribute, int $bulkRow = null) + protected function fillAttributeFromRequest(RestifyRequest $request, $model, $attribute, ?int $bulkRow = null) { $attribute = is_null($bulkRow) ? $attribute @@ -279,7 +279,7 @@ protected function fillAttributeFromRequest(RestifyRequest $request, $model, $at /** * Fill the model with value from the callback. */ - protected function fillAttributeFromCallback(RestifyRequest $request, $model, $attribute, int $bulkRow = null) + protected function fillAttributeFromCallback(RestifyRequest $request, $model, $attribute, ?int $bulkRow = null) { if (is_callable($cb = $this->guessBeforeFillableCallable($request))) { $value = $request->input($attribute ?? $this->attribute); diff --git a/src/Fields/File.php b/src/Fields/File.php index 73f57eb4..0713a002 100644 --- a/src/Fields/File.php +++ b/src/Fields/File.php @@ -48,7 +48,7 @@ class File extends Field implements DeletableContract, StorableContract */ public $storageCallback; - public function __construct($attribute, callable $resolveCallback = null) + public function __construct($attribute, ?callable $resolveCallback = null) { parent::__construct($attribute, $resolveCallback); @@ -81,7 +81,7 @@ public function storeAs($storeAs): self * * @return $this */ - public function resolveUsingTemporaryUrl(bool $resolveTemporaryUrl = true, CarbonInterface $expiration = null, array $options = []): self + public function resolveUsingTemporaryUrl(bool $resolveTemporaryUrl = true, ?CarbonInterface $expiration = null, array $options = []): self { if (! $resolveTemporaryUrl) { return $this; @@ -126,7 +126,7 @@ public function resolveUsingFullUrl(): self /** * Prepare the storage callback. */ - protected function prepareStorageCallback(callable $storageCallback = null): void + protected function prepareStorageCallback(?callable $storageCallback = null): void { $this->storageCallback = $storageCallback ?? function ($request, $model) { return $this->mergeExtraStorageColumns($request, [ @@ -227,7 +227,7 @@ protected function columnsThatShouldBeDeleted(): array return $attributes; } - public function fillAttribute(RestifyRequest $request, $model, int $bulkRow = null) + public function fillAttribute(RestifyRequest $request, $model, ?int $bulkRow = null) { if (is_null($file = $request->file($this->attribute)) || ! $file->isValid()) { return $this; diff --git a/src/Fields/HasMany.php b/src/Fields/HasMany.php index 8f22120b..f884786e 100644 --- a/src/Fields/HasMany.php +++ b/src/Fields/HasMany.php @@ -12,7 +12,7 @@ class HasMany extends EagerField { protected $canEnableRelationshipCallback; - public function __construct($relation, string $parentRepository = null) + public function __construct($relation, ?string $parentRepository = null) { parent::__construct($relation, $parentRepository); @@ -48,7 +48,7 @@ public function resolve($repository, $attribute = null) return $this; } - public function fillAttribute(RestifyRequest $request, $model, int $bulkRow = null) + public function fillAttribute(RestifyRequest $request, $model, ?int $bulkRow = null) { // } diff --git a/src/Fields/HasOne.php b/src/Fields/HasOne.php index 7b46a52b..af2ef870 100644 --- a/src/Fields/HasOne.php +++ b/src/Fields/HasOne.php @@ -10,7 +10,7 @@ class HasOne extends EagerField implements Sortable { use CanSort; - public function fillAttribute(RestifyRequest $request, $model, int $bulkRow = null) + public function fillAttribute(RestifyRequest $request, $model, ?int $bulkRow = null) { // } diff --git a/src/Fields/Image.php b/src/Fields/Image.php index fd98d5a5..4ec1d52c 100644 --- a/src/Fields/Image.php +++ b/src/Fields/Image.php @@ -7,7 +7,7 @@ class Image extends File { - public function __construct($attribute, callable $resolveCallback = null) + public function __construct($attribute, ?callable $resolveCallback = null) { parent::__construct($attribute, $resolveCallback); diff --git a/src/Filters/AdvancedFilter.php b/src/Filters/AdvancedFilter.php index 14224655..e6339750 100644 --- a/src/Filters/AdvancedFilter.php +++ b/src/Filters/AdvancedFilter.php @@ -32,7 +32,7 @@ public function validatePayload(RestifyRequest $request, AdvancedFilterPayloadDa return $this; } - protected function input(string $key = null, $default = null) + protected function input(?string $key = null, $default = null) { return data_get($this->dataObject->value, $key, $default); } diff --git a/src/Filters/RelatedDto.php b/src/Filters/RelatedDto.php index 6348b1ee..48b8e720 100644 --- a/src/Filters/RelatedDto.php +++ b/src/Filters/RelatedDto.php @@ -21,7 +21,7 @@ class RelatedDto public string $rootKey = ''; public function __construct( - RelatedQueryCollection $related = null, + ?RelatedQueryCollection $related = null, ) { $this->related = $related ?? RelatedQueryCollection::make([]); } diff --git a/src/Filters/RelatedQuery.php b/src/Filters/RelatedQuery.php index ccd74254..6eeb398f 100644 --- a/src/Filters/RelatedQuery.php +++ b/src/Filters/RelatedQuery.php @@ -14,7 +14,7 @@ public function __construct( public string $relation, public bool $loaded = false, public array $columns = ['*'], - RelatedQueryCollection $nested = null, + ?RelatedQueryCollection $nested = null, ) { $this->nested = $nested ?? RelatedQueryCollection::make([]); $this->tree = $relation; diff --git a/src/Filters/SortableFilter.php b/src/Filters/SortableFilter.php index c93e0599..20b76d0a 100644 --- a/src/Filters/SortableFilter.php +++ b/src/Filters/SortableFilter.php @@ -131,7 +131,7 @@ public function resolveFrontendColumn(): self return $this; } - public function syncDirection(string $direction = null): self + public function syncDirection(?string $direction = null): self { if (! is_null($direction) && in_array($direction, ['asc', 'desc'])) { $this->direction = $direction; diff --git a/src/Http/Requests/Concerns/InteractWithRepositories.php b/src/Http/Requests/Concerns/InteractWithRepositories.php index 153cd7da..71162649 100644 --- a/src/Http/Requests/Concerns/InteractWithRepositories.php +++ b/src/Http/Requests/Concerns/InteractWithRepositories.php @@ -60,21 +60,21 @@ public function repository($key = null): Repository } } - public function repositoryWith(Model $model, string $uriKey = null): Repository + public function repositoryWith(Model $model, ?string $uriKey = null): Repository { $repository = $this->repository($uriKey); return $repository::resolveWith($model); } - public function model(string $uriKey = null): Model + public function model(?string $uriKey = null): Model { $repository = $this->repository($uriKey); return $repository::newModel(); } - public function newQuery(string $uriKey = null): Builder|Relation + public function newQuery(?string $uriKey = null): Builder|Relation { if (! $this->isViaRepository()) { return $this->model($uriKey)->newQuery(); @@ -88,7 +88,7 @@ public function viaQuery(): Relation return $this->relatedEagerField()->getRelation(); } - public function modelQuery(string $repositoryId = null, string $uriKey = null): Builder|Relation + public function modelQuery(?string $repositoryId = null, ?string $uriKey = null): Builder|Relation { return $this->newQuery($uriKey)->whereKey( $repositoryId ?? $this->route('repositoryId') diff --git a/src/Models/ActionLog.php b/src/Models/ActionLog.php index d767f193..2d9500c6 100644 --- a/src/Models/ActionLog.php +++ b/src/Models/ActionLog.php @@ -47,7 +47,7 @@ class ActionLog extends Model public const ACTION_DELETED = 'Deleted'; - public static function forRepositoryStored(Model $model, Authenticatable $user = null, array $dirty = null): self + public static function forRepositoryStored(Model $model, ?Authenticatable $user = null, ?array $dirty = null): self { return new static([ 'batch_id' => (string) Str::uuid(), @@ -69,7 +69,7 @@ public static function forRepositoryStored(Model $model, Authenticatable $user = ]); } - public static function forRepositoryUpdated(Model $model, Authenticatable $user = null): self + public static function forRepositoryUpdated(Model $model, ?Authenticatable $user = null): self { return new static([ 'batch_id' => (string) Str::uuid(), @@ -91,7 +91,7 @@ public static function forRepositoryUpdated(Model $model, Authenticatable $user ]); } - public static function forRepositoryDestroy(Model $model, Authenticatable $user = null): self + public static function forRepositoryDestroy(Model $model, ?Authenticatable $user = null): self { return new static([ 'batch_id' => (string) Str::uuid(), @@ -113,7 +113,7 @@ public static function forRepositoryDestroy(Model $model, Authenticatable $user ]); } - public static function forRepositoryAction(Action $action, Model $model, Authenticatable $user = null): self + public static function forRepositoryAction(Action $action, Model $model, ?Authenticatable $user = null): self { return new static([ 'batch_id' => (string) Str::uuid(), @@ -139,7 +139,7 @@ public static function register( string $name, Model $actionable, array $attributes = [], - Authenticatable $user = null + ?Authenticatable $user = null ): self { return new static(array_merge([ 'batch_id' => (string) Str::uuid(), diff --git a/src/Repositories/Concerns/Testing.php b/src/Repositories/Concerns/Testing.php index 0ee56420..4ea410dd 100644 --- a/src/Repositories/Concerns/Testing.php +++ b/src/Repositories/Concerns/Testing.php @@ -16,9 +16,9 @@ trait Testing { public static function route( - string|Model $path = null, + string|Model|null $path = null, array $query = [], - Action|callable $action = null, + Action|callable|null $action = null, ): string { if ($path instanceof Model) { $path = $path->getKey(); @@ -47,19 +47,19 @@ public static function route( /** * @param Action $action */ - public static function action(string $action, string|int $key = null): string + public static function action(string $action, string|int|null $key = null): string { return static::route($key, action: app($action)); } - public static function getter(string $getter, string|int $key = null): string + public static function getter(string $getter, string|int|null $key = null): string { $path = $key ? "$key/getters" : 'getters'; return static::route($path.'/'.Getter::guessUriKey(app($getter))); } - public function dd(string $prop = null): void + public function dd(?string $prop = null): void { if (is_null($prop)) { dd($this); diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index 8ac596e9..dbbba033 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -1052,7 +1052,7 @@ public function jsonSerialize() return $this->serializeForShow(app(RestifyRequest::class)); } - private function modelAttributes(Request $request = null): Collection + private function modelAttributes(?Request $request = null): Collection { return collect(method_exists($this->resource, 'toArray') ? $this->resource->toArray() : []); } @@ -1071,7 +1071,7 @@ protected static function fillBulkFields( RestifyRequest $request, Model $model, Collection $fields, - int $bulkRow = null + ?int $bulkRow = null ) { return $fields->map(function (Field $field) use ($request, $model, $bulkRow) { return $field->fillAttribute($request, $model, $bulkRow); @@ -1098,7 +1098,7 @@ public static function getDetachers(): array return static::$detachers; } - public function eager(EagerField $field = null): Repository + public function eager(?EagerField $field = null): Repository { if (! $field) { $this->eagerState = false; diff --git a/src/Repositories/Serializer.php b/src/Repositories/Serializer.php index d495dd3b..f46f8fd7 100644 --- a/src/Repositories/Serializer.php +++ b/src/Repositories/Serializer.php @@ -133,7 +133,7 @@ public function jsonSerialize(): mixed ]); } - private function request(string $class = null): RestifyRequest + private function request(?string $class = null): RestifyRequest { /** * @var RestifyRequest $request diff --git a/src/Repositories/ValidatingTrait.php b/src/Repositories/ValidatingTrait.php index ef90c7a0..45c990ee 100644 --- a/src/Repositories/ValidatingTrait.php +++ b/src/Repositories/ValidatingTrait.php @@ -24,7 +24,7 @@ abstract public static function newModel(); /** * @return \Illuminate\Contracts\Validation\Validator */ - public static function validatorForStoring(RestifyRequest $request, array $plainPayload = null) + public static function validatorForStoring(RestifyRequest $request, ?array $plainPayload = null) { $on = static::resolveWith(static::newModel()); @@ -47,7 +47,7 @@ public static function validatorForStoring(RestifyRequest $request, array $plain }); } - public static function validatorForStoringBulk(RestifyRequest $request, array $plainPayload = null) + public static function validatorForStoringBulk(RestifyRequest $request, ?array $plainPayload = null) { $on = static::resolveWith(static::newModel()); @@ -78,7 +78,7 @@ public static function validateForUpdate(RestifyRequest $request, $resource = nu static::validatorForUpdate($request, $resource)->validate(); } - public static function validatorForUpdate(RestifyRequest $request, $resource = null, array $plainPayload = null) + public static function validatorForUpdate(RestifyRequest $request, $resource = null, ?array $plainPayload = null) { /** * @var Repository $on */ $on = $resource ?? static::resolveWith(static::newModel()); @@ -102,7 +102,7 @@ public static function validatorForUpdate(RestifyRequest $request, $resource = n }); } - public static function validatorForPatch(RestifyRequest $request, $resource = null, array $plainPayload = null) + public static function validatorForPatch(RestifyRequest $request, $resource = null, ?array $plainPayload = null) { /** * @var Repository $on */ $on = $resource ?? static::resolveWith(static::newModel()); @@ -128,7 +128,7 @@ public static function validatorForPatch(RestifyRequest $request, $resource = nu }); } - public static function validatorForAttach(RestifyRequest $request, $resource = null, array $plainPayload = null) + public static function validatorForAttach(RestifyRequest $request, $resource = null, ?array $plainPayload = null) { /** * @var Repository $on */ $on = $resource ?? static::resolveWith(static::newModel()); @@ -156,7 +156,7 @@ public static function validatorForAttach(RestifyRequest $request, $resource = n }); } - public static function validatorForUpdateBulk(RestifyRequest $request, $resource = null, array $plainPayload = null) + public static function validatorForUpdateBulk(RestifyRequest $request, $resource = null, ?array $plainPayload = null) { /** * @var Repository $on */ $on = $resource ?? static::resolveWith(static::newModel()); diff --git a/src/Repositories/WithRoutePrefix.php b/src/Repositories/WithRoutePrefix.php index b5b8a834..206c6478 100644 --- a/src/Repositories/WithRoutePrefix.php +++ b/src/Repositories/WithRoutePrefix.php @@ -76,7 +76,7 @@ protected static function shouldAuthorizeRouteUsage(): bool ])->some(fn ($prefix) => (bool) $prefix); } - public static function setPrefix(?string $prefix, string $uriKey = null): void + public static function setPrefix(?string $prefix, ?string $uriKey = null): void { static::$prefixes[$uriKey ?? static::uriKey()] = $prefix; static::$prefix = $prefix; diff --git a/src/Transaction.php b/src/Transaction.php index fd810b20..cb6f30e7 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -8,7 +8,7 @@ class Transaction { - public static function run(callable $callback, callable $finished = null) + public static function run(callable $callback, ?callable $finished = null) { try { DB::beginTransaction(); diff --git a/src/helpers.php b/src/helpers.php index 22f72981..f6e7298f 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -32,7 +32,7 @@ function data(mixed $data = [], int $status = 200, array $headers = [], $options } if (! function_exists('ok')) { - function ok(string $message = null, int $code = 200) + function ok(?string $message = null, int $code = 200) { if (! is_null($message)) { return response()->json([ diff --git a/tests/Assertables/AssertableModel.php b/tests/Assertables/AssertableModel.php index a098fdf2..6b20b2d4 100644 --- a/tests/Assertables/AssertableModel.php +++ b/tests/Assertables/AssertableModel.php @@ -30,7 +30,7 @@ public function __construct( ) { } - public function first(Closure $callback = null): Model + public function first(?Closure $callback = null): Model { return $this->model; } @@ -45,7 +45,7 @@ protected function dotPath(string $key = ''): string return $key; } - protected function prop(string $key = null) + protected function prop(?string $key = null) { if (is_null($key)) { return $this->model->toArray(); diff --git a/tests/Controllers/RepositoryLoadedFromServiceProviderTest.php b/tests/Controllers/RepositoryLoadedFromServiceProviderTest.php index 2ff01327..c6968df9 100644 --- a/tests/Controllers/RepositoryLoadedFromServiceProviderTest.php +++ b/tests/Controllers/RepositoryLoadedFromServiceProviderTest.php @@ -26,7 +26,7 @@ protected function tearDown(): void public function test_repositories_can_be_loaded_with_service_provider_register_method( string $directory, string $namespace, - string $serviceProvider = null, + ?string $serviceProvider = null, ): void { if (! $serviceProvider) { $this->markTestSkipped('No service provider was found in directory '.$directory.' skipping this iteration.'); diff --git a/tests/Fixtures/Comment/CommentPolicy.php b/tests/Fixtures/Comment/CommentPolicy.php index d6f0ccab..3546bc89 100644 --- a/tests/Fixtures/Comment/CommentPolicy.php +++ b/tests/Fixtures/Comment/CommentPolicy.php @@ -44,7 +44,7 @@ public function delete($user, $model) return $_SERVER['restify.comment.delete'] ?? true; } - public function attachUser(object $user = null, $model, $userToAttach) + public function attachUser(?object $user, $model, $userToAttach) { return $_SERVER['restify.comment.allowAttachUser'] ?? true; } diff --git a/tests/Fixtures/Company/CompanyPolicy.php b/tests/Fixtures/Company/CompanyPolicy.php index 789445ea..f71853ae 100644 --- a/tests/Fixtures/Company/CompanyPolicy.php +++ b/tests/Fixtures/Company/CompanyPolicy.php @@ -16,7 +16,7 @@ class CompanyPolicy * * @return mixed */ - public function allowRestify(User $user = null) + public function allowRestify(?User $user = null) { return true; } diff --git a/tests/Fixtures/MailTracking.php b/tests/Fixtures/MailTracking.php index df35b3c0..a1f0c4b8 100644 --- a/tests/Fixtures/MailTracking.php +++ b/tests/Fixtures/MailTracking.php @@ -78,7 +78,7 @@ protected function assertEmailsSent($count) * @param string $body * @return MailTracking */ - protected function assertEmailEquals($body, Swift_Message $message = null) + protected function assertEmailEquals($body, ?Swift_Message $message = null) { $this->assertEquals( $body, @@ -95,7 +95,7 @@ protected function assertEmailEquals($body, Swift_Message $message = null) * @param string $excerpt * @return MailTracking */ - protected function assertEmailContains($excerpt, Swift_Message $message = null) + protected function assertEmailContains($excerpt, ?Swift_Message $message = null) { $this->assertContains( $excerpt, @@ -112,7 +112,7 @@ protected function assertEmailContains($excerpt, Swift_Message $message = null) * @param string $subject * @return MailTracking */ - protected function assertEmailSubject($subject, Swift_Message $message = null) + protected function assertEmailSubject($subject, ?Swift_Message $message = null) { $this->assertEquals( $subject, @@ -129,7 +129,7 @@ protected function assertEmailSubject($subject, Swift_Message $message = null) * @param string $recipient * @return MailTracking */ - protected function assertEmailTo($recipient, Swift_Message $message = null) + protected function assertEmailTo($recipient, ?Swift_Message $message = null) { $this->assertArrayHasKey( $recipient, @@ -146,7 +146,7 @@ protected function assertEmailTo($recipient, Swift_Message $message = null) * @param string $sender * @return MailTracking */ - protected function assertEmailFrom($sender, Swift_Message $message = null) + protected function assertEmailFrom($sender, ?Swift_Message $message = null) { $this->assertArrayHasKey( $sender, @@ -170,7 +170,7 @@ public function addEmail(Swift_Message $email) * * @return mixed */ - protected function getEmail(Swift_Message $message = null) + protected function getEmail(?Swift_Message $message = null) { $this->assertEmailWasSent(); diff --git a/tests/Fixtures/Post/Getters/PostsShowGetter.php b/tests/Fixtures/Post/Getters/PostsShowGetter.php index b7b5ca5c..1efce55a 100644 --- a/tests/Fixtures/Post/Getters/PostsShowGetter.php +++ b/tests/Fixtures/Post/Getters/PostsShowGetter.php @@ -10,7 +10,7 @@ class PostsShowGetter extends Getter { public static $uriKey = 'posts-show-getter'; - public function handle(Request $request, Model $model = null) + public function handle(Request $request, ?Model $model = null) { return ok('show works'); } diff --git a/tests/Fixtures/Post/PostPolicy.php b/tests/Fixtures/Post/PostPolicy.php index e6a91a8d..028359c9 100644 --- a/tests/Fixtures/Post/PostPolicy.php +++ b/tests/Fixtures/Post/PostPolicy.php @@ -44,7 +44,7 @@ public function delete($user, $post) return $_SERVER['restify.post.delete'] ?? true; } - public function attachUser(object $user = null, $post, $userToAttach) + public function attachUser(?object $user, $post, $userToAttach) { return $_SERVER['restify.post.allowAttachUser'] ?? true; } diff --git a/tests/IntegrationTestCase.php b/tests/IntegrationTestCase.php index 247e5e64..a344a015 100644 --- a/tests/IntegrationTestCase.php +++ b/tests/IntegrationTestCase.php @@ -116,7 +116,7 @@ public function repositories(): self return $this; } - protected function authenticate(Authenticatable $user = null): self + protected function authenticate(?Authenticatable $user = null): self { $this->actingAs($this->authenticatedAs = $user ?? Mockery::mock(MockUser::class)); diff --git a/tests/Prototypes/Prototypeable.php b/tests/Prototypes/Prototypeable.php index 7a83d950..7feb17e3 100644 --- a/tests/Prototypes/Prototypeable.php +++ b/tests/Prototypes/Prototypeable.php @@ -113,7 +113,7 @@ public function get(): TestResponse return $this->test->getJson(static::repositoryClass()::route()); } - public function create(Closure $assertable = null, Closure $tap = null): self + public function create(?Closure $assertable = null, ?Closure $tap = null): self { $this->ensureRepositoryClassDefined(); @@ -124,7 +124,7 @@ public function create(Closure $assertable = null, Closure $tap = null): self return $this->wirteableCallback($id, $assertable); } - public function update(string|int $key = null, Closure $assertable = null, Closure $tap = null): self + public function update(string|int|null $key = null, ?Closure $assertable = null, ?Closure $tap = null): self { $key = $key ?? $this->model()->getKey(); @@ -135,7 +135,7 @@ public function update(string|int $key = null, Closure $assertable = null, Closu return $this->wirteableCallback($id, $assertable); } - public function destroy(string|int $key = null, Closure $assertable = null, Closure $tap = null): self + public function destroy(string|int|null $key = null, ?Closure $assertable = null, ?Closure $tap = null): self { $key = $key ?? $this->model()->getKey(); @@ -146,7 +146,7 @@ public function destroy(string|int $key = null, Closure $assertable = null, Clos return $this; } - public function runAction(string $actionClass, array $payload = [], Closure $cb = null): self + public function runAction(string $actionClass, array $payload = [], ?Closure $cb = null): self { abort_unless(is_subclass_of($actionClass, Action::class), 400, __('Invalid class instance.')); @@ -166,7 +166,7 @@ public function runAction(string $actionClass, array $payload = [], Closure $cb return $this; } - protected function wirteableCallback(mixed $key, Closure $cb = null): self + protected function wirteableCallback(mixed $key, ?Closure $cb = null): self { if (is_null($key)) { return $this; diff --git a/tests/Repositories/RepositorySerializerTest.php b/tests/Repositories/RepositorySerializerTest.php index da36377b..404339fc 100644 --- a/tests/Repositories/RepositorySerializerTest.php +++ b/tests/Repositories/RepositorySerializerTest.php @@ -35,6 +35,8 @@ public function test_can_manually_serialize_repository(): void $assertable ->has('meta') ->has('data') + ->has('data.0.relationships.user') + ->where('data.0.type', 'posts') ->count('data', 20) ->etc(); }