-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb2fa6f
commit 82aeba6
Showing
9 changed files
with
77 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the jiannei/laravel-response. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Jiannei\Response\Laravel\Tests\Enums; | ||
|
||
use Jiannei\Enum\Laravel\Support\Traits\EnumEnhance; | ||
|
@@ -29,4 +38,4 @@ enum ResponseEnum: int | |
case SYSTEM_CACHE_CONFIG_ERROR = 500003; | ||
case SYSTEM_CACHE_MISSED_ERROR = 500004; | ||
case SYSTEM_CONFIG_ERROR = 500005; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the jiannei/laravel-response. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
test('example', function () { | ||
expect(true)->toBeTrue(); | ||
}); |
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 |
---|---|---|
@@ -1,17 +1,15 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The closure you provide to your test functions is always bound to a specific PHPUnit test | ||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may | ||
| need to change it using the "uses()" function to bind a different classes or traits. | ||
| | ||
*/ | ||
* This file is part of the jiannei/laravel-response. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Response\Laravel\Tests\TestCase::class)->in('Unit'); | ||
uses(\Jiannei\Response\Laravel\Tests\TestCase::class)->in('Unit'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
|
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the jiannei/laravel-response. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
use Illuminate\Http\Exceptions\HttpResponseException; | ||
use Illuminate\Support\Arr; | ||
use Jiannei\Response\Laravel\Support\Facades\Response; | ||
|
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 |
---|---|---|
@@ -1,13 +1,20 @@ | ||
<?php | ||
|
||
use Jiannei\Response\Laravel\Support\Facades\Response; | ||
/* | ||
* This file is part of the jiannei/laravel-response. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
use Jiannei\Response\Laravel\Support\Facades\Response; | ||
|
||
test('add extra field', function () { | ||
$response = Response::success(); | ||
|
||
expect($response->status())->toEqual(200) | ||
->and($response->getData(true))->toHaveKey('extra') | ||
->and($response->getData(true)['extra'])->toHaveKey('time'); | ||
|
||
}); |
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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the jiannei/laravel-response. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
use Illuminate\Support\Arr; | ||
use Jiannei\Enum\Laravel\Support\Enums\HttpStatusCode; | ||
use Jiannei\Response\Laravel\Support\Facades\Response; | ||
use Jiannei\Response\Laravel\Tests\Enums\ResponseEnum; | ||
use Jiannei\Response\Laravel\Tests\Repositories\Models\User; | ||
use Jiannei\Response\Laravel\Tests\Repositories\Resources\UserCollection; | ||
use Jiannei\Response\Laravel\Tests\Repositories\Resources\UserResource; | ||
|
||
|
||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class); | ||
|
||
test('success', function () { | ||
|
@@ -45,12 +52,12 @@ | |
|
||
expect($response->status())->toEqual(202) | ||
->and($response->getContent())->toBeJson(json_encode([ | ||
'status' => 'success', | ||
'code' => 202, | ||
'message' => '', | ||
'data' => (object) [], | ||
'error' => (object) [], | ||
])); | ||
'status' => 'success', | ||
'code' => 202, | ||
'message' => '', | ||
'data' => (object) [], | ||
'error' => (object) [], | ||
])); | ||
}); | ||
|
||
test('no content', function () { | ||
|
@@ -59,12 +66,12 @@ | |
|
||
expect($response->status())->toEqual(204) | ||
->and($response->getContent())->toBeJson(json_encode([ | ||
'status' => 'success', | ||
'code' => 204, | ||
'message' => '', | ||
'data' => (object) [], | ||
'error' => (object) [], | ||
])); | ||
'status' => 'success', | ||
'code' => 204, | ||
'message' => '', | ||
'data' => (object) [], | ||
'error' => (object) [], | ||
])); | ||
}); | ||
|
||
test('success with array data', function () { | ||
|
@@ -140,7 +147,7 @@ | |
|
||
expect($response->status())->toEqual(200); | ||
|
||
$formatData = Arr::map($users->items(), fn($item) => [ | ||
$formatData = Arr::map($users->items(), fn ($item) => [ | ||
'nickname' => $item->name, | ||
'email' => $item->email, | ||
]); | ||
|
@@ -210,7 +217,7 @@ | |
|
||
expect($response->status())->toEqual(200); | ||
|
||
$formatData = Arr::map($users->items(), fn($item) => $item->toArray()); | ||
$formatData = Arr::map($users->items(), fn ($item) => $item->toArray()); | ||
|
||
$data = [ | ||
'data' => $formatData, | ||
|
@@ -247,7 +254,7 @@ | |
|
||
expect($response->status())->toEqual(200); | ||
|
||
$formatData = Arr::map($users->items(), fn($item) => $item->toArray()); | ||
$formatData = Arr::map($users->items(), fn ($item) => $item->toArray()); | ||
|
||
$data = [ | ||
'data' => $formatData, | ||
|
@@ -282,7 +289,7 @@ | |
|
||
expect($response->status())->toEqual(200); | ||
|
||
$formatData = Arr::map($users->items(), fn($item) => $item->toArray()); | ||
$formatData = Arr::map($users->items(), fn ($item) => $item->toArray()); | ||
|
||
$data = [ | ||
'data' => $formatData, | ||
|
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