| Total Complexity | 46 |
| Total Lines | 288 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like FlyingAnimalCreateTest 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 FlyingAnimalCreateTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class FlyingAnimalCreateTest extends TestModelTest |
||
| 16 | { |
||
| 17 | protected $tweety; |
||
| 18 | protected $hedwig; |
||
| 19 | protected $birdo; |
||
| 20 | protected $plucky; |
||
| 21 | protected $fiffy; |
||
| 22 | protected $timmy; |
||
| 23 | protected $daisy; |
||
| 24 | |||
| 25 | protected function setUp(): void |
||
| 50 | } |
||
| 51 | |||
| 52 | public function testSetWingspanAttributeByHelper(): void |
||
| 53 | { |
||
| 54 | $wingspan = 2.123; |
||
| 55 | $this->tweety->setWingspan($wingspan); |
||
| 56 | $this->assertEquals($wingspan, $this->tweety->getWingspan()); |
||
| 57 | } |
||
| 58 | |||
| 59 | public function testSetWingspanAttributeByAttributeName(): void |
||
| 60 | { |
||
| 61 | $wingspan = 2.123; |
||
| 62 | $this->tweety->setAttributeValue("wingspan", $wingspan, false); |
||
| 63 | $this->assertEquals($wingspan, $this->tweety->getWingspan()); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function testRemoveWingspanAttribute(): void |
||
| 67 | { |
||
| 68 | $wingspan = 2.123; |
||
| 69 | $this->tweety->setWingspan($wingspan); |
||
| 70 | $this->assertEquals($wingspan, $this->tweety->getWingspan()); |
||
| 71 | |||
| 72 | $this->tweety->removeAttribute("wingspan"); |
||
| 73 | |||
| 74 | $this->assertNull($this->tweety->getWingspan()); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function testSetFlightInstructorByHelper(): void |
||
| 81 | } |
||
| 82 | |||
| 83 | public function testUpdateFlightInstructorByIdHelper(): void |
||
| 84 | { |
||
| 85 | $this->hedwig->setId("new-" . $this->hedwig->getId()); |
||
| 86 | $this->assertTrue($this->tweety->getFlightInstructor()->equals($this->hedwig)); |
||
| 87 | } |
||
| 88 | |||
| 89 | public function testUpdateFlightInstructorByIdAttributeName(): void |
||
| 90 | { |
||
| 91 | $this->hedwig->setAttributeValue("id", "new-" . $this->hedwig->getId(), true); |
||
| 92 | $this->assertTrue($this->tweety->getFlightInstructor()->equals($this->hedwig)); |
||
| 93 | } |
||
| 94 | |||
| 95 | public function testUpdateFlightInstructorByReplaceElement(): void |
||
| 96 | { |
||
| 97 | $this->hedwig->replaceWithElement($this->timmy); |
||
| 98 | $this->assertTrue($this->tweety->getFlightInstructor()->equals($this->timmy)); |
||
| 99 | } |
||
| 100 | |||
| 101 | public function testUpdateFlightInstructorByRemoveElement(): void |
||
| 102 | { |
||
| 103 | $animals = $this->modelInstance->getDocumentElement(); |
||
| 104 | $animals->removeAnimal($this->hedwig); |
||
| 105 | $this->assertNull($this->tweety->getFlightInstructor()); |
||
| 106 | } |
||
| 107 | |||
| 108 | public function testClearFlightInstructor(): void |
||
| 109 | { |
||
| 110 | $this->tweety->removeFlightInstructor(); |
||
| 111 | $this->assertNull($this->tweety->getFlightInstructor()); |
||
| 112 | } |
||
| 113 | |||
| 114 | public function testAddFlightPartnerRefsByHelper(): void |
||
| 115 | { |
||
| 116 | $this->assertCount(4, $this->tweety->getFlightPartnerRefs()); |
||
| 117 | $birds = [$this->hedwig, $this->birdo, $this->plucky, $this->fiffy]; |
||
| 118 | foreach ($birds as $bird) { |
||
| 119 | $exists = false; |
||
| 120 | foreach ($this->tweety->getFlightPartnerRefs() as $ref) { |
||
| 121 | if ($ref->equals($bird)) { |
||
| 122 | $exists = true; |
||
| 123 | break; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | $this->assertTrue($exists); |
||
| 127 | } |
||
| 128 | $this->tweety->addFlightPartnerRef($this->timmy); |
||
| 129 | $this->tweety->addFlightPartnerRef($this->daisy); |
||
| 130 | |||
| 131 | $birds[] = $this->timmy; |
||
| 132 | $birds[] = $this->daisy; |
||
| 133 | |||
| 134 | foreach ($birds as $bird) { |
||
| 135 | $exists = false; |
||
| 136 | foreach ($this->tweety->getFlightPartnerRefs() as $ref) { |
||
| 137 | if ($ref->equals($bird)) { |
||
| 138 | $exists = true; |
||
| 139 | break; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | $this->assertTrue($exists); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | public function testUpdateFlightPartnerRefsByIdByHelper(): void |
||
| 147 | { |
||
| 148 | $this->hedwig->setId("new-" . $this->hedwig->getId()); |
||
| 149 | $this->plucky->setId("new-" . $this->plucky->getId()); |
||
| 150 | $this->assertCount(4, $this->tweety->getFlightPartnerRefs()); |
||
| 151 | $birds = [$this->hedwig, $this->birdo, $this->plucky, $this->fiffy]; |
||
| 152 | foreach ($birds as $bird) { |
||
| 153 | $exists = false; |
||
| 154 | foreach ($this->tweety->getFlightPartnerRefs() as $ref) { |
||
| 155 | if ($ref->equals($bird)) { |
||
| 156 | $exists = true; |
||
| 157 | break; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | $this->assertTrue($exists); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | public function testUpdateFlightPartnerRefsByIdByAttributeName(): void |
||
| 165 | { |
||
| 166 | $this->birdo->setAttributeValue("id", "new-" . $this->birdo->getId(), true); |
||
| 167 | $this->fiffy->setAttributeValue("id", "new-" . $this->fiffy->getId(), true); |
||
| 168 | $birds = [$this->hedwig, $this->birdo, $this->plucky, $this->fiffy]; |
||
| 169 | foreach ($birds as $bird) { |
||
| 170 | $exists = false; |
||
| 171 | foreach ($this->tweety->getFlightPartnerRefs() as $ref) { |
||
| 172 | if ($ref->equals($bird)) { |
||
| 173 | $exists = true; |
||
| 174 | break; |
||
| 175 | } |
||
| 176 | } |
||
| 177 | $this->assertTrue($exists); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | public function testUpdateFlightPartnerRefsByReplaceElements(): void |
||
| 182 | { |
||
| 183 | $this->hedwig->replaceWithElement($this->timmy); |
||
| 184 | $this->plucky->replaceWithElement($this->daisy); |
||
| 185 | $birds = [$this->timmy, $this->birdo, $this->daisy, $this->fiffy]; |
||
| 186 | foreach ($birds as $bird) { |
||
| 187 | $exists = false; |
||
| 188 | foreach ($this->tweety->getFlightPartnerRefs() as $ref) { |
||
| 189 | if ($ref->equals($bird)) { |
||
| 190 | $exists = true; |
||
| 191 | break; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | $this->assertTrue($exists); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | |||
| 198 | public function testUpdateFlightPartnerRefsByRemoveElements(): void |
||
| 213 | } |
||
| 214 | } |
||
| 215 | |||
| 216 | public function testClearFlightPartnerRefs(): void |
||
| 217 | { |
||
| 218 | $this->tweety->clearFlightPartnerRefs(); |
||
| 219 | $this->assertEmpty($this->tweety->getFlightPartnerRefs()); |
||
| 220 | } |
||
| 221 | |||
| 222 | public function testAddFlightPartnerRefElementsByHelper(): void |
||
| 223 | { |
||
| 224 | $this->assertCount(4, $this->tweety->getFlightPartnerRefElements()); |
||
| 225 | |||
| 226 | $timmyFlightPartnerRef = $this->modelInstance->newInstance(FlightPartnerRef::class); |
||
| 227 | $timmyFlightPartnerRef->setTextContent($this->timmy->getId()); |
||
| 228 | $this->tweety->addFlightPartnerRefElement($timmyFlightPartnerRef); |
||
| 229 | |||
| 230 | $daisyFlightPartnerRef = $this->modelInstance->newInstance(FlightPartnerRef::class); |
||
| 231 | $daisyFlightPartnerRef->setTextContent($this->daisy->getId()); |
||
| 232 | $this->tweety->addFlightPartnerRefElement($daisyFlightPartnerRef); |
||
| 233 | |||
| 234 | $this->assertCount(6, $this->tweety->getFlightPartnerRefElements()); |
||
| 235 | } |
||
| 236 | |||
| 237 | public function testFlightPartnerRefElementsByTextContent(): void |
||
| 238 | { |
||
| 239 | $flightPartnerRefElements = $this->tweety->getFlightPartnerRefElements(); |
||
| 240 | $textContents = []; |
||
| 241 | foreach ($flightPartnerRefElements as $flightPartnerRefElement) { |
||
| 242 | $textContent = $flightPartnerRefElement->getTextContent(); |
||
| 243 | $this->assertFalse(empty($textContent)); |
||
| 244 | $textContents[] = $textContent; |
||
| 245 | } |
||
| 246 | $this->assertCount(4, $textContents); |
||
| 247 | $this->assertContains($this->hedwig->getId(), $textContents); |
||
| 248 | $this->assertContains($this->birdo->getId(), $textContents); |
||
| 249 | $this->assertContains($this->plucky->getId(), $textContents); |
||
| 250 | $this->assertContains($this->fiffy->getId(), $textContents); |
||
| 251 | } |
||
| 252 | |||
| 253 | public function testUpdateFlightPartnerRefElementsByTextContent(): void |
||
| 254 | { |
||
| 255 | $flightPartnerRefs = $this->tweety->getFlightPartnerRefElements(); |
||
| 256 | |||
| 257 | $flightPartnerRefs[0]->setTextContent($this->timmy->getId()); |
||
| 258 | $flightPartnerRefs[2]->setTextContent($this->daisy->getId()); |
||
| 259 | |||
| 260 | $this->assertCount(4, $this->tweety->getFlightPartnerRefs()); |
||
| 261 | |||
| 262 | $birds = [$this->birdo, $this->fiffy, $this->timmy, $this->daisy]; |
||
| 263 | foreach ($birds as $bird) { |
||
| 264 | $exists = false; |
||
| 265 | foreach ($this->tweety->getFlightPartnerRefs() as $ref) { |
||
| 266 | if ($ref->equals($bird)) { |
||
| 267 | $exists = true; |
||
| 268 | break; |
||
| 269 | } |
||
| 270 | } |
||
| 271 | $this->assertTrue($exists); |
||
| 272 | } |
||
| 273 | } |
||
| 274 | |||
| 275 | public function testUpdateFlightPartnerRefElementsByRemoveElements(): void |
||
| 276 | { |
||
| 277 | $flightPartnerRefs = $this->tweety->getFlightPartnerRefElements(); |
||
| 278 | $this->tweety->removeFlightPartnerRefElement($flightPartnerRefs[1]); |
||
| 279 | $this->tweety->removeFlightPartnerRefElement($flightPartnerRefs[3]); |
||
| 280 | |||
| 281 | $this->assertCount(2, $this->tweety->getFlightPartnerRefs()); |
||
| 282 | $birds = [$this->hedwig, $this->plucky]; |
||
| 283 | foreach ($birds as $bird) { |
||
| 284 | $exists = false; |
||
| 285 | foreach ($this->tweety->getFlightPartnerRefs() as $ref) { |
||
| 286 | if ($ref->equals($bird)) { |
||
| 287 | $exists = true; |
||
| 288 | break; |
||
| 289 | } |
||
| 290 | } |
||
| 291 | $this->assertTrue($exists); |
||
| 292 | } |
||
| 293 | } |
||
| 294 | |||
| 295 | public function testClearFlightPartnerRefElements(): void |
||
| 303 | } |
||
| 304 | } |
||
| 305 |