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
[WIP] Feature | V3 - Request validator #291
base: v3
Are you sure you want to change the base?
[WIP] Feature | V3 - Request validator #291
Conversation
Hey @bobmulder thanks so much for working on this! 🙌 I'm a little busy tonight but I'll be taking a look over the weekend :) |
Thats fine Sam. I just want to check with you if the general setup is right. I'll try to do the pending work next week. |
Hey @bobmulder I've had a little look over and it looks good so far. Happy with the folder structure and I like your "check" contract - that looks good. With regards to the What are your thoughts? I realise that this is something I think I have forgotten to update - the |
Yeeha @Sammyjo20! I think you're completely right about the Can you tell me what should be changed? Should Without any knowledge about I'll get to know some more about pending requests today first. |
Hey @bobmulder I've had a re-think about the structure of some of the testing helpers. Would you mind moving the testing validators into a "Testing" directory inside of the "Helpers" directory? So we'll be able to use With the Update: Just to clarify - here's what I'm thinking we could change it to. Currently the $mockClient->assertSent(GetForgeServersRequest::class); // Stays the same
$mockClient->assertSent(function (PendingRequest $pendingRequest) {
RequestValidator::make($pendingRequest)
->hasHeader()
->instanceOf()
->etc()
}); |
Hey @bobmulder - I hope you are well! I just had an idea. What if, instead of creating a $mockClient->assertSentWithValidate(function (RequestValidator $validator) {
$validator
->hasHeader()
->instanceOf()
->etc()
}); |
Sorry for the delay, @Sammyjo20. I think your idea is pretty nice, I love it. It's close to one of the suggestions I posted in the discussion. However, no matter how we would integrate the validator, we would need a validator class. Also, for testing purposes and to apply SRP I think it's a good idea to create a validator class which will do the heavy lifting, and create some 'glue' afterwards to integrate it nicely for testing (like your The only thing I'm struggling right now is: should the validator class support |
Hey @bobmulder apologies for the delay - with v3 launch and the book launch I decided to take a step away for a few weeks. Would love to keep working on this with you - I'm glad that you like my suggestion :) I think we should use the pending request to be honest - that has the single source of truth and contains things merged from the connector/request and would be the closest to the actual request sent. Or - what if you used the PSR-7 request? You can get it with |
Hi Sam, I don't blame you because I haven't done much on the PR as well ;). I understand the Next week, I'll try to change my idea to supporting Wish you all the best! |
No worries at all 🤠 It's a very fair point about the interface - I would be very happy to add an interface as long as it doesn't introduce a breaking change, which I don't think it would? The interface would just need to include things like Wish you all the best too!! |
@Sammyjo20, I changed the Nice thing I realised when working on the public function valid(): bool
{
return $this->actual->getRequest() instanceof $this->expected;
} I also moved the Next, I'm going to work out some more checks! |
Just marking this as draft as it's still WIP - keep up the great work @bobmulder ! |
Hi Sammy, I lost track on this one but I'm motivated to finish the PR since I think it's pretty useful. Can we together work out a todo list of what needs to be done to get this ready to merge? I'd appreciate and finish the pending work. |
Hey @bobmulder Happy New Year. That's okay, these things happen. I'm not able to spend a huge amount of time on Saloon at the moment but over the next few weeks I will try to write up a list of things to do. I've also been thinking of ways to improve the testing in Saloon so I can include those changes too if you like? |
Hey @bobmulder how are you doing? Do you have any further plans for this PR or shall we revisit it in the future? ❤️ |
This PR introduces the
RequestValidator
as discussed in #275.At the moment of writing, it's a first draft to align our ideas. After that, the missing checks and tests will be added.
I decided to create dedicated
*Check
classes. This way, they have their own responsibility, can be tested separately and can have more context (likemessage()
)Questions to @Sammyjo20:
PendingRequests
are supported?The following checks are included:
BodyEqualsCheck
EndpointContainsCheck
EndpointEndsWithCheck
EndpointStartsWithCheck
InstanceOfCheck
QueryEqualsCheck