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

Conversation

mantis
Copy link
Contributor

@mantis mantis commented Feb 23, 2019

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

@nicolas-grekas nicolas-grekas added this to the 4.2 milestone Feb 23, 2019
@nicolas-grekas nicolas-grekas changed the title Fix undefined variable fromConstructor when passing context to getTypes [PropertyInfo] Fix undefined variable fromConstructor when passing context to getTypes Feb 23, 2019
@nicolas-grekas
Copy link
Member

Hi, thanks. Could you add a test case please?

@mantis
Copy link
Contributor Author

mantis commented Feb 23, 2019

@nicolas-grekas you asked the one question that I hoped you wouldn't ask - anyway, I've added my first attempt at using phpunit ;)

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

except this small change, I think you made it with the unit test @mantis 👍 congrats

@@ -111,7 +111,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

@mantis
Copy link
Contributor Author

mantis commented Feb 23, 2019

Thanks ;) I made the mistake of just doing this change through github's editor - hence the multiple formatting commits. But equally 'easier' if you don't have everything checked out.

In terms of the failing travis/appveyor builds, i'd used changes to the test fixtures that went in with 4.2 - and applied the fix to 4.1 branch. I'll leave you guys to decide what if anything you want to do there ;)

@OskarStark
Copy link
Contributor

OskarStark commented Feb 23, 2019

4.1 only receive security fixes, and this is not a security fix, so 4.2? should be right, as its a bug fix. My question was, if you are sure that this "bug" is not present in 3.4, in this case you must target 3.4`

master is only for new features

You can check the maintained versions on the roadmap

@mantis
Copy link
Contributor Author

mantis commented Feb 23, 2019

The issue was introduced in December 2017 by symfony/property-info@e168420#diff-818203fea9c55d86a0556b0d436126df

That's been tagged as 4.1.0beta1 -> 4.2.3

@OskarStark
Copy link
Contributor

Yes then 4.2 is the correct base branch

@mantis mantis changed the base branch from 4.1 to 4.2 February 23, 2019 19:16
@mantis mantis changed the base branch from 4.2 to 4.1 February 23, 2019 19:17
@fabpot
Copy link
Member

fabpot commented Mar 4, 2019

@mantis Can you fix the tests and change the target to 4.2?

@mantis
Copy link
Contributor Author

mantis commented Mar 4, 2019

@fabpot - when i tried to change the target to 4.2, it started to want to pull in changes to the changelog,, and I got confused... IIRC, I think the test failures were only due to the target not being 4.2

@OskarStark
Copy link
Contributor

First you should rebase your feature branch against 4.2 and push --force, afterwards change the target base branch to 4.2 in the github UI

This should work

@fabpot
Copy link
Member

fabpot commented Mar 4, 2019

@mantis I can do it for you if you want.

@mantis mantis changed the base branch from 4.1 to 4.2 March 4, 2019 22:00
@mantis
Copy link
Contributor Author

mantis commented Mar 4, 2019

@OskarStark @fabpot - I forced it - the tests were failing from adding in one of oskar's review comments. Current patch set passes as above, so I guess over to you guys ;)

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 issuse described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969)
@fabpot
Copy link
Member

fabpot commented Mar 5, 2019

Thank you @mantis.

@fabpot fabpot merged commit 7e4abee into symfony:4.2 Mar 5, 2019
fabpot added a commit that referenced this pull request Mar 5, 2019
… 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
fabpot added a commit that referenced this pull request Mar 5, 2019
… passing context to getTypes (mantis)

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
-------

7e4abee Fix undefined variable fromConstructor when passing context to getTypes
@fabpot fabpot mentioned this pull request Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants