Skip to content

Commit a399bbc

Browse files
committed
Better type validation for object assignments
1 parent 1253bf3 commit a399bbc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Tests/DefinitionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ public function testBadClassType() : void
6565
$fixture->class = new \DateTime();
6666
}
6767

68+
public function testClassAssignedInt() : void
69+
{
70+
$fixture = new \Tests\Fixtures\Type();
71+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
72+
$fixture->class = 1;
73+
}
74+
75+
public function testClassAssignedString() : void
76+
{
77+
$fixture = new \Tests\Fixtures\Type();
78+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
79+
$fixture->class = 'class';
80+
}
81+
6882
public function testBadEnum() : void
6983
{
7084
$fixture = new \Tests\Fixtures\Type();

src/ConstantContact/Definition/Base.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ public function __set(string $field, mixed $value)
172172
}
173173
}
174174
}
175-
elseif (! \is_object($value) && ! isset(self::$scalars[$expectedType]))
176-
{
177-
$value = new $expectedType($value);
178-
}
179175
elseif ($expectedType != $type)
180176
{
181177
throw new \PHPFUI\ConstantContact\Exception\InvalidType(static::class . "::{$actualField} is of type {$type} but should be type {$expectedType}");

0 commit comments

Comments
 (0)