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

chore: Fix wrong types #571

Merged
merged 1 commit into from
Apr 25, 2024
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
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);
}
}