|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class Dumper |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/mtymek/class-dumper |
|
6
|
|
|
* @copyright Copyright (c) 2015 Mateusz Tymek |
|
7
|
|
|
* @license BSD 2-Clause |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace ClassDumperTest; |
|
11
|
|
|
|
|
12
|
|
|
use ClassDumper\CodeGenerator; |
|
13
|
|
|
use PHPUnit_Framework_TestCase; |
|
14
|
|
|
use UserLib\Admin\SuperAdmin; |
|
15
|
|
|
use UserLib\Customer\Customer; |
|
16
|
|
|
use UserLib\Customer\CustomerInterface; |
|
17
|
|
|
use UserLib\Exception\RuntimeException; |
|
18
|
|
|
use UserLib\Product\ProductInterface; |
|
19
|
|
|
use Zend\Code\Reflection\ClassReflection; |
|
20
|
|
|
|
|
21
|
|
|
class CodeGeneratorTest extends PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
public function provideDataForGetUseLines() |
|
24
|
|
|
{ |
|
25
|
|
|
return [ |
|
26
|
|
|
'three_imports' => [ |
|
27
|
|
|
Customer::class, |
|
28
|
|
|
['use UserLib\Admin\Admin;', 'use UserLib\UserInterface;', 'use UserLib\Product\ProductInterface;'], |
|
29
|
|
|
], |
|
30
|
|
|
'no_imports' => [ |
|
31
|
|
|
ProductInterface::class, |
|
32
|
|
|
[], |
|
33
|
|
|
], |
|
34
|
|
|
'use_alias' => [ |
|
35
|
|
|
CustomerInterface::class, |
|
36
|
|
|
['use UserLib\Admin\Admin;', 'use UserLib\Product\ProductInterface as Product;'], |
|
37
|
|
|
] |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param $class |
|
43
|
|
|
* @param $expectedLines |
|
44
|
|
|
* @dataProvider provideDataForGetUseLines |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testGetUseLines($class, $expectedLines) |
|
47
|
|
|
{ |
|
48
|
|
|
$generator = new CodeGenerator(); |
|
49
|
|
|
$lines = $generator->getUseLines(new ClassReflection($class)); |
|
50
|
|
|
$this->assertEquals($expectedLines, $lines); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function provideDataForGetDeclarationLine() |
|
54
|
|
|
{ |
|
55
|
|
|
return [ |
|
56
|
|
|
'two_interfaces' => [ |
|
57
|
|
|
Customer::class, |
|
58
|
|
|
'class Customer implements CustomerInterface, UserInterface', |
|
59
|
|
|
], |
|
60
|
|
|
'extend_and_implement' => [ |
|
61
|
|
|
SuperAdmin::class, |
|
62
|
|
|
'class SuperAdmin extends Admin implements SuperAdminInterface', |
|
63
|
|
|
], |
|
64
|
|
|
'fcqn' => [ |
|
65
|
|
|
RuntimeException::class, |
|
66
|
|
|
'class RuntimeException extends \RuntimeException', |
|
67
|
|
|
] |
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param $class |
|
73
|
|
|
* @param $expectedLines |
|
74
|
|
|
* @dataProvider provideDataForGetDeclarationLine |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testGetDeclarationLine($class, $expectedLines) |
|
77
|
|
|
{ |
|
78
|
|
|
$generator = new CodeGenerator(); |
|
79
|
|
|
$lines = $generator->getDeclarationLine(new ClassReflection($class)); |
|
80
|
|
|
$this->assertEquals($expectedLines, $lines); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|