-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(HasExceptionPipes, HasPipes): Refactor object type check for clarity
- Refactor type checking for objects in both HasExceptionPipes and HasPipes traits. - Change use of 'and' to '&&' for better readability. - Improve code clarity by explicitly handling object instances before assigning class names. - Ensure functionality remains consistent while enhancing maintainability.
- Loading branch information
Showing
9 changed files
with
88 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** @noinspection PhpInternalEntityUsedInspection */ | ||
/** @noinspection AnonymousFunctionStaticInspection */ | ||
/** @noinspection StaticClosureCanBeUsedInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2024 guanguans<ityaozm@gmail.com> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/guanguans/laravel-api-response | ||
*/ | ||
|
||
it('can cast type', function ($data): void { | ||
expect($this->apiResponse()->castToNull()->success($data)->getData(true)['data'])->toBeNull() | ||
->and($this->apiResponse()->castToNull()->success($data)->getData()->data)->toBeNull() | ||
->and($this->apiResponse()->castToInteger()->success($data)->getData(true)['data'])->toBeInt() | ||
->and($this->apiResponse()->castToInteger()->success($data)->getData()->data)->toBeInt() | ||
->and($this->apiResponse()->castToFloat()->success($data)->getData(true)['data'])->toBeNumeric() // 0, float | ||
->and($this->apiResponse()->castToFloat()->success($data)->getData()->data)->toBeNumeric() // 0, float | ||
->and($this->apiResponse()->castToString()->success($data)->getData(true)['data'])->toBeString() | ||
->and($this->apiResponse()->castToString()->success($data)->getData()->data)->toBeString() | ||
->and($this->apiResponse()->castToBoolean()->success($data)->getData(true)['data'])->toBeBool() | ||
->and($this->apiResponse()->castToBoolean()->success($data)->getData()->data)->toBeBool() | ||
->and($this->apiResponse()->castToArray()->success($data)->getData(true)['data'])->toBeArray() | ||
// ->and($this->apiResponse()->castToArray()->success($data)->getData()->data)->toBeArray() | ||
// ->and($this->apiResponse()->castToObject()->success($data)->getData(true)['data'])->toBeObject() | ||
->and($this->apiResponse()->castToObject()->success($data)->getData()->data)->toBeObject(); | ||
})->group(__DIR__, __FILE__)->with([ | ||
null, | ||
1, | ||
1.1, | ||
'string', | ||
true, | ||
fn (): array => [], | ||
fn (): array => ['foo', 'bar', 'baz'], | ||
fn (): array => ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], | ||
(object) [], | ||
(object) ['foo', 'bar', 'baz'], | ||
(object) ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters