Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[API] Refactor ApiPlatformClient ver.1 #11210

Merged
merged 9 commits into from
Mar 13, 2020

Conversation

Zales0123
Copy link
Member

@Zales0123 Zales0123 commented Mar 11, 2020

Q A
Branch? api
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets
License MIT

Changes:

  • extraction of Request object, that knows about all technical details of the sent request (headers, method, URL, optionally content)
  • splitting the ApiPlatformClient into two services: one sending requests (still named ApiPlatformClient), the other for checking the response and getting its values (named ResponseChecker)
  • setting the resource per ApiPlatformClient to not being forced to specify it on each request

Known issues:

  • filter method still operates kinda old way (we can consider merging it with the index or separating another Request type)
  • ApiSecurityService is still not refactored (the question is - should it)

It should also allow us to operate on multiple responses easier 🖖

I'm open for the discussion regarding naming and proposed solutions - we should make this service as perfect as possible 💃

@Zales0123 Zales0123 added DX Issues and PRs aimed at improving Developer eXperience. API APIs related issues and PRs. labels Mar 11, 2020
@Zales0123 Zales0123 requested a review from a team as a code owner March 11, 2020 14:56
Copy link
Contributor

@pamil pamil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be continued 🎉


$this->request('GET', $path, ['HTTP_ACCEPT' => 'application/ld+json']);
}
$path = sprintf('/new-api/%s?%s', $this->resource, $query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we include a dedicated method in Request object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've mentioned it in the PR description 👍

$this->content[$key][] = $subresource;
}

private function mergeArraysUniquely(array $firstArray, array $secondArray): array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference from array_merge_recursive? Would be cool to mention.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not duplicate values for the same keys. But yes, it should be in the comment 👌


public function updateRequestData(array $data): void;
public function show(string $id): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be cool if it could return a response.

src/Sylius/Behat/Client/ApiClientInterface.php Outdated Show resolved Hide resolved
@GSadee GSadee added the Behat Issues and PRs aimed at improving Behat usage. label Mar 13, 2020
@GSadee GSadee force-pushed the refactor-api-client branch 2 times, most recently from 7a50318 to 91de8e7 Compare March 13, 2020 09:21
use Sylius\Behat\Client\ApiClientInterface;
use Webmozart\Assert\Assert;

final class NotificationContext implements Context
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it wasn't a bad idea to have these checks in one place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I have no idea, how it should be implemented since we have api client per resource 😞

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't, but we also would have to register this context with each api_platform_client, as there is a requirement to have the resource property set. In theory - it doesn't matter, as we only check the status. But we still need to get the response from the client :/ So in a result - it's worth to be refactored, but probably not now 🖖

*/
public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void
{
Assert::true($this->responseChecker->isCreationSuccessful($this->client->getLastResponse()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few true/false assertion without any comment, which will end up with an awesome error: "Expected true, got false"

We should do something about it in the next iteration

@lchrusciel lchrusciel merged commit ca193ac into Sylius:api Mar 13, 2020
@lchrusciel
Copy link
Member

Thanks, Mateusz! 🥇

@Zales0123
Copy link
Member Author

And Grzegorz! 🐎

lchrusciel added a commit that referenced this pull request Mar 13, 2020
…Sadee)

This PR was merged into the api branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | api
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | fixes #11210 (comment)
| License         | MIT


Commits
-------

e360744 [API][Behat] Add comment to notification assertion
@lchrusciel
Copy link
Member

Part of #11250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API APIs related issues and PRs. Behat Issues and PRs aimed at improving Behat usage. DX Issues and PRs aimed at improving Developer eXperience.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants