-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(changelog): add changelog, remove example, add a test for using …
…multiple traits
- Loading branch information
Showing
6 changed files
with
121 additions
and
207 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
## Changes | ||
|
||
## 0.12.0 - 11/05/2023 | ||
|
||
* **[BC BREAK]** No more yield, use php fiber instead | ||
* **[BC BREAK]** Make http test case as an option | ||
* **[BC BREAK]** No more global test case case | ||
* **[BC BREAK]** Use PHP attribute instead of annotation | ||
* Add a new test case trait for API | ||
|
||
### Migrating from 0.11 | ||
|
||
The API for asynit has changed, you need to update your test cases. | ||
|
||
#### Before | ||
|
||
```php | ||
<?php | ||
|
||
class HttpbinTest extends \Asynit\TestCase | ||
{ | ||
/** @\Asynit\Annotation\Depend('getToken') */ | ||
public function testGet($token) | ||
{ | ||
$response = yield $this->get('https://httpbin.org'); | ||
$response = yield $this->get('http://httpbin.org', ['Authorization' => 'Bearer {token}']); | ||
$this->assertStatusCode(200, $response); | ||
} | ||
|
||
public function getToken() | ||
{ | ||
return 'my_token'; | ||
} | ||
} | ||
``` | ||
|
||
#### After | ||
|
||
```php | ||
|
||
<?php | ||
|
||
#[\Asynit\Attribute\TestCase] | ||
class HttpbinTest | ||
{ | ||
use \Asynit\HttpClient\HttpClientWebCaseTrait; | ||
|
||
#[\Asynit\Attribute\Depend('getToken')] | ||
public function testGet($token) | ||
{ | ||
$response = $this->get('http://httpbin.org', ['Authorization' => 'Bearer {token}']); | ||
$this->assertStatusCode(200, $response); | ||
} | ||
|
||
public function getToken() | ||
{ | ||
return 'my_token'; | ||
} | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,54 @@ | ||
<?php | ||
|
||
namespace Asynit\Tests; | ||
|
||
use Asynit\Attribute\TestCase; | ||
use Asynit\HttpClient\ApiResponse; | ||
use Asynit\HttpClient\HttpClientApiCaseTrait; | ||
use Asynit\HttpClient\HttpClientWebCaseTrait; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
#[TestCase] | ||
class WebAndApiTests | ||
{ | ||
use HttpClientWebCaseTrait, HttpClientApiCaseTrait { | ||
HttpClientWebCaseTrait::get insteadof HttpClientApiCaseTrait; | ||
HttpClientWebCaseTrait::post insteadof HttpClientApiCaseTrait; | ||
HttpClientWebCaseTrait::patch insteadof HttpClientApiCaseTrait; | ||
HttpClientWebCaseTrait::put insteadof HttpClientApiCaseTrait; | ||
HttpClientWebCaseTrait::options insteadof HttpClientApiCaseTrait; | ||
HttpClientWebCaseTrait::delete insteadof HttpClientApiCaseTrait; | ||
HttpClientApiCaseTrait::get as private getApi; | ||
HttpClientApiCaseTrait::post as private postApi; | ||
HttpClientApiCaseTrait::patch as patchApi; | ||
HttpClientApiCaseTrait::put as putApi; | ||
HttpClientApiCaseTrait::options as optionsApi; | ||
HttpClientApiCaseTrait::delete as deleteApi; | ||
} | ||
|
||
public function testJsonWeb() | ||
{ | ||
$response = $this->get($this->createUri('/get')); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $response); | ||
$this->assertStatusCode(200, $response); | ||
|
||
$content = json_decode($response->getBody()->getContents(), true); | ||
$this->assertArrayNotHasKey('Content-Type', $content['headers']); | ||
|
||
} | ||
|
||
public function testJsonApi() | ||
{ | ||
$response = $this->getApi($this->createUri('/get')); | ||
|
||
$this->assertInstanceOf(ApiResponse::class, $response); | ||
$this->assertStatusCode(200, $response); | ||
$this->assertSame('application/json', $response['headers']['Content-Type']); | ||
} | ||
|
||
protected function createUri(string $uri): string | ||
{ | ||
return 'http://127.0.0.1:8081'.$uri; | ||
} | ||
} |