Skip to content

Commit

Permalink
Add validating test
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Sep 17, 2024
1 parent 21053a8 commit 46d25c2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests/unit/Codeception/Module/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public function testSeeResponseJsonXpathEvaluatesToBoolean()
$this->setStubResponse('{"success": 1}');
$this->module->seeResponseJsonXpathEvaluatesTo('count(//success) > 0', true);
}

public function testSeeResponseJsonXpathEvaluatesToNumber()
{
$this->setStubResponse('{"success": 1}');
Expand All @@ -587,7 +587,7 @@ public function testDontSeeResponseJsonXpathEvaluatesToBoolean()
$this->setStubResponse('{"success": 1}');
$this->module->dontSeeResponseJsonXpathEvaluatesTo('count(//success) > 0', false);
}

public function testDontSeeResponseJsonXpathEvaluatesToNumber()
{
$this->setStubResponse('{"success": 1}');
Expand Down Expand Up @@ -649,7 +649,7 @@ public function testHaveServerParameter()
* @dataProvider schemaAndResponse
*/

public function testSeeResponseIsValidOnJsonSchemachesJsonSchema(string $schema, string $response, bool $outcome, string $error)
public function testSeeResponseIsValidOnJsonSchemaMatchesJsonSchema(string $schema, string $response, bool $outcome, string $error)
{
$response = file_get_contents(codecept_data_dir($response));
$this->setStubResponse($response);
Expand All @@ -662,7 +662,7 @@ public function testSeeResponseIsValidOnJsonSchemachesJsonSchema(string $schema,
$this->module->seeResponseIsValidOnJsonSchema(codecept_data_dir($schema));
}

public function testSeeResponseIsValidOnJsonSchemachesJsonSchemaString()
public function testSeeResponseIsValidOnJsonSchemaMatchesJsonSchemaString()
{
$this->setStubResponse('{"name": "john", "age": 20}');
$this->module->seeResponseIsValidOnJsonSchemaString('{"type": "object"}');
Expand All @@ -678,6 +678,14 @@ public function testSeeResponseIsValidOnJsonSchemachesJsonSchemaString()
$this->module->seeResponseIsValidOnJsonSchemaString(json_encode($schema, JSON_THROW_ON_ERROR));
}

public function testSeeResponseIsInvalidOnJsonSchemaMatchesJsonSchemaString()
{
$this->setStubResponse('{"name": null, "age": 20}');
$this->expectExceptionMessage("[Property: 'name'] NULL value found, but a string is required");
$this->shouldFail();
$this->module->seeResponseIsValidOnJsonSchemaString('{"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "integer"}}}');
}

/**
* @dataProvider configAndRequestUrls
*/
Expand Down

0 comments on commit 46d25c2

Please sign in to comment.