Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 4.3:
  [Validator] fix access to uninitialized property when getting value
  [HttpClient] Fix regex bearer
  [HttpKernel] Fix stale-if-error behavior, add tests
  Improved error message when no supported user provider is found
  Properly handle phpunit arguments for configuration file
  • Loading branch information
nicolas-grekas committed Jan 31, 2020
2 parents 2f3ec17 + 0d2dcf4 commit eb3e15d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Mapping/PropertyMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public function __construct(string $class, string $name)
*/
public function getPropertyValue($object)
{
return $this->getReflectionMember($object)->getValue($object);
$reflProperty = $this->getReflectionMember($object);

if (\PHP_VERSION_ID >= 70400 && !$reflProperty->isInitialized($object)) {
return null;
}

return $reflProperty->getValue($object);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions Tests/Fixtures/Entity_74.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Symfony\Component\Validator\Tests\Fixtures;

class Entity_74
{
public int $uninitialized;
}
13 changes: 13 additions & 0 deletions Tests/Mapping/PropertyMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Mapping\PropertyMetadata;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Tests\Fixtures\Entity_74;

class PropertyMetadataTest extends TestCase
{
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
const CLASSNAME_74 = 'Symfony\Component\Validator\Tests\Fixtures\Entity_74';
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';

public function testInvalidPropertyName()
Expand Down Expand Up @@ -53,4 +55,15 @@ public function testGetPropertyValueFromRemovedProperty()
$this->expectException('Symfony\Component\Validator\Exception\ValidatorException');
$metadata->getPropertyValue($entity);
}

/**
* @requires PHP 7.4
*/
public function testGetPropertyValueFromUninitializedProperty()
{
$entity = new Entity_74();
$metadata = new PropertyMetadata(self::CLASSNAME_74, 'uninitialized');

$this->assertNull($metadata->getPropertyValue($entity));
}
}

0 comments on commit eb3e15d

Please sign in to comment.