1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class CodeReviewAutoloaderTest extends PHPUnit_Framework_TestCase { |
|
|
|
|
4
|
|
|
|
5
|
|
|
public function testRegister() { |
6
|
|
|
$autoloader = new CodeReviewAutoloader(); |
7
|
|
|
|
8
|
|
|
$this->assertFalse($autoloader->unregister()); |
9
|
|
|
//double register |
10
|
|
|
$this->assertTrue($autoloader->register()); |
11
|
|
|
$this->assertTrue($autoloader->register()); |
12
|
|
|
//unregister just once |
13
|
|
|
$this->assertTrue($autoloader->unregister()); |
14
|
|
|
$this->assertFalse($autoloader->unregister()); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testClassExists() { |
18
|
|
|
$classes = array( |
19
|
|
|
'code_review', |
20
|
|
|
'CodeFixer', |
21
|
|
|
'CodeReviewAnalyzer', |
22
|
|
|
'CodeReviewFileFilterIterator', |
23
|
|
|
'PhpFileParser', |
24
|
|
|
'PhpTokensFilterIterator', |
25
|
|
|
'CodeReview_Foo_TestClass', |
26
|
|
|
); |
27
|
|
|
foreach ($classes as $class) { |
28
|
|
|
$this->assertTrue(class_exists($class)); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testClassDoesNotExists() { |
33
|
|
|
$classes = array( |
34
|
|
|
'code_review_non_existing', |
35
|
|
|
'CodeReview_FooTestClass', |
36
|
|
|
'CodeReviewFoo_TestClass', |
37
|
|
|
'CodeReviewFooTestClass', |
38
|
|
|
'CodeReview/Foo/TestClass', |
39
|
|
|
'CodeReview_Foo/TestClass', |
40
|
|
|
'CodeReview/Foo_TestClass', |
41
|
|
|
); |
42
|
|
|
foreach ($classes as $class) { |
43
|
|
|
$this->assertFalse(class_exists($class)); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.