Skip to content
Permalink
Browse files

bug #30361 [PropertyInfo] Fix undefined variable fromConstructor when…

… passing context to getTypes (mantis, OskarStark)

This PR was merged into the 4.2 branch.

Discussion
----------

[PropertyInfo] Fix undefined variable fromConstructor when passing context to getTypes

| Q             | A
| ------------- | ---
| Branch?       | 4.1, 4.2, master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony-docs#10969
| License       | MIT
| Doc PR        |

If passing context to getTypes, it checks value of $context['enable_constructor_extraction'] for true/false or the constructor value of enableConstructorExtraction and should then populate fromConstructor if necessary. The missing brackets around the first part of this check mean that fromConstructor is only applied if context is not set.

This fixes the issue described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969)

Commits
-------

8e401af Allow 3rd argument to be null
04dc692 Remove whitespace (tab on blank line)
a0aa15a Update src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php
c2986d5 Update src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php
42995c8 Update src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php
2d88298 Update src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php
e43a3bc Update ReflectionExtractorTest.php
2c91c75 Update ReflectionExtractorTest.php
5acc85c Update ReflectionExtractorTest.php
d0a2dc0 Update ReflectionExtractorTest.php
be8d14a Fix undefined variable fromConstructor when passing context to getTypes
  • Loading branch information...
fabpot committed Mar 5, 2019
2 parents 203cfc4 + 8e401af commit af52f6e7d895687032c79f8f65fb1667a5aa9f6c
@@ -112,7 +112,7 @@ public function getTypes($class, $property, array $context = [])
}
if (
$context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction &&
($context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction) &&
$fromConstructor = $this->extractFromConstructor($class, $property)
) {
return $fromConstructor;
@@ -293,4 +293,29 @@ public function getInitializableProperties(): array
[NotInstantiable::class, 'foo', false],
];
}
/**
* @dataProvider constructorTypesProvider
*/
public function testExtractTypeConstructor(string $class, string $property, array $type = null)
{
/* Check that constructor extractions works by default, and if passed in via context.
Check that null is returned if constructor extraction is disabled */
$this->assertEquals($type, $this->extractor->getTypes($class, $property, []));
$this->assertEquals($type, $this->extractor->getTypes($class, $property, ['enable_constructor_extraction' => true]));
$this->assertNull($this->extractor->getTypes($class, $property, ['enable_constructor_extraction' => false]));
}
public function constructorTypesProvider(): array
{
return [
// php71 dummy has following constructor: __construct(string $string, int $intPrivate)
[Php71Dummy::class, 'string', [new Type(Type::BUILTIN_TYPE_STRING, false)]],
[Php71Dummy::class, 'intPrivate', [new Type(Type::BUILTIN_TYPE_INT, false)]],
// Php71DummyExtended2 adds int $intWithAccessor
[Php71DummyExtended2::class, 'intWithAccessor', [new Type(Type::BUILTIN_TYPE_INT, false)]],
[Php71DummyExtended2::class, 'intPrivate', [new Type(Type::BUILTIN_TYPE_INT, false)]],
[DefaultValue::class, 'foo', null],
];
}
}

0 comments on commit af52f6e

Please sign in to comment.
You can’t perform that action at this time.