Total Complexity | 51 |
Total Lines | 323 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Complex classes like CodeGeneratorEventDispatcherTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CodeGeneratorEventDispatcherTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class CodeGeneratorEventDispatcherTest extends TestCase |
||
13 | { |
||
14 | /** |
||
15 | * @var CodeGeneratorEventDispatcher |
||
16 | */ |
||
17 | private $dispatcher; |
||
18 | private $method1; |
||
19 | private $method2; |
||
20 | private $method3; |
||
21 | private $method4; |
||
22 | private $method5; |
||
23 | private $beanDescriptor; |
||
24 | private $configuration; |
||
25 | private $class; |
||
26 | private $file; |
||
27 | private $pivotTableMethodsDescriptor; |
||
28 | private $beanPropertyDescriptor; |
||
29 | private $nullDispatcher; |
||
30 | |||
31 | public function setUp(): void |
||
32 | { |
||
33 | $this->dispatcher = new CodeGeneratorEventDispatcher([new BaseCodeGeneratorListener()]); |
||
34 | $this->nullDispatcher = new CodeGeneratorEventDispatcher([new class () implements CodeGeneratorListenerInterface { |
||
35 | public function onBaseBeanGenerated(FileGenerator $fileGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration): ?FileGenerator |
||
36 | { |
||
37 | return null; |
||
38 | } |
||
39 | |||
40 | public function onBaseBeanConstructorGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
41 | { |
||
42 | return null; |
||
43 | } |
||
44 | |||
45 | public function onBaseBeanPropertyGenerated(?MethodGenerator $getter, ?MethodGenerator $setter, AbstractBeanPropertyDescriptor $propertyDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): array |
||
46 | { |
||
47 | return [null, null]; |
||
48 | } |
||
49 | |||
50 | public function onBaseBeanOneToManyGenerated(MethodGenerator $getter, DirectForeignKeyMethodDescriptor $directForeignKeyMethodDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
51 | { |
||
52 | return null; |
||
53 | } |
||
54 | |||
55 | public function onBaseBeanManyToManyGenerated(?MethodGenerator $getter, ?MethodGenerator $adder, ?MethodGenerator $remover, ?MethodGenerator $hasser, ?MethodGenerator $setter, PivotTableMethodsDescriptor $pivotTableMethodsDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): array |
||
56 | { |
||
57 | return [null, null, null, null, null]; |
||
58 | } |
||
59 | |||
60 | public function onBaseBeanJsonSerializeGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
61 | { |
||
62 | return null; |
||
63 | } |
||
64 | |||
65 | public function onBaseBeanCloneGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
68 | } |
||
69 | |||
70 | public function onBaseDaoGenerated(FileGenerator $fileGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration): ?FileGenerator |
||
71 | { |
||
72 | return null; |
||
73 | } |
||
74 | |||
75 | public function onBaseDaoConstructorGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
76 | { |
||
77 | return null; |
||
78 | } |
||
79 | |||
80 | public function onBaseDaoSaveGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
81 | { |
||
82 | return null; |
||
83 | } |
||
84 | |||
85 | public function onBaseDaoFindAllGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
86 | { |
||
87 | return null; |
||
88 | } |
||
89 | |||
90 | public function onBaseDaoGetByIdGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
91 | { |
||
92 | return null; |
||
93 | } |
||
94 | |||
95 | public function onBaseDaoDeleteGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
96 | { |
||
97 | return null; |
||
98 | } |
||
99 | |||
100 | public function onBaseDaoFindGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
101 | { |
||
102 | return null; |
||
103 | } |
||
104 | |||
105 | public function onBaseDaoFindFromSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
108 | } |
||
109 | |||
110 | public function onBaseDaoFindFromRawSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
111 | { |
||
112 | return null; |
||
113 | } |
||
114 | |||
115 | public function onBaseDaoFindOneGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
116 | { |
||
117 | return null; |
||
118 | } |
||
119 | |||
120 | public function onBaseDaoFindOneFromSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
121 | { |
||
122 | return null; |
||
123 | } |
||
124 | |||
125 | public function onBaseDaoSetDefaultSortGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
126 | { |
||
127 | return null; |
||
128 | } |
||
129 | |||
130 | public function onBaseDaoFindByIndexGenerated(MethodGenerator $methodGenerator, Index $index, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
133 | } |
||
134 | |||
135 | public function onBaseResultIteratorGenerated(FileGenerator $fileGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration): ?FileGenerator |
||
136 | { |
||
137 | return null; |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * @param BeanDescriptor[] $beanDescriptors |
||
142 | */ |
||
143 | public function onDaoFactoryGenerated(FileGenerator $fileGenerator, array $beanDescriptors, ConfigurationInterface $configuration): ?FileGenerator |
||
144 | { |
||
145 | return null; |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @param BeanDescriptor[] $beanDescriptors |
||
150 | */ |
||
151 | public function onDaoFactoryConstructorGenerated(MethodGenerator $methodGenerator, array $beanDescriptors, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
152 | { |
||
153 | return null; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param BeanDescriptor[] $beanDescriptor |
||
158 | */ |
||
159 | public function onDaoFactoryGetterGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
160 | { |
||
161 | return null; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * @param BeanDescriptor[] $beanDescriptor |
||
166 | */ |
||
167 | public function onDaoFactorySetterGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator |
||
168 | { |
||
169 | return null; |
||
170 | } |
||
171 | }]); |
||
172 | $this->method1 = new MethodGenerator(); |
||
173 | $this->method2 = new MethodGenerator(); |
||
174 | $this->method3 = new MethodGenerator(); |
||
175 | $this->method4 = new MethodGenerator(); |
||
176 | $this->method5 = new MethodGenerator(); |
||
177 | $this->beanDescriptor = $this->getMockBuilder(BeanDescriptor::class)->disableOriginalConstructor()->getMock(); |
||
178 | $this->configuration = $this->getMockBuilder(ConfigurationInterface::class)->disableOriginalConstructor()->getMock(); |
||
179 | $this->pivotTableMethodsDescriptor = $this->getMockBuilder(PivotTableMethodsDescriptor::class)->disableOriginalConstructor()->getMock(); |
||
180 | $this->beanPropertyDescriptor = $this->getMockBuilder(ScalarBeanPropertyDescriptor::class)->disableOriginalConstructor()->getMock(); |
||
181 | $this->class = new ClassGenerator(); |
||
182 | $this->file = new FileGenerator(); |
||
183 | } |
||
184 | |||
185 | public function testOnBaseDaoFindAllGenerated(): void |
||
186 | { |
||
187 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoFindAllGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
188 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoFindAllGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
189 | } |
||
190 | |||
191 | public function testOnBaseBeanJsonSerializeGenerated(): void |
||
192 | { |
||
193 | $this->assertSame($this->method1, $this->dispatcher->onBaseBeanJsonSerializeGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
194 | $this->assertSame(null, $this->nullDispatcher->onBaseBeanJsonSerializeGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
195 | } |
||
196 | |||
197 | public function testOnBaseDaoConstructorGenerated(): void |
||
198 | { |
||
199 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoConstructorGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
200 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoConstructorGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
201 | } |
||
202 | |||
203 | public function testOnBaseDaoFindOneFromSqlGenerated(): void |
||
204 | { |
||
205 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoFindOneFromSqlGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
206 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoFindOneFromSqlGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
207 | } |
||
208 | |||
209 | public function testOnBaseDaoGenerated(): void |
||
210 | { |
||
211 | $this->assertSame($this->file, $this->dispatcher->onBaseDaoGenerated($this->file, $this->beanDescriptor, $this->configuration)); |
||
212 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoGenerated($this->file, $this->beanDescriptor, $this->configuration)); |
||
213 | } |
||
214 | |||
215 | public function testOnBaseDaoSetDefaultSortGenerated(): void |
||
216 | { |
||
217 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoSetDefaultSortGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
218 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoSetDefaultSortGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
219 | } |
||
220 | |||
221 | public function testOnBaseDaoSaveGenerated(): void |
||
222 | { |
||
223 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoSaveGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
224 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoSaveGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
225 | } |
||
226 | |||
227 | public function testOnBaseDaoGetByIdGenerated(): void |
||
228 | { |
||
229 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoGetByIdGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
230 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoGetByIdGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
231 | } |
||
232 | |||
233 | public function testOnBaseBeanCloneGenerated(): void |
||
237 | } |
||
238 | |||
239 | public function testOnBaseDaoFindOneGenerated(): void |
||
240 | { |
||
241 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoFindOneGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
242 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoFindOneGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
243 | } |
||
244 | |||
245 | public function testOnBaseBeanPropertyGenerated(): void |
||
249 | } |
||
250 | |||
251 | public function testOnBaseDaoFindGenerated(): void |
||
252 | { |
||
253 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoFindGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
254 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoFindGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
255 | } |
||
256 | |||
257 | public function testOnBaseBeanOneToManyGenerated(): void |
||
258 | { |
||
259 | $directForeignKeyMethodDescriptor = $this->getMockBuilder(DirectForeignKeyMethodDescriptor::class)->disableOriginalConstructor()->getMock(); |
||
260 | $this->assertSame($this->method1, $this->dispatcher->onBaseBeanOneToManyGenerated($this->method1, $directForeignKeyMethodDescriptor, $this->beanDescriptor, $this->configuration, $this->class)); |
||
261 | $this->assertSame(null, $this->nullDispatcher->onBaseBeanOneToManyGenerated($this->method1, $directForeignKeyMethodDescriptor, $this->beanDescriptor, $this->configuration, $this->class)); |
||
262 | } |
||
263 | |||
264 | public function testOnBaseDaoFindFromSqlGenerated(): void |
||
265 | { |
||
266 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoFindFromSqlGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
267 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoFindFromSqlGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
268 | } |
||
269 | |||
270 | public function testOnBaseBeanConstructorGenerated(): void |
||
271 | { |
||
272 | $this->assertSame($this->method1, $this->dispatcher->onBaseBeanConstructorGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
273 | $this->assertSame(null, $this->nullDispatcher->onBaseBeanConstructorGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
274 | } |
||
275 | |||
276 | public function testOnBaseDaoFindFromRawSqlGenerated(): void |
||
280 | } |
||
281 | |||
282 | public function testOnBaseDaoDeleteGenerated(): void |
||
283 | { |
||
284 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoDeleteGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
285 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoDeleteGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
286 | } |
||
287 | |||
288 | public function testOnBaseBeanGenerated(): void |
||
289 | { |
||
290 | $this->assertSame($this->file, $this->dispatcher->onBaseBeanGenerated($this->file, $this->beanDescriptor, $this->configuration)); |
||
291 | $this->assertSame(null, $this->nullDispatcher->onBaseBeanGenerated($this->file, $this->beanDescriptor, $this->configuration)); |
||
292 | } |
||
293 | |||
294 | public function testOnBaseBeanManyToManyGenerated(): void |
||
295 | { |
||
296 | $this->assertSame([$this->method1, $this->method2, $this->method3, $this->method4, $this->method5], $this->dispatcher->onBaseBeanManyToManyGenerated($this->method1, $this->method2, $this->method3, $this->method4, $this->method5, $this->pivotTableMethodsDescriptor, $this->beanDescriptor, $this->configuration, $this->class)); |
||
297 | $this->assertSame([null, null, null, null, null], $this->nullDispatcher->onBaseBeanManyToManyGenerated(null, null, null, null, null, $this->pivotTableMethodsDescriptor, $this->beanDescriptor, $this->configuration, $this->class)); |
||
298 | } |
||
299 | |||
300 | public function testOnBaseDaoFindByIndexGenerated(): void |
||
301 | { |
||
302 | $index = $this->getMockBuilder(Index::class)->disableOriginalConstructor()->getMock(); |
||
303 | $this->assertSame($this->method1, $this->dispatcher->onBaseDaoFindByIndexGenerated($this->method1, $index, $this->beanDescriptor, $this->configuration, $this->class)); |
||
304 | $this->assertSame(null, $this->nullDispatcher->onBaseDaoFindByIndexGenerated($this->method1, $index, $this->beanDescriptor, $this->configuration, $this->class)); |
||
305 | } |
||
306 | |||
307 | public function testOnBaseResultIteratorGenerated(): void |
||
308 | { |
||
309 | $this->assertSame($this->file, $this->dispatcher->onBaseResultIteratorGenerated($this->file, $this->beanDescriptor, $this->configuration)); |
||
310 | $this->assertSame(null, $this->nullDispatcher->onBaseResultIteratorGenerated($this->file, $this->beanDescriptor, $this->configuration)); |
||
311 | } |
||
312 | |||
313 | public function testOnDaoFactoryGenerated(): void |
||
314 | { |
||
315 | $this->assertSame($this->file, $this->dispatcher->onDaoFactoryGenerated($this->file, [], $this->configuration)); |
||
316 | $this->assertSame(null, $this->nullDispatcher->onDaoFactoryGenerated($this->file, [], $this->configuration)); |
||
317 | } |
||
318 | |||
319 | public function testOnDaoFactoryConstructorGenerated(): void |
||
320 | { |
||
321 | $this->assertSame($this->method1, $this->dispatcher->onDaoFactoryConstructorGenerated($this->method1, [], $this->configuration, $this->class)); |
||
322 | $this->assertSame(null, $this->nullDispatcher->onDaoFactoryConstructorGenerated($this->method1, [], $this->configuration, $this->class)); |
||
323 | } |
||
324 | |||
325 | public function testOnDaoFactoryGetterGenerated(): void |
||
326 | { |
||
327 | $this->assertSame($this->method1, $this->dispatcher->onDaoFactoryGetterGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
328 | $this->assertSame(null, $this->nullDispatcher->onDaoFactoryGetterGenerated($this->method1, $this->beanDescriptor, $this->configuration, $this->class)); |
||
329 | } |
||
330 | |||
331 | public function testOnDaoFactorySetterGenerated(): void |
||
335 | } |
||
336 | } |
||
337 |