Skip to content

Add test for property visibilty on final classes #202

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

Closed

Conversation

jaapio
Copy link
Contributor

@jaapio jaapio commented Feb 14, 2020

This is a test case to show the issue we are facing with phpDocumentor. Both cases are failing now, but I would expect them to pass.

<<<'PHP'
<?php
final class TheClass {
private $b;
Copy link
Member

Choose a reason for hiding this comment

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

In this case, I'd say that the property was indeed changed: this shouldn't produce a Changes::empty()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? it doesn't make sense to have a protected property in this case. nobody can access it only the current class, so this is not a bc break. since private and protected are equal in this case. Since there is no parent class.

Copy link
Member

Choose a reason for hiding this comment

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

PropertyChanged forwards checks to futher BCBreak checkers: it doesn't really raise a BC break itself.

In the config of this project, changes to final classes are scoped within the FinalClassChanged checks:

new ClassBased\SkipClassBasedErrors(new ClassBased\FinalClassChanged(

I think what's being hit is this other checker:

new ClassBased\SkipClassBasedErrors(new ClassBased\ExcludeAnonymousClasses(new ClassBased\ExcludeInternalClass(
new ClassBased\MultipleChecksOnAClass(
new ClassBased\SkipClassBasedErrors(new ClassBased\ClassBecameAbstract()),
new ClassBased\SkipClassBasedErrors(new ClassBased\ClassBecameInterface()),
new ClassBased\SkipClassBasedErrors(new ClassBased\ClassBecameTrait()),
new ClassBased\SkipClassBasedErrors(new ClassBased\ClassBecameFinal()),
new ClassBased\SkipClassBasedErrors(new ClassBased\ConstantRemoved()),
new ClassBased\SkipClassBasedErrors(new ClassBased\PropertyRemoved()),

As you can see, not scoped within final classes context: we probably want such a check to only apply to open classes, or to public properties of final classes, so the rule has to be nested a bit deeper.

abstract class baseClass {}

final class TheClass extends baseClass{
private $b;
Copy link
Member

Choose a reason for hiding this comment

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

Similar here, property $b was indeed changed, but not on baseClass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because $b is not used in baseClass it could not be detected as a change.

Copy link
Member

Choose a reason for hiding this comment

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

Similar to discussion at #202 (comment): I think the bug is not in the sources themselves, but rather in the configuration.

Also see Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\PropertyRemoved: that's the one raising this specific warning.

@Ocramius
Copy link
Member

@jaapio what's the original error message that started this investigation? Maybe we can go in more detail in there, or maybe it's more of a mis-configuration issue (for final classes)

@Ocramius Ocramius added the bug label Feb 14, 2020

self::assertSame($propertyName, $to->getName());

return Changes::fromList(Change::added($propertyName, true));
Copy link
Member

Choose a reason for hiding this comment

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

The property wasn't added, since it is present in both $from and $to

@jaapio
Copy link
Contributor Author

jaapio commented Feb 14, 2020

The build which was failing can be found here:

https://github.com/phpDocumentor/ReflectionDocBlock/runs/442034844?check_suite_focus=true

The invalid error is in my opinion here:

[BC] REMOVED: Property phpDocumentor\Reflection\DocBlock\Tags\PropertyRead#$variableName was removed

On line: https://github.com/phpDocumentor/ReflectionDocBlock/pull/207/files#diff-788f8ed7c572c70343f0e841def48b5cL37

Protected properties in a final class do not make sense. Like implemented in this issue: #31

It could be that the test cases are not completely valid, but they do illustrate the issue. Please let me know if it required another test. I can imagine that you are filtering the results when the error class is final?

@Ocramius
Copy link
Member

It could be that the test cases are not completely valid, but they do illustrate the issue. Please let me know if it required another test. I can imagine that you are filtering the results when the error class is final?

I think our best bet for now is to change the tests you wrote to target Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\PropertyRemoved, which is more specific to the error you are getting right now.

@Ocramius
Copy link
Member

@jaapio I re-visited this while looking at the backlog, and isolated it to #253.

Sorry it took so long: 'been doing very little OSS due to work commitments.

@Ocramius Ocramius added this to the 5.0.0 milestone Jun 22, 2020
@Ocramius Ocramius self-assigned this Jun 22, 2020
Ocramius added a commit that referenced this pull request Jun 22, 2020
Ocramius added a commit that referenced this pull request Jun 22, 2020
…ies-of-final-classes-are-not-bc-breaks

Fix #202 - `PropertyRemoved` should only operate on `public` properties for `final` classes
@jaapio jaapio deleted the test/final-class-property-visiblity branch June 22, 2020 11:40
@jaapio
Copy link
Contributor Author

jaapio commented Jun 22, 2020

Thanks for addressing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants