Skip to content
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

feat: Support 'arrayContains' matcher in query and header #551

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/PhpPact/Consumer/Matcher/Matchers/ArrayContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpPact\Consumer\Matcher\Matchers;

use PhpPact\Consumer\Matcher\Formatters\MinimalFormatter;
use PhpPact\Consumer\Matcher\Formatters\ValueRequiredFormatter;

/**
* Checks if all the variants are present in an array.
Expand All @@ -14,23 +14,23 @@ class ArrayContains extends AbstractMatcher
*/
public function __construct(private array $variants)
{
$this->setFormatter(new MinimalFormatter());
$this->setFormatter(new ValueRequiredFormatter());
}

/**
* @return array<string, mixed>
*/
protected function getAttributesData(): array
{
return ['variants' => array_values($this->variants)];
return ['variants' => $this->getValue()];
}

/**
* @todo Change return type to `null`
* @return array<mixed>
*/
public function getValue(): mixed
public function getValue(): array
{
return null;
return array_values($this->variants);
}

public function getType(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testSerialize(): void
];
$array = new ArrayContains($variants);
$this->assertSame(
'{"pact:matcher:type":"arrayContains","variants":[{"pact:matcher:type":"type","value":"string"},{"pact:matcher:type":"integer","pact:generator:type":"RandomInt","min":0,"max":10}]}',
'{"pact:matcher:type":"arrayContains","variants":[{"pact:matcher:type":"type","value":"string"},{"pact:matcher:type":"integer","pact:generator:type":"RandomInt","min":0,"max":10}],"value":[{"pact:matcher:type":"type","value":"string"},{"pact:matcher:type":"integer","pact:generator:type":"RandomInt","min":0,"max":10}]}',
json_encode($array)
);
}
Expand Down