Skip to content

Commit ca2b8f5

Browse files
committed
Add test to verify that coercion isn't applied via validateImmutable()
1 parent 8ce399b commit ca2b8f5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/Constraints/CoerciveTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,29 @@ public function testInvalidCoerceCasesUsingAssoc($input, $schema, $errors = arra
116116
$this->assertFalse($validator->isValid(), print_r($validator->getErrors(), true));
117117
}
118118

119+
/**
120+
* @dataProvider getValidCoerceTests
121+
*/
122+
public function testValidCoerceCasesViaImmutable($input, $schema, $errors = array())
123+
{
124+
$checkMode = Constraint::CHECK_MODE_TYPE_CAST | Constraint::CHECK_MODE_COERCE;
125+
126+
$validator = new Validator();
127+
$schema = json_decode($schema);
128+
$value = json_decode($input);
129+
130+
$this->assertTrue(gettype($value->number) == "string");
131+
$this->assertTrue(gettype($value->integer) == "string");
132+
$this->assertTrue(gettype($value->boolean) == "string");
133+
134+
$validator->validateImmutable($value, $schema, Constraint::CHECK_MODE_COERCE);
135+
136+
// using immutable, so these shouldn't change
137+
$this->assertTrue(gettype($value->number) == "string");
138+
$this->assertTrue(gettype($value->integer) == "string");
139+
$this->assertTrue(gettype($value->boolean) == "string");
140+
}
141+
119142
public function getValidCoerceTests()
120143
{
121144
return array(

0 commit comments

Comments
 (0)