Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Client Implementation #1

Merged
merged 7 commits into from
Aug 18, 2023
Merged

Add Client Implementation #1

merged 7 commits into from
Aug 18, 2023

Conversation

XedinUnknown
Copy link
Member

No description provided.

- Depend on the relevant PSR packages.
  * `psr/http-client` (PSR-18) provides the client and supplementary interfaces.
  * `psr/http-factory` (PSR-17) allows de-coupling from PSR-7 implementations.
  * `psr/http-factory-implementation` indicates that a real PSR-17 implementation is necessary for the code to work.
  * Dev dep `nyholm/psr7` fulfills the above requirement for test purposes.
- Deps for mocking.
  * The WP core itself. Besides symbols, it indicates that we depend on the latest version of WordPress for testing. This can be changed dynamically on CI later to test on a range, via CLI.
  * `brain/monkey` is a reliable tool for mocking functions, and is build with WordPress in mind, while being free of many of the architectural and other limitations of its competitors.

The `Client` class itself is very simple, as it only performs the conversion of a PSR-7 `RequestInterface` to the WP HTTP API, and of its return into `ResponseInterface`. Most likely, this implementation isn't 100% compliant with the official spec yet.
@XedinUnknown XedinUnknown added the enhancement New feature or request label Aug 18, 2023
@XedinUnknown XedinUnknown added this to the v0.1 milestone Aug 18, 2023
@XedinUnknown XedinUnknown self-assigned this Aug 18, 2023
It needed stubs, because it doesn't work well when it needs to scan a whole WP core codebase.

Some additional type information was also necessary.
PHPUnit 10.4-dev gives the following:

> PHP Fatal error:  A never-returning function must not return in /home/runner/work/http-client/http-client/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php on line 91
Seems that there might be issues with it, causing it to report that a never-returning function returns.

> PHP Fatal error:  A never-returning function must not return in /home/runner/work/http-client/http-client/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php on line 91

https://github.com/wp-oop/http-client/actions/runs/5901854051/job/16008901130?pr=1

https://github.com/sebastianbergmann/phpunit/blob/main/src/Framework/Constraint/Constraint.php#L91
`Client` now throws `ClientException` if problem sending or reassembling request.
At present, it is unclear how to determine specifically a network problem in order to throw the relevant exception.
@XedinUnknown XedinUnknown marked this pull request as ready for review August 18, 2023 12:37
@XedinUnknown XedinUnknown requested a review from mecha August 18, 2023 12:38
@XedinUnknown XedinUnknown merged commit c410337 into 0.1.x Aug 18, 2023
@XedinUnknown XedinUnknown deleted the feature/implement-client branch August 18, 2023 13:47
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants