-
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
Merged
tienvx
merged 2 commits into
pact-foundation:ffi
from
tienvx:create-matchers-and-generators-classes
Dec 18, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
7 changes: 7 additions & 0 deletions
7
src/PhpPact/Consumer/Matcher/Exception/MatcherNotSupportedException.php
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,7 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Exception; | ||
|
||
class MatcherNotSupportedException extends MatcherException | ||
{ | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.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)
byintegerV3(13)
But there is 1 problem:
If I use
integerV3(13)
, the generatorProviderState
is still not working (it's because of PHP, not Rust. See GeneratorAwareMatcher)That's why I replace
integerV3(13)
by justintegerV3()
.That's why
13
is replaced bynull
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 generatorProviderState
?There are 2 reasons:
pact:generator:type = 'ProviderState'
into the final json.ProviderState
generator is a bit different from other generators: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.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 checkif (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.
It's a good point actually.
Unfortunately, adding a simple condition
if (null === $this->getValue() || $this->generator instanceof ProviderState) {
doesn't helpI 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