Total Complexity | 40 |
Total Lines | 363 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like StandardTest 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 StandardTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class StandardTest extends \PHPUnit\Framework\TestCase |
||
13 | { |
||
14 | private $object; |
||
15 | private $values; |
||
16 | |||
17 | |||
18 | protected function setUp() : void |
||
19 | { |
||
20 | $this->values = array( |
||
21 | 'locale.site.id' => 12, |
||
22 | 'locale.site.siteid' => 12, |
||
23 | 'locale.site.code' => 'ExtID', |
||
24 | 'locale.site.label' => 'My Site', |
||
25 | 'locale.site.config' => array( 'timezone' => 'Europe/Berlin' ), |
||
26 | 'locale.site.icon' => 'path/to/site-icon.png', |
||
27 | 'locale.site.logo' => [1 => 'path/to/site-logo.png'], |
||
28 | 'locale.site.refid' => '1234', |
||
29 | 'locale.site.theme' => 'elegance', |
||
30 | 'locale.site.status' => 1, |
||
31 | 'locale.site.mtime' => '2011-01-01 00:00:02', |
||
32 | 'locale.site.ctime' => '2011-01-01 00:00:01', |
||
33 | 'locale.site.editor' => 'unitTestUser' |
||
34 | ); |
||
35 | |||
36 | $children = array( new \Aimeos\MShop\Locale\Item\Site\Standard() ); |
||
37 | $this->object = new \Aimeos\MShop\Locale\Item\Site\Standard( $this->values, $children ); |
||
38 | } |
||
39 | |||
40 | |||
41 | protected function tearDown() : void |
||
42 | { |
||
43 | $this->object = null; |
||
44 | } |
||
45 | |||
46 | |||
47 | public function testIsModified() |
||
48 | { |
||
49 | $this->assertFalse( $this->object->isModified() ); |
||
50 | } |
||
51 | |||
52 | |||
53 | public function testGetId() |
||
54 | { |
||
55 | $this->assertEquals( 12, $this->object->getId() ); |
||
56 | } |
||
57 | |||
58 | |||
59 | public function testGetSiteId() |
||
60 | { |
||
61 | $this->assertEquals( 12, $this->object->getSiteId() ); |
||
62 | } |
||
63 | |||
64 | public function testSetId() |
||
65 | { |
||
66 | $return = $this->object->setId( null ); |
||
67 | |||
68 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
69 | $this->assertEquals( null, $this->object->getId() ); |
||
70 | $this->assertTrue( $this->object->isModified() ); |
||
71 | |||
72 | $return = $this->object->setId( 12 ); |
||
73 | |||
74 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
75 | $this->assertFalse( $this->object->isModified() ); |
||
76 | } |
||
77 | |||
78 | |||
79 | public function testGetCode() |
||
80 | { |
||
81 | $this->assertEquals( 'ExtID', $this->object->getCode() ); |
||
82 | } |
||
83 | |||
84 | |||
85 | public function testSetCode() |
||
86 | { |
||
87 | $return = $this->object->setCode( 'OtherExtID' ); |
||
88 | |||
89 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
90 | $this->assertEquals( 'OtherExtID', $this->object->getCode() ); |
||
91 | $this->assertTrue( $this->object->isModified() ); |
||
92 | } |
||
93 | |||
94 | |||
95 | public function testGetLabel() |
||
96 | { |
||
97 | $this->assertEquals( 'My Site', $this->object->getLabel() ); |
||
98 | } |
||
99 | |||
100 | |||
101 | public function testSetLabel() |
||
102 | { |
||
103 | $return = $this->object->setLabel( 'Other Name' ); |
||
104 | |||
105 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
106 | $this->assertEquals( 'Other Name', $this->object->getLabel() ); |
||
107 | $this->assertTrue( $this->object->isModified() ); |
||
108 | } |
||
109 | |||
110 | |||
111 | public function testGetIcon() |
||
112 | { |
||
113 | $this->assertEquals( 'path/to/site-icon.png', $this->object->getIcon() ); |
||
114 | } |
||
115 | |||
116 | |||
117 | public function testSetIcon() |
||
118 | { |
||
119 | $return = $this->object->setIcon( 'path/site-icon2.png' ); |
||
120 | |||
121 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
122 | $this->assertEquals( 'path/site-icon2.png', $this->object->getIcon() ); |
||
123 | $this->assertTrue( $this->object->isModified() ); |
||
124 | } |
||
125 | |||
126 | |||
127 | public function testGetLogo() |
||
128 | { |
||
129 | $this->assertEquals( 'path/to/site-logo.png', $this->object->getLogo() ); |
||
130 | } |
||
131 | |||
132 | |||
133 | public function testGetLogos() |
||
134 | { |
||
135 | $this->assertEquals( [1 => 'path/to/site-logo.png'], $this->object->getLogos() ); |
||
136 | } |
||
137 | |||
138 | |||
139 | public function testSetLogo() |
||
140 | { |
||
141 | $return = $this->object->setLogo( '/path/site-logo2.png' ); |
||
142 | |||
143 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
144 | $this->assertEquals( '/path/site-logo2.png', $this->object->getLogo() ); |
||
145 | $this->assertTrue( $this->object->isModified() ); |
||
146 | } |
||
147 | |||
148 | |||
149 | public function testSetLogos() |
||
150 | { |
||
151 | $return = $this->object->setLogos( [1 => '/path/site-logo2.png'] ); |
||
152 | |||
153 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
154 | $this->assertEquals( [1 => '/path/site-logo2.png'], $this->object->getLogos() ); |
||
155 | $this->assertTrue( $this->object->isModified() ); |
||
156 | } |
||
157 | |||
158 | |||
159 | public function testGetConfig() |
||
160 | { |
||
161 | $this->assertEquals( array( 'timezone' => 'Europe/Berlin' ), $this->object->getConfig() ); |
||
162 | } |
||
163 | |||
164 | |||
165 | public function testGetConfigValue() |
||
166 | { |
||
167 | $this->assertEquals( 'Europe/Berlin', $this->object->getConfigValue( 'timezone' ) ); |
||
168 | } |
||
169 | |||
170 | |||
171 | public function testSetConfig() |
||
172 | { |
||
173 | $return = $this->object->setConfig( array( 'timezone' => 'Europe/Paris' ) ); |
||
174 | |||
175 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
176 | $this->assertEquals( array( 'timezone' => 'Europe/Paris' ), $this->object->getConfig() ); |
||
177 | $this->assertTrue( $this->object->isModified() ); |
||
178 | } |
||
179 | |||
180 | |||
181 | public function testGetStatus() |
||
182 | { |
||
183 | $this->assertEquals( 1, $this->object->getStatus() ); |
||
184 | } |
||
185 | |||
186 | |||
187 | public function testSetStatus() |
||
188 | { |
||
189 | $return = $this->object->setStatus( 0 ); |
||
190 | |||
191 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
192 | $this->assertEquals( 0, $this->object->getStatus() ); |
||
193 | $this->assertTrue( $this->object->isModified() ); |
||
194 | } |
||
195 | |||
196 | |||
197 | public function testGetRefId() |
||
198 | { |
||
199 | $this->assertEquals( '1234', $this->object->getRefId() ); |
||
200 | } |
||
201 | |||
202 | |||
203 | public function testSetRefId() |
||
204 | { |
||
205 | $return = $this->object->setRefId( '5678' ); |
||
206 | |||
207 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
208 | $this->assertEquals( '5678', $this->object->getRefId() ); |
||
209 | $this->assertTrue( $this->object->isModified() ); |
||
210 | } |
||
211 | |||
212 | |||
213 | public function testGetTheme() |
||
214 | { |
||
215 | $this->assertEquals( 'elegance', $this->object->getTheme() ); |
||
216 | } |
||
217 | |||
218 | |||
219 | public function testSetTheme() |
||
220 | { |
||
221 | $return = $this->object->setTheme( 'shop' ); |
||
222 | |||
223 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
||
224 | $this->assertEquals( 'shop', $this->object->getTheme() ); |
||
225 | $this->assertTrue( $this->object->isModified() ); |
||
226 | } |
||
227 | |||
228 | |||
229 | public function testGetTimeModified() |
||
232 | } |
||
233 | |||
234 | |||
235 | public function testGetTimeCreated() |
||
236 | { |
||
237 | $this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
||
238 | } |
||
239 | |||
240 | |||
241 | public function testGetEditor() |
||
242 | { |
||
243 | $this->assertEquals( 'unitTestUser', $this->object->editor() ); |
||
244 | } |
||
245 | |||
246 | |||
247 | public function testGetResourceType() |
||
248 | { |
||
249 | $this->assertEquals( 'locale/site', $this->object->getResourceType() ); |
||
250 | } |
||
251 | |||
252 | |||
253 | public function testIsAvailable() |
||
254 | { |
||
255 | $this->assertTrue( $this->object->isAvailable() ); |
||
256 | $this->object->setAvailable( false ); |
||
257 | $this->assertFalse( $this->object->isAvailable() ); |
||
258 | } |
||
259 | |||
260 | |||
261 | public function testIsAvailableOnStatus() |
||
262 | { |
||
263 | $this->assertTrue( $this->object->isAvailable() ); |
||
264 | $this->object->setStatus( 0 ); |
||
265 | $this->assertFalse( $this->object->isAvailable() ); |
||
266 | $this->object->setStatus( -1 ); |
||
267 | $this->assertFalse( $this->object->isAvailable() ); |
||
268 | } |
||
269 | |||
270 | |||
271 | public function testFromArray() |
||
272 | { |
||
273 | $item = new \Aimeos\MShop\Locale\Item\Site\Standard(); |
||
274 | |||
275 | $list = $entries = array( |
||
276 | 'locale.site.id' => 2, |
||
277 | 'locale.site.code' => 'test', |
||
278 | 'locale.site.label' => 'test item', |
||
279 | 'locale.site.status' => 1, |
||
280 | 'locale.site.config' => ['test'], |
||
281 | 'locale.site.icon' => 'site-icon.jpg', |
||
282 | 'locale.site.logo' => [1 => 'site-logo.jpg'], |
||
283 | 'locale.site.refid' => '9876', |
||
284 | 'locale.site.theme' => 'shop', |
||
285 | ); |
||
286 | |||
287 | $item = $item->fromArray( $entries, true ); |
||
288 | |||
289 | $this->assertEquals( [], $entries ); |
||
290 | $this->assertEquals( $list['locale.site.id'], $item->getId() ); |
||
291 | $this->assertEquals( $list['locale.site.code'], $item->getCode() ); |
||
292 | $this->assertEquals( $list['locale.site.label'], $item->getLabel() ); |
||
293 | $this->assertEquals( $list['locale.site.status'], $item->getStatus() ); |
||
294 | $this->assertEquals( $list['locale.site.config'], $item->getConfig() ); |
||
295 | $this->assertEquals( $list['locale.site.refid'], $item->getRefId() ); |
||
296 | $this->assertEquals( $list['locale.site.theme'], $item->getTheme() ); |
||
297 | $this->assertEquals( $list['locale.site.logo'], $item->getLogos() ); |
||
298 | $this->assertEquals( $list['locale.site.icon'], $item->getIcon() ); |
||
299 | } |
||
300 | |||
301 | |||
302 | public function testToArray() |
||
303 | { |
||
304 | $arrayObject = $this->object->toArray( true ); |
||
305 | |||
306 | $this->assertEquals( count( $this->values ) + 3, count( $arrayObject ) ); |
||
307 | |||
308 | $this->assertEquals( $this->object->getId(), $arrayObject['locale.site.id'] ); |
||
309 | $this->assertEquals( $this->object->getSiteId(), $arrayObject['locale.site.siteid'] ); |
||
310 | $this->assertEquals( $this->object->getCode(), $arrayObject['locale.site.code'] ); |
||
311 | $this->assertEquals( $this->object->getLabel(), $arrayObject['locale.site.label'] ); |
||
312 | $this->assertEquals( $this->object->getStatus(), $arrayObject['locale.site.status'] ); |
||
313 | $this->assertEquals( $this->object->getConfig(), $arrayObject['locale.site.config'] ); |
||
314 | $this->assertEquals( $this->object->getLogos(), $arrayObject['locale.site.logo'] ); |
||
315 | $this->assertEquals( $this->object->getIcon(), $arrayObject['locale.site.icon'] ); |
||
316 | $this->assertEquals( $this->object->getTheme(), $arrayObject['locale.site.theme'] ); |
||
317 | $this->assertEquals( $this->object->getRefId(), $arrayObject['locale.site.refid'] ); |
||
318 | $this->assertEquals( $this->object->getTimeCreated(), $arrayObject['locale.site.ctime'] ); |
||
319 | $this->assertEquals( $this->object->getTimeModified(), $arrayObject['locale.site.mtime'] ); |
||
320 | $this->assertEquals( $this->object->editor(), $arrayObject['locale.site.editor'] ); |
||
321 | } |
||
322 | |||
323 | |||
324 | public function testAddChild() |
||
325 | { |
||
326 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Tree\Iface::class, $this->object->addChild( $this->object ) ); |
||
327 | } |
||
328 | |||
329 | |||
330 | public function testDeleteChild() |
||
331 | { |
||
332 | $result = $this->object->deleteChild( $this->object ); |
||
333 | |||
334 | $this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $result ); |
||
335 | $this->assertEquals( 0, count( $this->object->getChildren() ) ); |
||
336 | } |
||
337 | |||
338 | |||
339 | public function testGetChild() |
||
340 | { |
||
341 | $this->expectException( \Aimeos\MShop\Locale\Exception::class ); |
||
342 | $this->object->getChild( 0 ); |
||
343 | } |
||
344 | |||
345 | |||
346 | public function testGetChildren() |
||
347 | { |
||
348 | $this->assertInstanceOf( \Aimeos\Map::class, $this->object->getChildren() ); |
||
349 | $this->assertEquals( [], $this->object->getChildren()->toArray() ); |
||
350 | } |
||
351 | |||
352 | |||
353 | public function testGetChildrenDeleted() |
||
354 | { |
||
355 | $result = $this->object->getChildrenDeleted(); |
||
356 | |||
357 | $this->assertInstanceOf( \Aimeos\Map::class, $result ); |
||
358 | $this->assertEquals( [], $result->toArray() ); |
||
359 | } |
||
360 | |||
361 | |||
362 | public function testToList() |
||
369 | } |
||
370 | |||
371 | |||
372 | public function testHasChildren() |
||
373 | { |
||
374 | $this->assertFalse( $this->object->hasChildren() ); |
||
375 | } |
||
376 | } |
||
377 |