Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be52b39

Browse files
fancywebfabpot
authored andcommitted
[PropertyAccess] Handle interfaces in the invalid argument exception
1 parent 77289b9 commit be52b39

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static function handleError($type, $message, $file, $line, $context)
246246
private static function throwInvalidArgumentException($message, $trace, $i)
247247
{
248248
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file']) {
249-
$pos = strpos($message, $delim = 'must be of the type ') ?: strpos($message, $delim = 'must be an instance of ');
249+
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
250250
$pos += strlen($delim);
251251
$type = $trace[$i]['args'][0];
252252
$type = is_object($type) ? get_class($type) : gettype($type);

src/Symfony/Component/PropertyAccess/Tests/Fixtures/TypeHinted.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class TypeHinted
1818
{
1919
private $date;
2020

21+
/**
22+
* @var \Countable
23+
*/
24+
private $countable;
25+
2126
public function setDate(\DateTime $date)
2227
{
2328
$this->date = $date;
@@ -27,4 +32,20 @@ public function getDate()
2732
{
2833
return $this->date;
2934
}
35+
36+
/**
37+
* @return \Countable
38+
*/
39+
public function getCountable()
40+
{
41+
return $this->countable;
42+
}
43+
44+
/**
45+
* @param \Countable $countable
46+
*/
47+
public function setCountable(\Countable $countable)
48+
{
49+
$this->countable = $countable;
50+
}
3051
}

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,4 +554,15 @@ public function testArrayNotBeeingOverwritten()
554554
$this->assertSame('baz', $this->propertyAccessor->getValue($object, 'publicAccessor[value2]'));
555555
$this->assertSame(array('value1' => 'foo', 'value2' => 'baz'), $object->getPublicAccessor());
556556
}
557+
558+
/**
559+
* @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidArgumentException
560+
* @expectedExceptionMessage Expected argument of type "Countable", "string" given
561+
*/
562+
public function testThrowTypeErrorWithInterface()
563+
{
564+
$object = new TypeHinted();
565+
566+
$this->propertyAccessor->setValue($object, 'countable', 'This is a string, \Countable expected.');
567+
}
557568
}

0 commit comments

Comments
 (0)