|
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\ClassDumper; |
|
13
|
|
|
use PHPUnit_Framework_TestCase; |
|
14
|
|
|
use UserLib\Admin\Admin; |
|
15
|
|
|
use UserLib\Admin\SuperAdmin; |
|
16
|
|
|
use UserLib\Customer\Customer; |
|
17
|
|
|
use UserLib\Exception\RuntimeException; |
|
18
|
|
|
use UserLib\Product\Phone; |
|
19
|
|
|
use UserLib\Product\ProductInterface; |
|
20
|
|
|
use UserLib\UserInterface; |
|
21
|
|
|
|
|
22
|
|
|
class ClassDumperTest extends PHPUnit_Framework_TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
public function testDumpCreatesMergedClasses() |
|
25
|
|
|
{ |
|
26
|
|
|
$dumper = new ClassDumper(); |
|
27
|
|
|
$classes = [ |
|
28
|
|
|
UserInterface::class, |
|
29
|
|
|
Admin::class, |
|
30
|
|
|
ProductInterface::class, |
|
31
|
|
|
Customer::class, |
|
32
|
|
|
]; |
|
33
|
|
|
$cache = $dumper->dump($classes); |
|
34
|
|
|
$this->assertEquals('namespace UserLib { |
|
35
|
|
|
interface UserInterface |
|
36
|
|
|
{ |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
namespace UserLib\Admin { |
|
41
|
|
|
use UserLib\UserInterface; |
|
42
|
|
|
class Admin implements UserInterface |
|
43
|
|
|
{ |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
namespace UserLib\Product { |
|
48
|
|
|
interface ProductInterface |
|
49
|
|
|
{ |
|
50
|
|
|
public function getName(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
namespace UserLib\Customer { |
|
55
|
|
|
use UserLib\Admin\Admin; |
|
56
|
|
|
use UserLib\Product\ProductInterface as Product; |
|
57
|
|
|
interface CustomerInterface |
|
58
|
|
|
{ |
|
59
|
|
|
public function buy(Product $product); |
|
60
|
|
|
|
|
61
|
|
|
public function sendMessageToAdmin(Admin $admin); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
namespace UserLib\Customer { |
|
66
|
|
|
use UserLib\Admin\Admin; |
|
67
|
|
|
use UserLib\UserInterface; |
|
68
|
|
|
use UserLib\Product\ProductInterface; |
|
69
|
|
|
class Customer implements CustomerInterface, UserInterface |
|
70
|
|
|
{ |
|
71
|
|
|
public function buy(ProductInterface $product) |
|
72
|
|
|
{ |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function sendMessageToAdmin(Admin $admin) |
|
76
|
|
|
{ |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
', $cache); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testDumpCreatesMergedAndMinifiedClasses() |
|
84
|
|
|
{ |
|
85
|
|
|
$dumper = new ClassDumper(); |
|
86
|
|
|
$classes = [ |
|
87
|
|
|
UserInterface::class, |
|
88
|
|
|
Admin::class, |
|
89
|
|
|
ProductInterface::class, |
|
90
|
|
|
Customer::class, |
|
91
|
|
|
]; |
|
92
|
|
|
$cache = $dumper->dump($classes, true); |
|
93
|
|
|
$this->assertEquals('namespace UserLib { interface UserInterface { } } namespace UserLib\Admin { use UserLib\UserInterface; class Admin implements UserInterface { } } namespace UserLib\Product { interface ProductInterface { public function getName(); } } namespace UserLib\Customer { use UserLib\Admin\Admin; use UserLib\Product\ProductInterface as Product; interface CustomerInterface { public function buy(Product $product); public function sendMessageToAdmin(Admin $admin); } } namespace UserLib\Customer { use UserLib\Admin\Admin; use UserLib\UserInterface; use UserLib\Product\ProductInterface; class Customer implements CustomerInterface, UserInterface { public function buy(ProductInterface $product) { } public function sendMessageToAdmin(Admin $admin) { } } }', $cache); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testDumpIncludesRequiredInterfacesAndParentClasses() |
|
97
|
|
|
{ |
|
98
|
|
|
$dumper = new ClassDumper(); |
|
99
|
|
|
$classes = [ |
|
100
|
|
|
SuperAdmin::class, |
|
101
|
|
|
]; |
|
102
|
|
|
$cache = $dumper->dump($classes); |
|
103
|
|
|
$this->assertEquals('namespace UserLib { |
|
104
|
|
|
interface UserInterface |
|
105
|
|
|
{ |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
namespace UserLib\Admin { |
|
110
|
|
|
use UserLib\UserInterface; |
|
111
|
|
|
class Admin implements UserInterface |
|
112
|
|
|
{ |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
namespace UserLib\Admin { |
|
117
|
|
|
interface SuperAdminInterface |
|
118
|
|
|
{ |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
namespace UserLib\Admin { |
|
123
|
|
|
class SuperAdmin extends Admin implements SuperAdminInterface |
|
124
|
|
|
{ |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
', $cache); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function testDumpIncludesRequiredTraits() |
|
131
|
|
|
{ |
|
132
|
|
|
$dumper = new ClassDumper(); |
|
133
|
|
|
$classes = [ |
|
134
|
|
|
Phone::class, |
|
135
|
|
|
]; |
|
136
|
|
|
$cache = $dumper->dump($classes); |
|
137
|
|
|
$this->assertEquals('namespace UserLib\Product { |
|
138
|
|
|
interface ProductInterface |
|
139
|
|
|
{ |
|
140
|
|
|
public function getName(); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
namespace UserLib\Product { |
|
145
|
|
|
trait GpsTrait |
|
146
|
|
|
{ |
|
147
|
|
|
public function locate() |
|
148
|
|
|
{ |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
namespace UserLib\Product { |
|
154
|
|
|
class Phone implements ProductInterface |
|
155
|
|
|
{ |
|
156
|
|
|
use GpsTrait; |
|
157
|
|
|
|
|
158
|
|
|
public function getName() |
|
159
|
|
|
{ |
|
160
|
|
|
return \'phone\'; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
', $cache); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function testDumpSkipsInternalClasses() |
|
168
|
|
|
{ |
|
169
|
|
|
$dumper = new ClassDumper(); |
|
170
|
|
|
$classes = [ |
|
171
|
|
|
RuntimeException::class, |
|
172
|
|
|
]; |
|
173
|
|
|
$cache = $dumper->dump($classes); |
|
174
|
|
|
$this->assertEquals('namespace UserLib\Exception { |
|
175
|
|
|
class RuntimeException extends \RuntimeException |
|
176
|
|
|
{ |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
', $cache); |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|