Skip to content

Commit 928cc69

Browse files
author
Alexander Obuhovich
committed
Adding test, that would fail when orphaned annotations are not skipped
1 parent d7392a0 commit 928cc69

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

test/suite/Annotations.test.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use mindplay\annotations\AnnotationManager;
88
use mindplay\annotations\Annotations;
99
use mindplay\annotations\Annotation;
10+
use mindplay\annotations\standard\ReturnAnnotation;
1011
use mindplay\test\annotations\Package;
1112
use mindplay\test\lib\xTest;
1213
use mindplay\test\lib\xTestRunner;
@@ -811,6 +812,22 @@ public function testMalformedParamAnnotationThrowsException()
811812
Annotations::ofMethod('BrokenParamAnnotationClass', 'brokenParamAnnotation');
812813
}
813814

815+
protected function testOrphanedAnnotationsAreIgnored()
816+
{
817+
$manager = new AnnotationManager();
818+
$manager->namespace = 'mindplay\test\Sample';
819+
$manager->cache = false;
820+
821+
/** @var Annotation[] $annotations */
822+
$annotations = $manager->getMethodAnnotations('mindplay\test\Sample\OrphanedAnnotations', 'someMethod');
823+
824+
$this->check(count($annotations) == 1, 'the @return annotation was found');
825+
$this->check(
826+
$annotations[0] instanceof ReturnAnnotation,
827+
'the @return annotation has correct type'
828+
);
829+
}
830+
814831
}
815832

816833
return new AnnotationsTest;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace mindplay\test\Sample;
4+
5+
class OrphanedAnnotations
6+
{
7+
8+
/**
9+
* Some method.
10+
*
11+
* @return void
12+
*/
13+
public function someMethod()
14+
{
15+
$a = 5;
16+
17+
// @codeCoverageIgnoreStart
18+
if (false) {
19+
$a = 6;
20+
}
21+
// @codeCoverageIgnoreEnd
22+
23+
$a = 5;
24+
}
25+
26+
}

0 commit comments

Comments
 (0)