| Total Complexity | 42 |
| Total Lines | 800 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ExtraLazyCollectionTest 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 ExtraLazyCollectionTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class ExtraLazyCollectionTest extends OrmFunctionalTestCase |
||
| 25 | { |
||
| 26 | private $userId; |
||
| 27 | private $userId2; |
||
| 28 | private $groupId; |
||
| 29 | private $articleId; |
||
| 30 | private $ddc2504OtherClassId; |
||
| 31 | private $ddc2504ChildClassId; |
||
| 32 | |||
| 33 | private $username; |
||
| 34 | private $groupname; |
||
| 35 | private $topic; |
||
| 36 | private $phonenumber; |
||
| 37 | |||
| 38 | public function setUp() |
||
| 39 | { |
||
| 40 | $this->useModelSet('tweet'); |
||
| 41 | $this->useModelSet('cms'); |
||
| 42 | $this->useModelSet('ddc2504'); |
||
| 43 | parent::setUp(); |
||
| 44 | |||
| 45 | $class = $this->_em->getClassMetadata(CmsUser::class); |
||
| 46 | $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; |
||
| 47 | $class->associationMappings['groups']['indexBy'] = 'name'; |
||
| 48 | $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; |
||
| 49 | $class->associationMappings['articles']['indexBy'] = 'topic'; |
||
| 50 | $class->associationMappings['phonenumbers']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; |
||
| 51 | $class->associationMappings['phonenumbers']['indexBy'] = 'phonenumber'; |
||
| 52 | |||
| 53 | unset($class->associationMappings['phonenumbers']['cache']); |
||
| 54 | unset($class->associationMappings['articles']['cache']); |
||
| 55 | unset($class->associationMappings['users']['cache']); |
||
| 56 | |||
| 57 | $class = $this->_em->getClassMetadata(CmsGroup::class); |
||
| 58 | $class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; |
||
| 59 | $class->associationMappings['users']['indexBy'] = 'username'; |
||
| 60 | |||
| 61 | $this->loadFixture(); |
||
| 62 | } |
||
| 63 | |||
| 64 | public function tearDown() |
||
| 65 | { |
||
| 66 | parent::tearDown(); |
||
| 67 | |||
| 68 | $class = $this->_em->getClassMetadata(CmsUser::class); |
||
| 69 | $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_LAZY; |
||
| 70 | $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY; |
||
| 71 | $class->associationMappings['phonenumbers']['fetch'] = ClassMetadataInfo::FETCH_LAZY; |
||
| 72 | |||
| 73 | unset($class->associationMappings['groups']['indexBy']); |
||
| 74 | unset($class->associationMappings['articles']['indexBy']); |
||
| 75 | unset($class->associationMappings['phonenumbers']['indexBy']); |
||
| 76 | |||
| 77 | $class = $this->_em->getClassMetadata(CmsGroup::class); |
||
| 78 | $class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_LAZY; |
||
| 79 | |||
| 80 | unset($class->associationMappings['users']['indexBy']); |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @group DDC-546 |
||
| 85 | * @group non-cacheable |
||
| 86 | */ |
||
| 87 | public function testCountNotInitializesCollection() |
||
| 88 | { |
||
| 89 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 90 | $queryCount = $this->getCurrentQueryCount(); |
||
| 91 | |||
| 92 | $this->assertFalse($user->groups->isInitialized()); |
||
|
|
|||
| 93 | $this->assertEquals(3, count($user->groups)); |
||
| 94 | $this->assertFalse($user->groups->isInitialized()); |
||
| 95 | |||
| 96 | foreach ($user->groups as $group) { |
||
| 97 | } |
||
| 98 | |||
| 99 | $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), 'Expecting two queries to be fired for count, then iteration.'); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @group DDC-546 |
||
| 104 | */ |
||
| 105 | public function testCountWhenNewEntityPresent() |
||
| 106 | { |
||
| 107 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 108 | |||
| 109 | $newGroup = new CmsGroup(); |
||
| 110 | $newGroup->name = 'Test4'; |
||
| 111 | |||
| 112 | $user->addGroup($newGroup); |
||
| 113 | $this->_em->persist($newGroup); |
||
| 114 | |||
| 115 | $this->assertFalse($user->groups->isInitialized()); |
||
| 116 | $this->assertEquals(4, count($user->groups)); |
||
| 117 | $this->assertFalse($user->groups->isInitialized()); |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @group DDC-546 |
||
| 122 | * @group non-cacheable |
||
| 123 | */ |
||
| 124 | public function testCountWhenInitialized() |
||
| 125 | { |
||
| 126 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 127 | $queryCount = $this->getCurrentQueryCount(); |
||
| 128 | |||
| 129 | foreach ($user->groups as $group) { |
||
| 130 | } |
||
| 131 | |||
| 132 | $this->assertTrue($user->groups->isInitialized()); |
||
| 133 | $this->assertEquals(3, count($user->groups)); |
||
| 134 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), 'Should only execute one query to initialize collection, no extra query for count() more.'); |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @group DDC-546 |
||
| 139 | */ |
||
| 140 | public function testCountInverseCollection() |
||
| 141 | { |
||
| 142 | $group = $this->_em->find(CmsGroup::class, $this->groupId); |
||
| 143 | $this->assertFalse($group->users->isInitialized(), 'Pre-Condition'); |
||
| 144 | |||
| 145 | $this->assertEquals(4, count($group->users)); |
||
| 146 | $this->assertFalse($group->users->isInitialized(), 'Extra Lazy collection should not be initialized by counting the collection.'); |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @group DDC-546 |
||
| 151 | */ |
||
| 152 | public function testCountOneToMany() |
||
| 153 | { |
||
| 154 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 155 | $this->assertFalse($user->groups->isInitialized(), 'Pre-Condition'); |
||
| 156 | |||
| 157 | $this->assertEquals(2, count($user->articles)); |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @group DDC-2504 |
||
| 162 | */ |
||
| 163 | public function testCountOneToManyJoinedInheritance() |
||
| 164 | { |
||
| 165 | $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); |
||
| 166 | |||
| 167 | $this->assertFalse($otherClass->childClasses->isInitialized(), 'Pre-Condition'); |
||
| 168 | $this->assertEquals(2, count($otherClass->childClasses)); |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @group DDC-546 |
||
| 173 | */ |
||
| 174 | public function testFullSlice() |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @group DDC-546 |
||
| 185 | * @group non-cacheable |
||
| 186 | */ |
||
| 187 | public function testSlice() |
||
| 188 | { |
||
| 189 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 190 | $this->assertFalse($user->groups->isInitialized(), 'Pre-Condition: Collection is not initialized.'); |
||
| 191 | |||
| 192 | $queryCount = $this->getCurrentQueryCount(); |
||
| 193 | |||
| 194 | $someGroups = $user->groups->slice(0, 2); |
||
| 195 | |||
| 196 | $this->assertContainsOnly(CmsGroup::class, $someGroups); |
||
| 197 | $this->assertEquals(2, count($someGroups)); |
||
| 198 | $this->assertFalse($user->groups->isInitialized(), "Slice should not initialize the collection if it wasn't before!"); |
||
| 199 | |||
| 200 | $otherGroup = $user->groups->slice(2, 1); |
||
| 201 | |||
| 202 | $this->assertContainsOnly(CmsGroup::class, $otherGroup); |
||
| 203 | $this->assertEquals(1, count($otherGroup)); |
||
| 204 | $this->assertFalse($user->groups->isInitialized()); |
||
| 205 | |||
| 206 | foreach ($user->groups as $group) { |
||
| 207 | } |
||
| 208 | |||
| 209 | $this->assertTrue($user->groups->isInitialized()); |
||
| 210 | $this->assertEquals(3, count($user->groups)); |
||
| 211 | |||
| 212 | $this->assertEquals($queryCount + 3, $this->getCurrentQueryCount()); |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @group DDC-546 |
||
| 217 | * @group non-cacheable |
||
| 218 | */ |
||
| 219 | public function testSliceInitializedCollection() |
||
| 220 | { |
||
| 221 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 222 | $queryCount = $this->getCurrentQueryCount(); |
||
| 223 | |||
| 224 | foreach ($user->groups as $group) { |
||
| 225 | } |
||
| 226 | |||
| 227 | $someGroups = $user->groups->slice(0, 2); |
||
| 228 | |||
| 229 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 230 | |||
| 231 | $this->assertEquals(2, count($someGroups)); |
||
| 232 | $this->assertTrue($user->groups->contains(array_shift($someGroups))); |
||
| 233 | $this->assertTrue($user->groups->contains(array_shift($someGroups))); |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @group DDC-546 |
||
| 238 | */ |
||
| 239 | public function testSliceInverseCollection() |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @group DDC-546 |
||
| 259 | */ |
||
| 260 | public function testSliceOneToMany() |
||
| 261 | { |
||
| 262 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 263 | $this->assertFalse($user->articles->isInitialized(), 'Pre-Condition: Collection is not initialized.'); |
||
| 264 | |||
| 265 | $queryCount = $this->getCurrentQueryCount(); |
||
| 266 | |||
| 267 | $someArticle = $user->articles->slice(0, 1); |
||
| 268 | $otherArticle = $user->articles->slice(1, 1); |
||
| 269 | |||
| 270 | $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @group DDC-546 |
||
| 275 | */ |
||
| 276 | public function testContainsOneToMany() |
||
| 277 | { |
||
| 278 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 279 | $this->assertFalse($user->articles->isInitialized(), 'Pre-Condition: Collection is not initialized.'); |
||
| 280 | |||
| 281 | // Test One to Many existence retrieved from DB |
||
| 282 | $article = $this->_em->find(CmsArticle::class, $this->articleId); |
||
| 283 | $queryCount = $this->getCurrentQueryCount(); |
||
| 284 | |||
| 285 | $this->assertTrue($user->articles->contains($article)); |
||
| 286 | $this->assertFalse($user->articles->isInitialized(), 'Post-Condition: Collection is not initialized.'); |
||
| 287 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 288 | |||
| 289 | // Test One to Many existence with state new |
||
| 290 | $article = new CmsArticle(); |
||
| 291 | $article->topic = 'Testnew'; |
||
| 292 | $article->text = 'blub'; |
||
| 293 | |||
| 294 | $queryCount = $this->getCurrentQueryCount(); |
||
| 295 | $this->assertFalse($user->articles->contains($article)); |
||
| 296 | $this->assertEquals($queryCount, $this->getCurrentQueryCount(), 'Checking for contains of new entity should cause no query to be executed.'); |
||
| 297 | |||
| 298 | // Test One to Many existence with state clear |
||
| 299 | $this->_em->persist($article); |
||
| 300 | $this->_em->flush(); |
||
| 301 | |||
| 302 | $queryCount = $this->getCurrentQueryCount(); |
||
| 303 | $this->assertFalse($user->articles->contains($article)); |
||
| 304 | $this->assertEquals($queryCount+1, $this->getCurrentQueryCount(), 'Checking for contains of persisted entity should cause one query to be executed.'); |
||
| 305 | $this->assertFalse($user->articles->isInitialized(), 'Post-Condition: Collection is not initialized.'); |
||
| 306 | |||
| 307 | // Test One to Many existence with state managed |
||
| 308 | $article = new CmsArticle(); |
||
| 309 | $article->topic = 'How to not fail anymore on tests'; |
||
| 310 | $article->text = 'That is simple! Just write more tests!'; |
||
| 311 | |||
| 312 | $this->_em->persist($article); |
||
| 313 | |||
| 314 | $queryCount = $this->getCurrentQueryCount(); |
||
| 315 | |||
| 316 | $this->assertFalse($user->articles->contains($article)); |
||
| 317 | $this->assertEquals($queryCount, $this->getCurrentQueryCount(), 'Checking for contains of managed entity (but not persisted) should cause no query to be executed.'); |
||
| 318 | $this->assertFalse($user->articles->isInitialized(), 'Post-Condition: Collection is not initialized.'); |
||
| 319 | } |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @group DDC-2504 |
||
| 323 | */ |
||
| 324 | public function testLazyOneToManyJoinedInheritanceIsLazilyInitialized() |
||
| 325 | { |
||
| 326 | $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); |
||
| 327 | |||
| 328 | $this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.'); |
||
| 329 | } |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @group DDC-2504 |
||
| 333 | */ |
||
| 334 | public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWhenMatchingItemIsFound() |
||
| 335 | { |
||
| 336 | $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); |
||
| 337 | |||
| 338 | // Test One to Many existence retrieved from DB |
||
| 339 | $childClass = $this->_em->find(DDC2504ChildClass::class, $this->ddc2504ChildClassId); |
||
| 340 | $queryCount = $this->getCurrentQueryCount(); |
||
| 341 | |||
| 342 | $this->assertTrue($otherClass->childClasses->contains($childClass)); |
||
| 343 | $this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.'); |
||
| 344 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), 'Search operation was performed via SQL'); |
||
| 345 | } |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @group DDC-2504 |
||
| 349 | */ |
||
| 350 | public function testContainsOnOneToManyJoinedInheritanceWillNotCauseQueriesWhenNonPersistentItemIsMatched() |
||
| 351 | { |
||
| 352 | $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); |
||
| 353 | $queryCount = $this->getCurrentQueryCount(); |
||
| 354 | |||
| 355 | $this->assertFalse($otherClass->childClasses->contains(new DDC2504ChildClass())); |
||
| 356 | $this->assertEquals( |
||
| 357 | $queryCount, |
||
| 358 | $this->getCurrentQueryCount(), |
||
| 359 | 'Checking for contains of new entity should cause no query to be executed.' |
||
| 360 | ); |
||
| 361 | } |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @group DDC-2504 |
||
| 365 | */ |
||
| 366 | public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWithClearStateMatchingItem() |
||
| 367 | { |
||
| 368 | $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); |
||
| 369 | $childClass = new DDC2504ChildClass(); |
||
| 370 | |||
| 371 | // Test One to Many existence with state clear |
||
| 372 | $this->_em->persist($childClass); |
||
| 373 | $this->_em->flush(); |
||
| 374 | |||
| 375 | $queryCount = $this->getCurrentQueryCount(); |
||
| 376 | $this->assertFalse($otherClass->childClasses->contains($childClass)); |
||
| 377 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), 'Checking for contains of persisted entity should cause one query to be executed.'); |
||
| 378 | $this->assertFalse($otherClass->childClasses->isInitialized(), 'Post-Condition: Collection is not initialized.'); |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @group DDC-2504 |
||
| 383 | */ |
||
| 384 | public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWithNewStateNotMatchingItem() |
||
| 385 | { |
||
| 386 | $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); |
||
| 387 | $childClass = new DDC2504ChildClass(); |
||
| 388 | |||
| 389 | $this->_em->persist($childClass); |
||
| 390 | |||
| 391 | $queryCount = $this->getCurrentQueryCount(); |
||
| 392 | |||
| 393 | $this->assertFalse($otherClass->childClasses->contains($childClass)); |
||
| 394 | $this->assertEquals($queryCount, $this->getCurrentQueryCount(), 'Checking for contains of managed entity (but not persisted) should cause no query to be executed.'); |
||
| 395 | $this->assertFalse($otherClass->childClasses->isInitialized(), 'Post-Condition: Collection is not initialized.'); |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @group DDC-2504 |
||
| 400 | */ |
||
| 401 | public function testCountingOnOneToManyJoinedInheritanceWillNotInitializeCollection() |
||
| 402 | { |
||
| 403 | $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); |
||
| 404 | |||
| 405 | $this->assertEquals(2, count($otherClass->childClasses)); |
||
| 406 | |||
| 407 | $this->assertFalse($otherClass->childClasses->isInitialized()); |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @group DDC-546 |
||
| 412 | */ |
||
| 413 | public function testContainsManyToMany() |
||
| 457 | } |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @group DDC-546 |
||
| 461 | */ |
||
| 462 | public function testContainsManyToManyInverse() |
||
| 463 | { |
||
| 464 | $group = $this->_em->find(CmsGroup::class, $this->groupId); |
||
| 465 | $this->assertFalse($group->users->isInitialized(), 'Pre-Condition: Collection is not initialized.'); |
||
| 466 | |||
| 467 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 468 | |||
| 469 | $queryCount = $this->getCurrentQueryCount(); |
||
| 481 | } |
||
| 482 | |||
| 483 | /** |
||
| 484 | * @group DDC-1399 |
||
| 485 | */ |
||
| 486 | public function testCountAfterAddThenFlush() |
||
| 487 | { |
||
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @group DDC-1462 |
||
| 507 | * @group non-cacheable |
||
| 508 | */ |
||
| 509 | public function testSliceOnDirtyCollection() |
||
| 510 | { |
||
| 511 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 512 | /** @var CmsUser $user */ |
||
| 513 | |||
| 514 | $newGroup = new CmsGroup(); |
||
| 515 | $newGroup->name = 'Test4'; |
||
| 516 | |||
| 517 | $user->addGroup($newGroup); |
||
| 518 | $this->_em->persist($newGroup); |
||
| 519 | |||
| 520 | $qc = $this->getCurrentQueryCount(); |
||
| 521 | $groups = $user->groups->slice(0, 10); |
||
| 522 | |||
| 523 | $this->assertEquals(4, count($groups)); |
||
| 524 | $this->assertEquals($qc + 1, $this->getCurrentQueryCount()); |
||
| 525 | } |
||
| 526 | |||
| 527 | /** |
||
| 528 | * @group DDC-1398 |
||
| 529 | * @group non-cacheable |
||
| 530 | */ |
||
| 531 | public function testGetIndexByIdentifier() |
||
| 532 | { |
||
| 533 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 534 | /** @var CmsUser $user */ |
||
| 535 | |||
| 536 | $queryCount = $this->getCurrentQueryCount(); |
||
| 537 | $phonenumber = $user->phonenumbers->get($this->phonenumber); |
||
| 538 | |||
| 539 | $this->assertFalse($user->phonenumbers->isInitialized()); |
||
| 540 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 541 | $this->assertSame($phonenumber, $this->_em->find(CmsPhonenumber::class, $this->phonenumber)); |
||
| 542 | |||
| 543 | $article = $user->phonenumbers->get($this->phonenumber); |
||
| 544 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), 'Getting the same entity should not cause an extra query to be executed'); |
||
| 545 | } |
||
| 546 | |||
| 547 | /** |
||
| 548 | * @group DDC-1398 |
||
| 549 | */ |
||
| 550 | public function testGetIndexByOneToMany() |
||
| 551 | { |
||
| 552 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 553 | /** @var CmsUser $user */ |
||
| 554 | |||
| 555 | $queryCount = $this->getCurrentQueryCount(); |
||
| 556 | |||
| 557 | $article = $user->articles->get($this->topic); |
||
| 558 | |||
| 559 | $this->assertFalse($user->articles->isInitialized()); |
||
| 560 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 561 | $this->assertSame($article, $this->_em->find(CmsArticle::class, $this->articleId)); |
||
| 562 | } |
||
| 563 | |||
| 564 | /** |
||
| 565 | * @group DDC-1398 |
||
| 566 | */ |
||
| 567 | public function testGetIndexByManyToManyInverseSide() |
||
| 579 | } |
||
| 580 | |||
| 581 | /** |
||
| 582 | * @group DDC-1398 |
||
| 583 | */ |
||
| 584 | public function testGetIndexByManyToManyOwningSide() |
||
| 585 | { |
||
| 586 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 587 | /** @var CmsUser $user */ |
||
| 588 | |||
| 589 | $queryCount = $this->getCurrentQueryCount(); |
||
| 590 | |||
| 591 | $group = $user->groups->get($this->groupname); |
||
| 592 | |||
| 593 | $this->assertFalse($user->groups->isInitialized()); |
||
| 594 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 595 | $this->assertSame($group, $this->_em->find(CmsGroup::class, $this->groupId)); |
||
| 596 | } |
||
| 597 | |||
| 598 | /** |
||
| 599 | * @group DDC-1398 |
||
| 600 | */ |
||
| 601 | public function testGetNonExistentIndexBy() |
||
| 602 | { |
||
| 603 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 604 | $this->assertNull($user->articles->get(-1)); |
||
| 605 | $this->assertNull($user->groups->get(-1)); |
||
| 606 | } |
||
| 607 | |||
| 608 | public function testContainsKeyIndexByOneToMany() |
||
| 609 | { |
||
| 610 | $user = $this->_em->find(CmsUser::class, $this->userId); |
||
| 611 | /** @var CmsUser $user */ |
||
| 612 | |||
| 613 | $queryCount = $this->getCurrentQueryCount(); |
||
| 614 | |||
| 615 | $contains = $user->articles->containsKey($this->topic); |
||
| 616 | |||
| 617 | $this->assertTrue($contains); |
||
| 618 | $this->assertFalse($user->articles->isInitialized()); |
||
| 619 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 620 | } |
||
| 621 | |||
| 622 | public function testContainsKeyIndexByOneToManyJoinedInheritance() |
||
| 623 | { |
||
| 624 | $class = $this->_em->getClassMetadata(DDC2504OtherClass::class); |
||
| 625 | $class->associationMappings['childClasses']['indexBy'] = 'id'; |
||
| 626 | |||
| 627 | $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); |
||
| 628 | |||
| 629 | $queryCount = $this->getCurrentQueryCount(); |
||
| 630 | |||
| 631 | $contains = $otherClass->childClasses->containsKey($this->ddc2504ChildClassId); |
||
| 632 | |||
| 633 | $this->assertTrue($contains); |
||
| 634 | $this->assertFalse($otherClass->childClasses->isInitialized()); |
||
| 635 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 636 | } |
||
| 637 | |||
| 638 | public function testContainsKeyIndexByManyToMany() |
||
| 639 | { |
||
| 640 | $user = $this->_em->find(CmsUser::class, $this->userId2); |
||
| 641 | |||
| 642 | $group = $this->_em->find(CmsGroup::class, $this->groupId); |
||
| 643 | |||
| 644 | $queryCount = $this->getCurrentQueryCount(); |
||
| 645 | |||
| 646 | $contains = $user->groups->containsKey($group->name); |
||
| 647 | |||
| 648 | $this->assertTrue($contains, 'The item is not into collection'); |
||
| 649 | $this->assertFalse($user->groups->isInitialized(), 'The collection must not be initialized'); |
||
| 650 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 651 | } |
||
| 652 | public function testContainsKeyIndexByManyToManyNonOwning() |
||
| 664 | } |
||
| 665 | |||
| 666 | public function testContainsKeyIndexByWithPkManyToMany() |
||
| 667 | { |
||
| 668 | $class = $this->_em->getClassMetadata(CmsUser::class); |
||
| 669 | $class->associationMappings['groups']['indexBy'] = 'id'; |
||
| 670 | |||
| 671 | $user = $this->_em->find(CmsUser::class, $this->userId2); |
||
| 672 | |||
| 673 | $queryCount = $this->getCurrentQueryCount(); |
||
| 674 | |||
| 675 | $contains = $user->groups->containsKey($this->groupId); |
||
| 676 | |||
| 677 | $this->assertTrue($contains, 'The item is not into collection'); |
||
| 678 | $this->assertFalse($user->groups->isInitialized(), 'The collection must not be initialized'); |
||
| 679 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 680 | } |
||
| 681 | public function testContainsKeyIndexByWithPkManyToManyNonOwning() |
||
| 695 | } |
||
| 696 | |||
| 697 | public function testContainsKeyNonExistentIndexByOneToMany() |
||
| 698 | { |
||
| 699 | $user = $this->_em->find(CmsUser::class, $this->userId2); |
||
| 700 | |||
| 701 | $queryCount = $this->getCurrentQueryCount(); |
||
| 702 | |||
| 703 | $contains = $user->articles->containsKey('NonExistentTopic'); |
||
| 704 | |||
| 705 | $this->assertFalse($contains); |
||
| 706 | $this->assertFalse($user->articles->isInitialized()); |
||
| 707 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 708 | } |
||
| 709 | |||
| 710 | public function testContainsKeyNonExistentIndexByManyToMany() |
||
| 711 | { |
||
| 712 | $user = $this->_em->find(CmsUser::class, $this->userId2); |
||
| 713 | |||
| 714 | $queryCount = $this->getCurrentQueryCount(); |
||
| 715 | |||
| 716 | $contains = $user->groups->containsKey('NonExistentTopic'); |
||
| 717 | |||
| 718 | $this->assertFalse($contains); |
||
| 719 | $this->assertFalse($user->groups->isInitialized()); |
||
| 720 | $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
||
| 721 | } |
||
| 722 | |||
| 723 | private function loadFixture() |
||
| 824 | } |
||
| 825 | } |
||
| 826 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.