Search code examples
phppact

Accept any number in pacts somethingLike


in my clients pact-contract I have rules like

{
   foo: like(1.2)
}

What I want to require is that foo is a either a float, or an integer. On the provider side however pact tests fail for integers.

My provider-side (PHP) looks something like this:

myApi() {
   return [
      foo => (float) 1 // Returns 1 in PHP, not 1.0
   ];
}

Does the provider really need to return 1.0 instead of 1 or is it possible to write the contract in a different way?


Solution

  • See https://github.com/pact-foundation/pact-ruby/issues/191 (and other related such as https://github.com/pact-foundation/pact-js/issues/94). It should actually now be supported by the framework based on feedback and discussion.

    Pact PHP needs to upgrade to the latest of this underlying library (it is an engine used under the hood) and it should just work