Skip to content
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

setIgnoreNotImportedAnnotations(true) doesn't work on already autoloaded classes #110

Merged
merged 2 commits into from Dec 30, 2016

Conversation

bfanger
Copy link
Contributor

@bfanger bfanger commented Dec 28, 2016

Because FuelPHP has a Package class, which isn’t an @annotation the following error occurs:

[Semantical Error] The class "package" is not annotated with @annotation. Are you sure this class can be used as annotation? If so, then you need to add @annotation to the class doc comment of "package". If it is indeed no annotation, then you need to add @IgnoreAnnotation("package") to the class doc comment of ...


Duplicate of #25, requested by @Ocramius

Because FuelPHP has a Package class, which isn’t an @annotation the following error occurs:

> [Semantical Error] The class "package" is not annotated with @annotation. Are you sure this class can be used as annotation? If so, then you need to add @annotation to the _class_ doc comment of "package". If it is indeed no annotation, then you need to add @IgnoreAnnotation("package") to the _class_ doc comment of ...

Using @IgnoreAnnotation("package") won’t help because this issue also affects the AnnotationReader->preParser, so this error also occurs when trying to extract the @IgnoreAnnotations
@mikeSimonson
Copy link
Contributor

@bfanger Thanks for the PR.

Someone still needs to verify that the logic of this change is sound.

@@ -387,8 +387,11 @@ public function testInvalidAnnotationUsageButIgnoredClass()
$reader = $this->getReader();
$ref = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\InvalidAnnotationUsageButIgnoredClass');
$annots = $reader->getClassAnnotations($ref);

$this->assertEquals(2, count($annots));
if ($annots[0] instanceof IgnoreAnnotation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you split that test is 2 distinct ones.
The "if" here indicate that you are testing 2 different behaviours in the same test.

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 have removed if statement from the unittest and moved testing the behaviour of SimpleAnnotationReader into the SimpleAnnotationReaderTest


$this->assertEquals(2, count($annots));
if ($annots[0] instanceof IgnoreAnnotation) {
$this->assertEquals(2, count($annots));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use assertCount everywhere you count in the assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

grep -r "assertCount" tests/|wc -l = 13
grep -r "assertEquals" tests/|grep "count("|wc -l = 51
This codebase clearly prefers assertEquals over assertCount.

Copy link
Contributor

Choose a reason for hiding this comment

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

You realise that this justification is weak right ?
With that kind of logic why not using assertTrue everywhere ?
Why do you think that we need to conform to use only one assertion in the hundred that exists ?

The reason to use assertCount here is because it will make the error message when the test fails an order of magnitude easier to understand and that why we test.

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'm in favour of assertCount(), but when creating pull requests it's considered good behaviour to conform to the style of the project.

Please create a pull request changing all the assertEquals into the better assertCount and when that gets merged first i'll gladly change the assertions.

PS. In my personal project I use assertSame and don't use assertEquals at all, as it doesn't catch subtle bugs like $this->assertEquals("1", true);

if ($annots[0] instanceof IgnoreAnnotation) {
$this->assertEquals(2, count($annots));
} else { // SimpleAnnotationReader doens't include the IgnoreAnnotation in the results.
$this->assertEquals(1, count($annots));
Copy link
Contributor

Choose a reason for hiding this comment

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

assertCount

$parser->setIgnoreNotImportedAnnotations(true);
$result = $parser->parse('@PHPUnit_Framework_TestCase');

$this->assertEquals(0, count($result));
Copy link
Contributor

Choose a reason for hiding this comment

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

assertCount

…mpleAnnotationReader into the SimpleAnnotationReaderTest
Ocramius added a commit that referenced this pull request Dec 30, 2016
Ocramius added a commit that referenced this pull request Dec 30, 2016
…dy-autoloaded-classes-1.3.x' into 1.3.x

Close #110
Backport #110
@Ocramius Ocramius merged commit afbc9f1 into doctrine:master Dec 30, 2016
Ocramius added a commit that referenced this pull request Dec 30, 2016
Ocramius added a commit that referenced this pull request Dec 30, 2016
@Ocramius
Copy link
Member

Merged and moved to count-oriented assertions. Will apply further fixes to assertions on master

@Ocramius Ocramius added the bug label Dec 30, 2016
@Ocramius Ocramius added this to the v1.3.1 milestone Dec 30, 2016
@Ocramius Ocramius self-assigned this Dec 30, 2016
@Ocramius Ocramius changed the title setIgnoreNotImportedAnnotations(true) didn’t work for existing classes. setIgnoreNotImportedAnnotations(true) doesn't work on already autoloaded classes Dec 30, 2016
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.

None yet

3 participants