Skip to content

Commit

Permalink
[PropertyInfo] Fix phpstan extractor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky authored and nicolas-grekas committed Dec 25, 2021
1 parent 66942cf commit 0832c84
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Tests/Normalizer/ObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
namespace Symfony\Component\Serializer\Tests\Normalizer;

use Doctrine\Common\Annotations\AnnotationReader;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPUnit\Framework\TestCase;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\Serializer\Exception\LogicException;
Expand Down Expand Up @@ -721,6 +723,22 @@ public function testAcceptJsonNumber()
$this->assertSame(10.0, $serializer->denormalize(['number' => 10], JsonNumber::class, 'jsonld')->number);
}

public function testDoesntHaveIssuesWithUnionConstTypes()
{
if (!class_exists(PhpStanExtractor::class) || !class_exists(PhpDocParser::class)) {
$this->markTestSkipped('phpstan/phpdoc-parser required for this test');
}

$extractor = new PropertyInfoExtractor([], [new PhpStanExtractor(), new PhpDocExtractor(), new ReflectionExtractor()]);
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
$serializer = new Serializer([new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer]);

$this->assertSame('bar', $serializer->denormalize(['foo' => 'bar'], \get_class(new class() {
/** @var self::*|null */
public $foo;
}))->foo);
}

public function testExtractAttributesRespectsFormat()
{
$normalizer = new FormatAndContextAwareNormalizer();
Expand Down

0 comments on commit 0832c84

Please sign in to comment.