-
Notifications
You must be signed in to change notification settings - Fork 92
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
refactor: Use matcher and generator classes #372
refactor: Use matcher and generator classes #372
Conversation
This is quite a big PR. I'll make time to review, but I may not get to it until mid next week if that's alright. |
5da2153
to
05c5213
Compare
It's totally fine. Thanks |
05c5213
to
86e85f5
Compare
Hi @Lewiscowles1986 , @Greg0 Are you still interested in reviewing PRs from this project? |
|
|
First PR: #375 ~ 600 lines. Is it okay, or I need to split PRs for each generator? |
Nevermind, 600 lines PR is still too big, split again. First PR: #376 |
I will gladly look at this to the end of the year. Some covid here 😉 |
@tienvx if this were rebased, how many lines would now be delivered? |
It's about ~1400 lines Which do you prefer? rebase or create new PR? |
86e85f5
to
a76d914
Compare
Rebased for now. I will try to split into smaller PRs |
a76d914
to
44dff56
Compare
44dff56
to
fb404e6
Compare
No need to split, anything under 1000 lines (this was 2.5k) can be worked on. I Have a strong preference for soft-limit of 500 lines (ignoring lock files) |
@@ -14,7 +14,7 @@ | |||
"request": { | |||
"body": { | |||
"content": { | |||
"id": 13 | |||
"id": null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one feels off. Do you have a bit more of an explanation on why the id has changed if the matcher is working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 2 methods:
integer(13)
usedType
matching rule, with require an integer as example value. This matching rule doesn't support a generator.integerV3(13)
usedInteger
matching rule. This one doesn't require example value. So it support generator.
In this example, I want to test ProviderState
generator.
- Because
Type
doesn't support generator, I will got the (new)MatcherNotSupportedException
exception. Integer
, on the other hand, support generator, so we didn't get this exception.
So that's why I replace integer(13)
by integerV3(13)
But there is 1 problem:
If I use integerV3(13)
, the generator ProviderState
is still not working (it's because of PHP, not Rust. See GeneratorAwareMatcher)
That's why I replace integerV3(13)
by just integerV3()
.
That's why 13
is replaced by null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may ask: Why on the old code, integer(13)
still work with the generator ProviderState
?
There are 2 reasons:
- I didn't do any checking in the code, just assign the
pact:generator:type = 'ProviderState'
into the final json. ProviderState
generator is a bit different from other generators:- Other generators work on consumer side, so if there is example value (e.g.
13
), generator will not have any effects. ProviderState
generator work on provider side. The example value (e.g.13
) will be replaced by the value from the provider state anyway.
- Other generators work on consumer side, so if there is example value (e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can update GeneratorAwareMatcher
, add additional check if (null === $this->getValue() || $this->generator instanceof ProviderState) {
, but I think it's unnecessary condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think the additional if statement will make it so that regression and surprise cannot take place, and the API is easier to think about. Computational cost vs user brain cost; but I'll approve (you've been very patient).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think the additional if statement will make it so that regression and surprise cannot take place...
It's a good point actually.
regression
Unfortunately, adding a simple condition if (null === $this->getValue() || $this->generator instanceof ProviderState) {
doesn't help
surprise
I think we shouldn't allow these code at the first place:
$this->matcher->fromProviderState($this->matcher->integer(123), '${id}')
$this->matcher->fromProviderState($this->matcher->integerV3(123), '${id}')
Example value can't be used along with generator. Generator will be silently ignored without any notice (except for ProviderState
, example value will be ignored). User will be surprised. So I created this PR to handle that #420
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is broadly very good. One question needs answering around the id
changing; but once we have that down, this looks very good. Thank you for your patience with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've done so much work here. Please be very proud!
Depends on #373, please review it first