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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/Common/Annotations/DocParser.php
Expand Up @@ -742,7 +742,7 @@ private function Annotation()

// verify that the class is really meant to be an annotation and not just any ordinary class
if (self::$annotationMetadata[$name]['is_annotation'] === false) {
if (isset($this->ignoredAnnotationNames[$originalName])) {
if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$originalName])) {
return false;
}

Expand Down
Expand Up @@ -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));
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);

} 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

}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/DocParserTest.php
Expand Up @@ -1049,6 +1049,15 @@ public function testNotAnAnnotationClassIsIgnoredWithoutWarning()
$this->assertEquals(0, count($result));
}

public function testNotAnAnnotationClassIsIgnoredWithoutWarningWithoutCheating()
{
$parser = new DocParser();
$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

}

/**
* @expectedException \Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage Expected PlainValue, got ''' at position 10.
Expand Down
Expand Up @@ -61,7 +61,17 @@ public function testClassWithInvalidAnnotationTargetAtMethodDocBlock()
}

/**
* @expectedException \Doctrine\Common\Annotations\AnnotationException
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testErrorWhenInvalidAnnotationIsUsed()
{
parent::testErrorWhenInvalidAnnotationIsUsed();
}

/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testInvalidAnnotationUsageButIgnoredClass()
{
Expand Down