Use `eachValue` matcher for query parameter. See t...
# libpact_ffi-users
t
Use
eachValue
matcher for query parameter. See this thread for more details:
Use
regex
matcher with array of values to match multiple values for query parameter works fine. See this thread https://pact-foundation.slack.com/archives/C02BXLDJ7JR/p1698024666918839
But when I replace
regex
by
eachValue
matcher, it doesn't work as I expected:
Client DSL:
Copy code
- 'locales[]' => [
-     json_encode($this->matcher->regex(['en-US'], '^[a-z]{2}-[A-Z]{2}$')),
- ],
+ 'locales[]' => [
+     json_encode($this->matcher->eachValue(['en-US'], [$this->matcher->regex(null, '^[a-z]{2}-[A-Z]{2}$')])),
+ ],
FFI call:
Copy code
pactffi_with_query_parameter_v2($interactionId, 'locales[]', 0, '"{"rules":[{"regex":"^[a-z]{2}-[A-Z]{2}$","pact:matcher:type":"regex","pact:generator:type":"Regex"}],"value":["en-US"],"pact:matcher:type":"eachValue"}"');
Http client's query:
Copy code
locales[]=en-US&locales[]=en-AU
Log:
Copy code
2023-10-28T07:21:35.888456Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing 'en-US' to 'en-US' ==> false cascaded=false matcher=EachValue(MatchingRuleDefinition { value: "[\"en-US\"]", value_type: Unknown, rules: [Left(Regex("^[a-z]{2}-[A-Z]{2}$"))], generator: None })
2023-10-28T07:21:35.888506Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '' to 'en-AU' ==> false cascaded=false matcher=EachValue(MatchingRuleDefinition { value: "[\"en-US\"]", value_type: Unknown, rules: [Left(Regex("^[a-z]{2}-[A-Z]{2}$"))], generator: None })
2023-10-28T07:21:35.888576Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: [QueryMismatch { parameter: "locales[]", expected: "en-US", actual: "en-US", mismatch: "Unable to match 'en-US' using EachValue(MatchingRuleDefinition { value: \"[\\\"en-US\\\"]\", value_type: Unknown, rules: [Left(Regex(\"^[a-z]{2}-[A-Z]{2}$\"))], generator: None })" }, QueryMismatch { parameter: "locales[]", expected: "", actual: "en-AU", mismatch: "Unable to match '' using EachValue(MatchingRuleDefinition { value: \"[\\\"en-US\\\"]\", value_type: Unknown, rules: [Left(Regex(\"^[a-z]{2}-[A-Z]{2}$\"))], generator: None })" }]
Is this a bug?
r
EachValue
was written to support ignoring the keys in a map like structure in the body. Only really for JSON objects. It will probably not work with anything else.
EachKey
is the same