/
ReflectionFileTest.php
103 lines (83 loc) · 2.75 KB
/
ReflectionFileTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* PHP Token Reflection
*
* Version 1.3.0
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this library in the file LICENSE.
*
* @author Ondřej Nešpor
* @author Jaroslav Hanslík
*/
namespace TokenReflection;
use ReflectionClass as InternalReflectionClass;
require_once __DIR__ . '/../bootstrap.php';
/**
* Class test.
*/
class ReflectionFileTest extends Test
{
/**
* Element type.
*
* @var string
*/
protected $type = 'file';
/**
* Tests file level docblocks.
*/
public function testDocComment()
{
$fileName = $this->getFilePath('docComment');
$this->getBroker()->processFile($fileName);
$this->assertTrue($this->getBroker()->hasFile($fileName));
$fileReflection = $this->getBroker()->getFile($fileName);
$this->assertInstanceOf('\TokenReflection\ReflectionFile', $fileReflection);
$this->assertSame($this->getFilePath('docComment'), $fileReflection->getPrettyName());
$this->assertTrue($fileReflection->hasAnnotation('package'));
$this->assertTrue($fileReflection->hasAnnotation('author'));
$this->assertFalse($fileReflection->hasAnnotation('licence'));
$this->assertSame(array('package name'), $fileReflection->getAnnotation('package'));
$this->assertSame(array('author name'), $fileReflection->getAnnotation('author'));
}
/**
* Tests file level docblocks.
*/
public function testNoDocComment()
{
$fileName = $this->getFilePath('noDocComment');
$this->getBroker()->processFile($fileName);
$this->assertTrue($this->getBroker()->hasFile($fileName));
$fileReflection = $this->getBroker()->getFile($fileName);
$this->assertInstanceOf('\TokenReflection\ReflectionFile', $fileReflection);
$this->assertSame($this->getFilePath('noDocComment'), $fileReflection->getPrettyName());
$this->assertFalse($fileReflection->hasAnnotation('package'));
$this->assertFalse($fileReflection->hasAnnotation('author'));
$this->assertFalse($fileReflection->getDocComment());
}
/**
* Tests returning file reflections.
*/
public function testReturningFileReflection()
{
$fileName = $this->getFilePath('docComment');
$rfl = $this->getClassReflection('docComment');
$this->assertTrue($this->getBroker()->hasFile($fileName));
$this->assertSame($rfl->token->getFileName(), $rfl->token->getFileReflection()->getName());
$this->assertSame($this->getBroker()->getFile($fileName), $rfl->token->getFileReflection());
}
/**
* Tests throwing exceptions when requesting reflections of files that were not processed.
*
* @expectedException \TokenReflection\Exception\BrokerException
*/
public function testExceptionReturningFileReflection()
{
$broker = $this->getBroker();
$this->assertFalse($broker->hasFile('#non~Existent#'));
$broker->getFile('#non~Existent#');
}
}