1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace Papper\Tests\Internal; |
4
|
|
|
|
5
|
|
|
use Papper\Internal\AnnotationTypeReader; |
6
|
|
|
use Papper\Tests\Internal\AnnotationFixtures\AnotherNS\AliasedClass as AliasedPathClass; |
7
|
|
|
use Papper\Tests\Internal\AnnotationFixtures\AnotherNS\AnotherNsClass; |
8
|
|
|
use Papper\Tests\Internal\AnnotationFixtures\SameNS\AliasedClass; |
9
|
|
|
use Papper\Tests\Internal\AnnotationFixtures\SameNS\Composite; |
10
|
|
|
use Papper\Tests\Internal\AnnotationFixtures\SameNS\SameNsClass; |
11
|
|
|
|
12
|
|
|
include 'AnnotationFixtures/PapperGlobalAnnotationClass.php'; |
13
|
|
|
|
14
|
|
|
class AnnotationTypeReaderTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @dataProvider testGetTypeDataProvider |
18
|
|
|
* @param \Reflector $reflector |
19
|
|
|
* @param string $classname |
20
|
|
|
*/ |
21
|
|
|
public function testGetType($reflector, $classname) |
22
|
|
|
{ |
23
|
|
|
// arrange |
24
|
|
|
$annotationReader = new AnnotationTypeReader(); |
25
|
|
|
// act |
26
|
|
|
$type = $annotationReader->getType($reflector); |
27
|
|
|
// assert |
28
|
|
|
$this->assertEquals($classname, $type); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testGetTypeDataProvider() |
32
|
|
|
{ |
33
|
|
|
return array( |
34
|
|
|
'method, another ns' => array( |
35
|
|
|
new \ReflectionMethod(Composite::className(), 'getAnotherNsClass'), AnotherNsClass::className() |
36
|
|
|
), |
37
|
|
|
'property, same ns' => array( |
38
|
|
|
new \ReflectionProperty(Composite::className(), 'sameNsClass'), SameNsClass::className() |
39
|
|
|
), |
40
|
|
|
'property, aliased class' => array( |
41
|
|
|
new \ReflectionProperty(Composite::className(), 'aliasedClass'), AliasedClass::className() |
42
|
|
|
), |
43
|
|
|
'property, aliased path class' => array( |
44
|
|
|
new \ReflectionProperty(Composite::className(), 'aliasedPathClass'), AliasedPathClass::className() |
45
|
|
|
), |
46
|
|
|
'property, global class' => array( |
47
|
|
|
new \ReflectionProperty(Composite::className(), 'globalClass'), \PapperGlobalAnnotationClass::className() |
48
|
|
|
), |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.