Skip to content

Commit 46d25c2

Browse files
committedSep 17, 2024··
Add validating test
1 parent 21053a8 commit 46d25c2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
 

‎tests/unit/Codeception/Module/RestTest.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public function testSeeResponseJsonXpathEvaluatesToBoolean()
575575
$this->setStubResponse('{"success": 1}');
576576
$this->module->seeResponseJsonXpathEvaluatesTo('count(//success) > 0', true);
577577
}
578-
578+
579579
public function testSeeResponseJsonXpathEvaluatesToNumber()
580580
{
581581
$this->setStubResponse('{"success": 1}');
@@ -587,7 +587,7 @@ public function testDontSeeResponseJsonXpathEvaluatesToBoolean()
587587
$this->setStubResponse('{"success": 1}');
588588
$this->module->dontSeeResponseJsonXpathEvaluatesTo('count(//success) > 0', false);
589589
}
590-
590+
591591
public function testDontSeeResponseJsonXpathEvaluatesToNumber()
592592
{
593593
$this->setStubResponse('{"success": 1}');
@@ -649,7 +649,7 @@ public function testHaveServerParameter()
649649
* @dataProvider schemaAndResponse
650650
*/
651651

652-
public function testSeeResponseIsValidOnJsonSchemachesJsonSchema(string $schema, string $response, bool $outcome, string $error)
652+
public function testSeeResponseIsValidOnJsonSchemaMatchesJsonSchema(string $schema, string $response, bool $outcome, string $error)
653653
{
654654
$response = file_get_contents(codecept_data_dir($response));
655655
$this->setStubResponse($response);
@@ -662,7 +662,7 @@ public function testSeeResponseIsValidOnJsonSchemachesJsonSchema(string $schema,
662662
$this->module->seeResponseIsValidOnJsonSchema(codecept_data_dir($schema));
663663
}
664664

665-
public function testSeeResponseIsValidOnJsonSchemachesJsonSchemaString()
665+
public function testSeeResponseIsValidOnJsonSchemaMatchesJsonSchemaString()
666666
{
667667
$this->setStubResponse('{"name": "john", "age": 20}');
668668
$this->module->seeResponseIsValidOnJsonSchemaString('{"type": "object"}');
@@ -678,6 +678,14 @@ public function testSeeResponseIsValidOnJsonSchemachesJsonSchemaString()
678678
$this->module->seeResponseIsValidOnJsonSchemaString(json_encode($schema, JSON_THROW_ON_ERROR));
679679
}
680680

681+
public function testSeeResponseIsInvalidOnJsonSchemaMatchesJsonSchemaString()
682+
{
683+
$this->setStubResponse('{"name": null, "age": 20}');
684+
$this->expectExceptionMessage("[Property: 'name'] NULL value found, but a string is required");
685+
$this->shouldFail();
686+
$this->module->seeResponseIsValidOnJsonSchemaString('{"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "integer"}}}');
687+
}
688+
681689
/**
682690
* @dataProvider configAndRequestUrls
683691
*/

0 commit comments

Comments
 (0)