-
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.
feat: support get data before response
- Loading branch information
Showing
4 changed files
with
68 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,3 +267,42 @@ | |
'error' => [], | ||
]); | ||
}); | ||
|
||
test('get formatted data before response', function () { | ||
$data = Format::data([ | ||
'name' => 'Jiannei', | ||
'email' => '[email protected]', | ||
], '创建成功', 201); | ||
|
||
expect($data->get())->toMatchArray([ | ||
'status' => 'success', | ||
'code' => 201, | ||
'message' => '创建成功', | ||
'data' => [ | ||
'name' => 'Jiannei', | ||
'email' => '[email protected]', | ||
], | ||
'error' => (object) [], | ||
]); | ||
|
||
$response = $data->response(); | ||
|
||
expect($response->status())->toEqual(201) | ||
->and($response->getData(true))->toMatchArray([ | ||
'status' => 'success', | ||
'code' => 201, | ||
'message' => '创建成功', | ||
'data' => [ | ||
'name' => 'Jiannei', | ||
'email' => '[email protected]', | ||
], | ||
'error' => [], | ||
]); | ||
}); | ||
|
||
test('compare data and success', function () { | ||
expect(Response::success()->status())->toEqual(Format::data(null, '', 200)->response()->status()) | ||
->and(Response::success()->content())->toEqual(Format::data(null, '', 200)->response()->content()); | ||
}); | ||
|
||
|