Skip to content

Commit

Permalink
Merge pull request #571 from tienvx/fix-wrong-types
Browse files Browse the repository at this point in the history
chore: Fix wrong types
  • Loading branch information
tienvx authored Apr 25, 2024
2 parents 3135b2f + 6ee3096 commit 6285191
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
8 changes: 5 additions & 3 deletions tests/PhpPact/Consumer/Matcher/Matchers/StatusCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ protected function getMatcherWithExampleValue(): GeneratorAwareMatcher
* ["serverError", null, "{\"pact:matcher:type\":\"statusCode\",\"pact:generator:type\":\"RandomInt\",\"status\":\"serverError\",\"min\":500,\"max\":599}"]
* ["nonError", null, "{\"pact:matcher:type\":\"statusCode\",\"pact:generator:type\":\"RandomInt\",\"status\":\"nonError\",\"min\":100,\"max\":399}"]
* ["error", null, "{\"pact:matcher:type\":\"statusCode\",\"pact:generator:type\":\"RandomInt\",\"status\":\"error\",\"min\":400,\"max\":599}"]
* ["info", "123", "{\"pact:matcher:type\":\"statusCode\",\"status\":\"info\",\"value\":123}"]
* ["info", 123, "{\"pact:matcher:type\":\"statusCode\",\"status\":\"info\",\"value\":123}"]
*/
public function testSerialize(string $status, ?string $value, ?string $json): void
public function testSerialize(string $status, ?int $value, ?string $json): void
{
if (!$json) {
$this->expectException(InvalidHttpStatusException::class);
$this->expectExceptionMessage("Status 'invalid' is not supported. Supported status are: info, success, redirect, clientError, serverError, nonError, error");
}
$matcher = new StatusCode($status, $value);
$this->assertSame($json, json_encode($matcher));
$jsonEncoded = json_encode($matcher);
$this->assertIsString($jsonEncoded);
$this->assertJsonStringEqualsJsonString($json, $jsonEncoded);
}
}
13 changes: 4 additions & 9 deletions tests/PhpPact/Consumer/Matcher/Matchers/StringValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@

class StringValueTest extends TestCase
{
protected StringValue $matcher;

protected function setUp(): void
{
$this->matcher = new StringValue();
}

/**
* @testWith [null, "{\"pact:matcher:type\":\"type\",\"value\":\"some string\",\"pact:generator:type\":\"RandomString\",\"size\":10}"]
* ["test", "{\"pact:matcher:type\":\"type\",\"value\":\"test\"}"]
*/
public function testSerialize(?string $value, string $json): void
{
$this->matcher = new StringValue($value);
$this->assertJsonStringEqualsJsonString($json, json_encode($this->matcher));
$matcher = new StringValue($value);
$jsonEncoded = json_encode($matcher);
$this->assertIsString($jsonEncoded);
$this->assertJsonStringEqualsJsonString($json, $jsonEncoded);
}
}

0 comments on commit 6285191

Please sign in to comment.