This repository has been archived by the owner on Dec 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add more tests for the JsonGuard error conversion
- Loading branch information
Showing
31 changed files
with
597 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...onGuardValidationError/AnyOfConverter.php → ...lidationErrorConverter/AnyOfConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...il/JsonGuardValidationError/Converter.php → ...ardValidationErrorConverter/Converter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...uardValidationError/ConverterAbstract.php → ...ationErrorConverter/ConverterAbstract.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ardValidationError/ConverterInterface.php → ...tionErrorConverter/ConverterInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...sonGuardValidationError/EnumConverter.php → ...alidationErrorConverter/EnumConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...uardValidationError/MaxItemsConverter.php → ...ationErrorConverter/MaxItemsConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...uardValidationError/MinItemsConverter.php → ...ationErrorConverter/MinItemsConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ardValidationError/MinLengthConverter.php → ...tionErrorConverter/MinLengthConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...onGuardValidationError/OneOfConverter.php → ...lidationErrorConverter/OneOfConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...uardValidationError/RequiredConverter.php → ...ationErrorConverter/RequiredConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...sonGuardValidationError/TypeConverter.php → ...alidationErrorConverter/TypeConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...dValidationError/UniqueItemsConverter.php → ...onErrorConverter/UniqueItemsConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/units/Validator/Util/JsonGuardValidationErrorConverter/AnyOfConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace RREST\tests\units\Validator\Util\JsonGuardValidationErrorConverter; | ||
|
||
require_once __DIR__ . '/../../../boostrap.php'; | ||
|
||
use atoum; | ||
use League\JsonGuard\Validator; | ||
use RREST\Error; | ||
|
||
class AnyOfConverter extends atoum | ||
{ | ||
public function testGetErrors() | ||
{ | ||
$json = json_decode('{"x":5}'); | ||
$schema = json_decode('{ | ||
"$schema": "http://json-schema.org/schema", | ||
"type": "object", | ||
"properties": { | ||
"artist": { "type": "string" } | ||
}, | ||
"anyOf":[ | ||
{"required": ["artist"]}, | ||
{"required": ["toto"]} | ||
] | ||
}'); | ||
$validator = new Validator($json, $schema); | ||
$error = $validator->errors()[0]; | ||
|
||
$this | ||
->given($this->newTestedInstance($error)) | ||
->array($this->testedInstance->getErrors()) | ||
->hasSize(1) | ||
->values | ||
->object[0]->isInstanceOf('\RREST\Error') | ||
->string($this->testedInstance->getErrors()[0]->code)->isEqualTo(Error::DATA_VALIDATION_REQUIRED_ANYOF); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/units/Validator/Util/JsonGuardValidationErrorConverter/Converter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace RREST\tests\units\Validator\Util\JsonGuardValidationErrorConverter; | ||
|
||
require_once __DIR__ . '/../../../boostrap.php'; | ||
|
||
use atoum; | ||
use League\JsonGuard\Constraint\DraftFour\Required; | ||
|
||
class Converter extends atoum | ||
{ | ||
public function testGetErrors() | ||
{ | ||
$this | ||
->given($this->newTestedInstance( | ||
new \League\JsonGuard\ValidationError('a','b','c','d','e','f','g') | ||
)) | ||
->array($this->testedInstance->getErrors()) | ||
->hasSize(1) | ||
->values | ||
->object[0]->isInstanceOf('\RREST\Error'); | ||
|
||
$this | ||
->given($this->newTestedInstance( | ||
new \League\JsonGuard\ValidationError('a',Required::KEYWORD,'c',['d'],'e','f','g') | ||
)) | ||
->array($this->testedInstance->getErrors()) | ||
->hasSize(1) | ||
; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/units/Validator/Util/JsonGuardValidationErrorConverter/EnumConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace RREST\tests\units\Validator\Util\JsonGuardValidationErrorConverter; | ||
|
||
require_once __DIR__ . '/../../../boostrap.php'; | ||
|
||
use atoum; | ||
use League\JsonGuard\Validator; | ||
use RREST\Error; | ||
|
||
class EnumConverter extends atoum | ||
{ | ||
public function testGetErrors() | ||
{ | ||
$json = json_decode('{"artist":"c"}'); | ||
$schema = json_decode('{ | ||
"$schema": "http://json-schema.org/schema", | ||
"type": "object", | ||
"properties": { | ||
"artist": { "type": "string", "enum": ["a","b"] } | ||
}, | ||
"required": [ "artist" ] | ||
}'); | ||
$validator = new Validator($json, $schema); | ||
$error = $validator->errors()[0]; | ||
|
||
$this | ||
->given($this->newTestedInstance($error)) | ||
->array($this->testedInstance->getErrors()) | ||
->hasSize(1) | ||
->values | ||
->object[0]->isInstanceOf('\RREST\Error') | ||
->string($this->testedInstance->getErrors()[0]->code)->isEqualTo(Error::DATA_VALIDATION_ENUM); | ||
} | ||
} |
Oops, something went wrong.