8000 [PropertyInfo] Fix undefined variable fromConstructor when passing context to getTypes by mantis · Pull Request #30361 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getTypes($class, $property, array $context = [])
}

if (
$context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction &&
($context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure your tests only pass if you add these brackets? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the brackets:

  1. Symfony\Component\PropertyInfo\Tests\Extractor\ReflectionExtractorTest::testExtractTypeConstructor with data set #0 ('Symfony\Component\PropertyInf...1Dummy', 'string', array(Symfony\Component\PropertyInfo\Type Object (...)))
    Undefined variable: fromConstructor

if I knock up a quick script, returning true for $a, the bellows returns null / 1:

$a = $b = $c = 1;

if( $a ?? $b && $d = $c ) {
var_dump($d);
}
if( ($a ?? $b) && $d = $c ) {
var_dump($d);
}

returns null / 1

$fromConstructor = $this->extractFromConstructor($class, $property)
) {
return $fromConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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