8000 fix Autowiring tests of #18144 by HeahDude · Pull Request #18436 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

fix Autowiring tests of #18144 #18436

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
Apr 14, 2016
Merged

Conversation

HeahDude
Copy link
Contributor
@HeahDude HeahDude commented Apr 4, 2016
Q A
Branch? master
Bug fix? yes
Tests pass? yes
Fixed issue #18422 (comment)
License MIT

@HeahDude
Copy link
Contributor Author
HeahDude commented Apr 4, 2016

Wow! It's all green again! ping @nicolas-grekas :)


$newSelf = AutowirePass::createResourceForClass($reflectionClass);

return $this == $newSelf;
Copy link
Member

Choose a reason for hiding this comment

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

one-liner + strict comparison

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about inlining but this was the original style (ref 49271e8#diff-04e2904117929f6ffe784d5be3cb1103L49).

So I'm fine either way. Final call ?

Doesn't a strict comparison always return true ? We need to compare their data, right ?

Copy link
Member

Choose a reason for hiding this comment

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

10000

In fact triple equals wouldn't fit as objects have different identities. Yet this is strange: @weaverryan shouldn't we touch($this->filePath) here when the objects are equals?
Would it be better to compare properties using strict comparisons? This could be done with:
((array) $this === (array) AutowirePass::createResourceForClass($reflectionClass)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's always false, hence the tests would pass anyway. I don't think we need touch since my guess is that it handles the case where the original class file does not exist anymore but the same class can be autoloaded from elsewhere (? weird or not I don't know :).

In any case we should at least add comments here about what's happening and at best add a test to cover regressions like the two previous PR's.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I got you

Copy link
Member

Choose a reason for hiding this comment

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

@nicolas-grekas I'm sorry, what would be the point of the touch() - I'm not sure I understand?

And yes, would could definitely cast into arrays to compare the properties only - that's definitely "in the spirit" of what we want to compare. Really, we could just compare the autowiringMetadata paths (as we've already checked things on filePath). But I didn't want to make this public just for this.

So:

  • +1 for casting both objects into arrays
  • I don't understand the touch($this->filepath) - would that just be to update the file so that it looks fresh automatically next time and avoids extra checking? If so, we could do that for sure - but probably the rest of the logic is very fast anyways
  • I don't understand the comment You're right, it's always false, hence the tests would pass anyway.

Sorry for being slow on this :) - thanks to both of you for the help!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now fixed.

@weaverryan originally the PR was about fixing a test where this function should return false.
In PHP, when comparing object using strict === it returns true if this is the same instance of the class, in that case it would always be false, so the test would always pass.
We could use == to compare the objects since it returns true for different instances with identical properties, this is the same as casting them to arrays being strict, without checking the class.

@nicolas-grekas
Copy link
Member

Status: needs work

@HeahDude HeahDude force-pushed the fix/test-autowiring branch from 1e94811 to 0cbf04a Compare April 13, 2016 06:43
@HeahDude
Copy link
Contributor Author

Status: Needs Review

@xabbuh
Copy link
Member
xabbuh commented Apr 13, 2016

👍

Status: Reviewed

@fabpot
Copy link
Member
fabpot commented Apr 14, 2016

Thank you @HeahDude.

@fabpot fabpot merged commit 0cbf04a into symfony:master Apr 14, 2016
fabpot added a commit that referenced this pull request Apr 14, 2016
This PR was merged into the 3.1-dev branch.

Discussion
----------

fix Autowiring tests of #18144

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| Tests pass?   | yes
| Fixed issue | #18422 (comment)
| License       | MIT

Commits
-------

0cbf04a [DI] fix Autowiring tests of #18144
@HeahDude HeahDude deleted the fix/test-autowiring branch April 28, 2016 17:18
@fabpot fabpot mentioned this pull request May 13, 2016
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.

7 participants
0