diff --git a/src/PHPUnit/CheckAnnotations.php b/src/PHPUnit/CheckAnnotations.php index c7aa231..ac2252f 100644 --- a/src/PHPUnit/CheckAnnotations.php +++ b/src/PHPUnit/CheckAnnotations.php @@ -105,7 +105,7 @@ private function checkFile(\SplFileInfo $fileInfo, string $annotation): void $matches = []; preg_match_all( <</\*(?:[^*]|\n|(?:\*(?:[^/]|\n)))*\*/)\s+?public\s+?function\s+?(?.+?)\(% +%(?/\*(?:[^*]|\n|(?:\*(?:[^/]|\n)))*\*/|\n)\s+?public\s+?function\s+?(?.+?)\(% REGEXP .'si', $contents, @@ -116,12 +116,18 @@ private function checkFile(\SplFileInfo $fileInfo, string $annotation): void return; } - foreach ($matches['docblock'] as $key => $docblock) { - if (false !== strpos($docblock, '@'.$annotation)) { + foreach ($matches['method'] as $key => $method) { + $docblock = $matches['docblock'][$key]; + /* Found the annotation - continue */ + if (false !== \strpos($docblock, '@'.$annotation)) { + continue; + } + /* No @test annotation found & method not beginning test = not a test, so continue */ + if (false === \strpos($docblock, '@test') && false === \strpos($method, 'test')) { continue; } $this->errors[$fileInfo->getFilename()][] = - 'Failed finding @'.$annotation.' for method: '.$matches['method'][$key]; + 'Failed finding @'.$annotation.' for method: '.$method; } } diff --git a/tests/Small/PHPUnit/CheckAnnotationsTest.php b/tests/Small/PHPUnit/CheckAnnotationsTest.php index d65f9f6..8a21373 100644 --- a/tests/Small/PHPUnit/CheckAnnotationsTest.php +++ b/tests/Small/PHPUnit/CheckAnnotationsTest.php @@ -93,6 +93,7 @@ public function itFindsMissingLargeAnnotations(): void $expected = [ 'SomethingTest.php' => [ 'Failed finding @large for method: itDoesSomething', + 'Failed finding @large for method: testSomethingHappens', ], ]; $actual = $this->checker->main($pathToTestsDirectory); diff --git a/tests/assets/phpunitAnnotations/projectAllGood/tests/Large/SomethingTest.php b/tests/assets/phpunitAnnotations/projectAllGood/tests/Large/SomethingTest.php index 4e8780c..addff99 100644 --- a/tests/assets/phpunitAnnotations/projectAllGood/tests/Large/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectAllGood/tests/Large/SomethingTest.php @@ -10,8 +10,18 @@ class SomethingTest extends TestCase * @throws \Exception * @covers ::somethingThings() * @large + * @test */ public function itDoesSomething() { } + + /** + * @throws \Exception + * @covers ::somethingThings() + * @large + */ + public function testItDoesSomething() + { + } } diff --git a/tests/assets/phpunitAnnotations/projectAllGood/tests/Medium/SomethingTest.php b/tests/assets/phpunitAnnotations/projectAllGood/tests/Medium/SomethingTest.php index 3d65fc8..eb76e57 100644 --- a/tests/assets/phpunitAnnotations/projectAllGood/tests/Medium/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectAllGood/tests/Medium/SomethingTest.php @@ -8,6 +8,7 @@ class SomethingTest extends TestCase { /** * @medium + * @test */ public function itDoesSomething() { diff --git a/tests/assets/phpunitAnnotations/projectAllGood/tests/Small/SomethingTest.php b/tests/assets/phpunitAnnotations/projectAllGood/tests/Small/SomethingTest.php index ad36ac7..423b4e2 100644 --- a/tests/assets/phpunitAnnotations/projectAllGood/tests/Small/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectAllGood/tests/Small/SomethingTest.php @@ -8,8 +8,17 @@ class SomethingTest extends TestCase { /** * @small + * @test */ public function itDoesSomething() { } + + /** + * This method does not have the size annotation but it is not a test, so this should not cause any problem + */ + public function methodThatIsNotATest() + { + + } } diff --git a/tests/assets/phpunitAnnotations/projectMissingLarge/tests/Large/SomethingTest.php b/tests/assets/phpunitAnnotations/projectMissingLarge/tests/Large/SomethingTest.php index 85ecde9..debe557 100644 --- a/tests/assets/phpunitAnnotations/projectMissingLarge/tests/Large/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectMissingLarge/tests/Large/SomethingTest.php @@ -8,8 +8,14 @@ class SomethingTest extends TestCase { /** * @largo + * @test */ public function itDoesSomething() { } + + public function testSomethingHappens() + { + + } } diff --git a/tests/assets/phpunitAnnotations/projectMissingLarge/tests/Medium/SomethingTest.php b/tests/assets/phpunitAnnotations/projectMissingLarge/tests/Medium/SomethingTest.php index 6f23332..5689dc6 100644 --- a/tests/assets/phpunitAnnotations/projectMissingLarge/tests/Medium/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectMissingLarge/tests/Medium/SomethingTest.php @@ -8,6 +8,7 @@ class SomethingTest extends TestCase { /** * @medium + * @test */ public function itDoesSomething() { diff --git a/tests/assets/phpunitAnnotations/projectMissingMedium/tests/Medium/SomethingTest.php b/tests/assets/phpunitAnnotations/projectMissingMedium/tests/Medium/SomethingTest.php index c883b83..b61eaa6 100644 --- a/tests/assets/phpunitAnnotations/projectMissingMedium/tests/Medium/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectMissingMedium/tests/Medium/SomethingTest.php @@ -8,6 +8,7 @@ class SomethingTest extends TestCase { /** * @modium + * @test */ public function itDoesSomething() { diff --git a/tests/assets/phpunitAnnotations/projectMissingMedium/tests/Small/SomethingTest.php b/tests/assets/phpunitAnnotations/projectMissingMedium/tests/Small/SomethingTest.php index 41ca96b..2adff50 100644 --- a/tests/assets/phpunitAnnotations/projectMissingMedium/tests/Small/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectMissingMedium/tests/Small/SomethingTest.php @@ -8,6 +8,7 @@ class SomethingTest extends TestCase { /** * @small + * @test */ public function itDoesSomething() { diff --git a/tests/assets/phpunitAnnotations/projectMissingSmall/tests/Medium/SomethingTest.php b/tests/assets/phpunitAnnotations/projectMissingSmall/tests/Medium/SomethingTest.php index 6f23332..5689dc6 100644 --- a/tests/assets/phpunitAnnotations/projectMissingSmall/tests/Medium/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectMissingSmall/tests/Medium/SomethingTest.php @@ -8,6 +8,7 @@ class SomethingTest extends TestCase { /** * @medium + * @test */ public function itDoesSomething() { diff --git a/tests/assets/phpunitAnnotations/projectMissingSmall/tests/Small/SomethingTest.php b/tests/assets/phpunitAnnotations/projectMissingSmall/tests/Small/SomethingTest.php index 06931f0..ac8b464 100644 --- a/tests/assets/phpunitAnnotations/projectMissingSmall/tests/Small/SomethingTest.php +++ b/tests/assets/phpunitAnnotations/projectMissingSmall/tests/Small/SomethingTest.php @@ -8,6 +8,7 @@ class SomethingTest extends TestCase { /** * @smaalll + * @test */ public function itDoesSomething() {