[PropertyAccess] Fix TypeError discard
This commit is contained in:
parent
7acc34537b
commit
e0c5040398
@ -245,7 +245,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
|
||||
private static function throwInvalidArgumentException($message, $trace, $i)
|
||||
{
|
||||
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file']) {
|
||||
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file'] && isset($trace[$i]['args'][0])) {
|
||||
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
|
||||
$pos += strlen($delim);
|
||||
$type = $trace[$i]['args'][0];
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class ReturnTyped
|
||||
{
|
||||
public function getFoos(): array
|
||||
{
|
||||
return 'It doesn\'t respect the return type on purpose';
|
||||
}
|
||||
|
||||
public function addFoo(\DateTime $dateTime)
|
||||
{
|
||||
}
|
||||
|
||||
public function removeFoo(\DateTime $dateTime)
|
||||
{
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ namespace Symfony\Component\PropertyAccess\Tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\ReturnTyped;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClass;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicCall;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicGet;
|
||||
@ -566,4 +567,16 @@ class PropertyAccessorTest extends TestCase
|
||||
|
||||
$this->propertyAccessor->setValue($object, 'countable', 'This is a string, \Countable expected.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7
|
||||
*
|
||||
* @expectedException \TypeError
|
||||
*/
|
||||
public function testDoNotDiscardReturnTypeError()
|
||||
{
|
||||
$object = new ReturnTyped();
|
||||
|
||||
$this->propertyAccessor->setValue($object, 'foos', array(new \DateTime()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user