diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionsTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionsTest.php index c027e0f5dd..554b67d2e4 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionsTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionsTest.php @@ -22,7 +22,7 @@ public function testCollections() $this->dm->flush(); $this->dm->clear(); - $bar = $this->dm->find('Documents\Bars\Bar', $bar->getId()); + $bar = $this->dm->find(Bar::class, $bar->getId()); $this->assertNotNull($bar); $locations = $bar->getLocations(); @@ -31,10 +31,10 @@ public function testCollections() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getDocumentCollection('Documents\Bars\Bar')->findOne(); + $test = $this->dm->getDocumentCollection(Bar::class)->findOne(); $this->assertCount(2, $test['locations']); - $bar = $this->dm->find('Documents\Bars\Bar', $bar->getId()); + $bar = $this->dm->find(Bar::class, $bar->getId()); $this->assertNotNull($bar); $locations = $bar->getLocations(); $this->assertCount(2, $locations); @@ -44,7 +44,7 @@ public function testCollections() $this->dm->flush(); $this->dm->clear(); - $bar = $this->dm->find('Documents\Bars\Bar', $bar->getId()); + $bar = $this->dm->find(Bar::class, $bar->getId()); $this->assertNotNull($bar); $locations = $bar->getLocations(); $this->assertCount(0, $locations); @@ -55,7 +55,7 @@ public function testCollections() $this->dm->flush(); $this->dm->clear(); - $bar = $this->dm->find('Documents\Bars\Bar', $bar->getId()); + $bar = $this->dm->find(Bar::class, $bar->getId()); $this->assertEquals($bar->getId(), $this->dm->getUnitOfWork()->getDocumentIdentifier($bar)); $this->assertNotNull($bar); @@ -66,7 +66,7 @@ public function testCollections() $this->assertCount(0, $locations); $this->dm->flush(); $this->dm->clear(); - $bar = $this->dm->find('Documents\Bars\Bar', $bar->getId()); + $bar = $this->dm->find(Bar::class, $bar->getId()); $locations = $bar->getLocations(); $this->assertCount(0, $locations); $this->dm->flush(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php index 2303452bda..1f4ecfc121 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php @@ -32,7 +32,7 @@ public function testSetId() $this->dm->clear(); - $user = $this->dm->find('Documents\CustomUser', $user->getId()); + $user = $this->dm->find(CustomUser::class, $user->getId()); $this->assertNotNull($user); @@ -41,7 +41,7 @@ public function testSetId() $this->dm->clear(); unset($user); - $user = $this->dm->find('Documents\CustomUser', 'userId'); + $user = $this->dm->find(CustomUser::class, 'userId'); $this->assertNotNull($user); @@ -78,7 +78,7 @@ public function testBatchInsertCustomId() unset($user1, $user2, $user3); - $users = $this->dm->getRepository('Documents\User')->findAll(); + $users = $this->dm->getRepository(User::class)->findAll(); $this->assertCount(2, $users); @@ -91,7 +91,7 @@ public function testBatchInsertCustomId() $results['ids'][] = $user->getId(); } - $users = $this->dm->getRepository('Documents\CustomUser')->findAll(); + $users = $this->dm->getRepository(CustomUser::class)->findAll(); $this->assertCount(1, $users); @@ -137,7 +137,7 @@ public function testFindUser() unset($user1, $user2, $user3); - $user = $this->dm->find('Documents\CustomUser', 'userId'); + $user = $this->dm->find(CustomUser::class, 'userId'); $this->assertNotNull($user); $this->assertEquals('userId', $user->getId()); @@ -146,7 +146,7 @@ public function testFindUser() $this->dm->clear(); unset($user); - $this->assertNull($this->dm->find('Documents\User', 'userId')); - $this->assertNull($this->dm->find('Documents\CustomUser', 'asd')); + $this->assertNull($this->dm->find(User::class, 'userId')); + $this->assertNull($this->dm->find(CustomUser::class, 'asd')); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php index a243f19284..a24207981a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php @@ -26,7 +26,7 @@ public function testDates() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'w00ting']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'w00ting']); $this->assertNotNull($user); $this->assertEquals('w00ting', $user->getUsername()); $this->assertInstanceOf(\DateTime::class, $user->getCreatedAt()); @@ -96,10 +96,10 @@ public function testOldDate() $this->dm->clear(); - $test = $this->dm->getDocumentCollection('Documents\User')->findOne(['username' => 'datetest2']); + $test = $this->dm->getDocumentCollection(User::class)->findOne(['username' => 'datetest2']); $this->assertArrayHasKey('createdAt', $test); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'datetest2']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'datetest2']); $this->assertInstanceOf(\DateTime::class, $user->getCreatedAt()); $this->assertEquals('1900-01-01', $user->getCreatedAt()->format('Y-m-d')); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php index 6557700255..159fc0bf1f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php @@ -48,7 +48,7 @@ public function testEmbedding() $this->assertCount(3, $product->getOptions()); $this->assertEquals(12.99, $product->getOption('small')->getPrice()); - $usdCurrency = $this->dm->getRepository('Documents\Ecommerce\Currency')->findOneBy(['name' => 'USD']); + $usdCurrency = $this->dm->getRepository(Currency::class)->findOneBy(['name' => 'USD']); $this->assertNotNull($usdCurrency); $usdCurrency->setMultiplier('2'); @@ -64,7 +64,7 @@ public function testMoneyDocumentsAvailableForReference() $currency = $price->getCurrency(); $this->assertInstanceOf(Currency::class, $currency); $this->assertNotNull($currency->getId()); - $this->assertEquals($currency, $this->dm->getRepository('Documents\Ecommerce\Currency')->findOneBy(['name' => Currency::USD])); + $this->assertEquals($currency, $this->dm->getRepository(Currency::class)->findOneBy(['name' => Currency::USD])); } public function testRemoveOption() @@ -85,7 +85,7 @@ public function testRemoveOption() protected function getProduct() { - $products = $this->dm->getRepository('Documents\Ecommerce\ConfigurableProduct') + $products = $this->dm->getRepository(ConfigurableProduct::class) ->createQueryBuilder() ->getQuery() ->execute(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php index dc3ae2363b..0fd7a60cdf 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php @@ -35,7 +35,7 @@ public function testSetEmbeddedToNull() $this->dm->clear(); $userId = $user->getId(); - $user = $this->dm->getRepository('Documents\User')->find($userId); + $user = $this->dm->getRepository(User::class)->find($userId); $this->assertEquals($userId, $user->getId()); $this->assertNull($user->getAddress()); } @@ -49,8 +49,8 @@ public function testFlushEmbedded() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getRepository('Documents\Functional\EmbeddedTestLevel0')->findOneBy(['name' => 'test']); - $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test); + $test = $this->dm->getRepository(EmbeddedTestLevel0::class)->findOneBy(['name' => 'test']); + $this->assertInstanceOf(EmbeddedTestLevel0::class, $test); // Adding this flush here makes level1 not to be inserted. $this->dm->flush(); @@ -62,9 +62,9 @@ public function testFlushEmbedded() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->find('Documents\Functional\EmbeddedTestLevel0', $test->id); - $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test); - $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel1', $test->level1[0]); + $test = $this->dm->find(EmbeddedTestLevel0::class, $test->id); + $this->assertInstanceOf(EmbeddedTestLevel0::class, $test); + $this->assertInstanceOf(EmbeddedTestLevel1::class, $test->level1[0]); $test->level1[0]->name = 'changed'; $level1 = new EmbeddedTestLevel1(); @@ -73,7 +73,7 @@ public function testFlushEmbedded() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->find('Documents\Functional\EmbeddedTestLevel0', $test->id); + $test = $this->dm->find(EmbeddedTestLevel0::class, $test->id); $this->assertCount(2, $test->level1); $this->assertEquals('changed', $test->level1[0]->name); $this->assertEquals('testing', $test->level1[1]->name); @@ -106,7 +106,7 @@ public function testOneEmbedded() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->createQueryBuilder('Documents\User') + $user = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()) ->getQuery() ->getSingleResult(); @@ -142,7 +142,7 @@ public function testRemoveOneEmbedded() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->createQueryBuilder('Documents\User') + $user = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()) ->getQuery() ->getSingleResult(); @@ -160,7 +160,7 @@ public function testManyEmbedded() $this->dm->flush(); $this->dm->clear(); - $user2 = $this->dm->createQueryBuilder('Documents\User') + $user2 = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()) ->getQuery() ->getSingleResult(); @@ -382,7 +382,7 @@ public function testEmbeddedDocumentChangesParent() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertNotNull($user); $address = $user->getAddress(); $address->setAddress('changed'); @@ -390,7 +390,7 @@ public function testEmbeddedDocumentChangesParent() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertEquals('changed', $user->getAddress()->getAddress()); } @@ -414,7 +414,7 @@ public function testRemoveEmbeddedDocument() $this->dm->flush(); - $check = $this->dm->getDocumentCollection('Documents\User')->findOne(); + $check = $this->dm->getDocumentCollection(User::class)->findOne(); $this->assertEmpty($check['phonenumbers']); $this->assertArrayNotHasKey('address', $check); } @@ -446,7 +446,7 @@ public function testRemoveAddDeepEmbedded() $this->dm->flush(); $this->dm->clear(); - $vhost = $this->dm->find('Documents\Functional\VirtualHost', $vhost->getId()); + $vhost = $this->dm->find(VirtualHost::class, $vhost->getId()); foreach ($vhost->getVHostDirective()->getDirectives() as $directive) { $this->assertNotEmpty($directive->getName()); @@ -464,7 +464,7 @@ public function testEmbeddedDocumentNotSavedFields() $this->dm->flush(); $this->dm->clear(); - $document = $this->dm->find('Documents\Functional\NotSaved', $document->id); + $document = $this->dm->find(NotSaved::class, $document->id); $this->assertEquals('foo', $document->embedded->name); $this->assertNull($document->embedded->notSaved); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php index 568ed60a98..f1fccf9acb 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php @@ -51,7 +51,7 @@ protected function enableUserFilter() { $this->fc->enable('testFilter'); $testFilter = $this->fc->getFilter('testFilter'); - $testFilter->setParameter('class', 'Documents\User'); + $testFilter->setParameter('class', User::class); $testFilter->setParameter('field', 'username'); $testFilter->setParameter('value', 'Tim'); } @@ -60,7 +60,7 @@ protected function enableGroupFilter() { $this->fc->enable('testFilter'); $testFilter = $this->fc->getFilter('testFilter'); - $testFilter->setParameter('class', 'Documents\Group'); + $testFilter->setParameter('class', Group::class); $testFilter->setParameter('field', 'name'); $testFilter->setParameter('value', 'groupA'); } @@ -69,7 +69,7 @@ protected function enableProfileFilter() { $this->fc->enable('testFilter'); $testFilter = $this->fc->getFilter('testFilter'); - $testFilter->setParameter('class', 'Documents\Profile'); + $testFilter->setParameter('class', Profile::class); $testFilter->setParameter('field', 'firstname'); $testFilter->setParameter('value', 'Something Else'); } @@ -89,7 +89,7 @@ public function testRepositoryFind() protected function getUsernamesWithFind() { - $repository = $this->dm->getRepository('Documents\User'); + $repository = $this->dm->getRepository(User::class); $tim = $repository->find($this->ids['tim']); $john = $repository->find($this->ids['john']); @@ -122,7 +122,7 @@ public function testRepositoryFindBy() protected function getUsernamesWithFindBy() { - $all = $this->dm->getRepository('Documents\User')->findBy(['hits' => 10]); + $all = $this->dm->getRepository(User::class)->findBy(['hits' => 10]); $usernames = []; foreach ($all as $user) { @@ -147,7 +147,7 @@ public function testRepositoryFindOneBy() protected function getJohnsUsernameWithFindOneBy() { - $john = $this->dm->getRepository('Documents\User')->findOneBy(['id' => $this->ids['john']]); + $john = $this->dm->getRepository(User::class)->findOneBy(['id' => $this->ids['john']]); return isset($john) ? $john->getUsername() : null; } @@ -167,7 +167,7 @@ public function testRepositoryFindAll() protected function getUsernamesWithFindAll() { - $all = $this->dm->getRepository('Documents\User')->findAll(); + $all = $this->dm->getRepository(User::class)->findAll(); $usernames = []; foreach ($all as $user) { @@ -192,7 +192,7 @@ public function testReferenceMany() protected function getGroupsByReference() { - $tim = $this->dm->getRepository('Documents\User')->find($this->ids['tim']); + $tim = $this->dm->getRepository(User::class)->find($this->ids['tim']); $groupnames = []; foreach ($tim->getGroups() as $group) { @@ -221,7 +221,7 @@ public function testReferenceOne() protected function getProfileByReference() { - $tim = $this->dm->getRepository('Documents\User')->find($this->ids['tim']); + $tim = $this->dm->getRepository(User::class)->find($this->ids['tim']); $profile = $tim->getProfile(); try { @@ -247,8 +247,8 @@ public function testDocumentManagerRef() protected function getUsernamesWithDocumentManager() { - $tim = $this->dm->getReference('Documents\User', $this->ids['tim']); - $john = $this->dm->getReference('Documents\User', $this->ids['john']); + $tim = $this->dm->getReference(User::class, $this->ids['tim']); + $john = $this->dm->getReference(User::class, $this->ids['john']); $usernames = []; @@ -283,7 +283,7 @@ public function testQuery() protected function getUsernamesWithQuery() { - $qb = $this->dm->createQueryBuilder('Documents\User'); + $qb = $this->dm->createQueryBuilder(User::class); $query = $qb->getQuery(); $all = $query->execute(); @@ -299,13 +299,13 @@ public function testMultipleFiltersOnSameField() { $this->fc->enable('testFilter'); $testFilter = $this->fc->getFilter('testFilter'); - $testFilter->setParameter('class', 'Documents\User'); + $testFilter->setParameter('class', User::class); $testFilter->setParameter('field', 'username'); $testFilter->setParameter('value', 'Tim'); $this->fc->enable('testFilter2'); $testFilter2 = $this->fc->getFilter('testFilter2'); - $testFilter2->setParameter('class', 'Documents\User'); + $testFilter2->setParameter('class', User::class); $testFilter2->setParameter('field', 'username'); $testFilter2->setParameter('value', 'John'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FindAndModifyTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FindAndModifyTest.php index cfa99daa89..6d45208ddf 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FindAndModifyTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FindAndModifyTest.php @@ -11,13 +11,13 @@ class FindAndModifyTest extends BaseTest { public function testFindAndModify() { - $coll = $this->dm->getDocumentCollection('Documents\User'); + $coll = $this->dm->getDocumentCollection(User::class); $docs = [['count' => 0], ['count' => 0]]; $coll->insertMany($docs); // test update findAndModify $q = $this->dm->createQueryBuilder() - ->findAndUpdate('Documents\User') + ->findAndUpdate(User::class) ->returnNew(true) ->field('count')->inc(5) ->field('username')->set('jwage') @@ -30,7 +30,7 @@ public function testFindAndModify() // Test remove findAndModify $q = $this->dm->createQueryBuilder() - ->findAndRemove('Documents\User') + ->findAndRemove(User::class) ->field('username')->equals('jwage') ->getQuery(); $result = $q->execute(); @@ -52,7 +52,7 @@ public function testFindAndModifyAlt() // test update findAndModify $q = $this->dm->createQueryBuilder() - ->findAndUpdate('Documents\User') + ->findAndUpdate(User::class) ->returnNew(true) ->field('username')->equals('jwage') ->field('username')->set('Romain Neutron') diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FunctionalTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FunctionalTest.php index 1582d28233..891cea9e95 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FunctionalTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FunctionalTest.php @@ -29,14 +29,19 @@ use Documents\Functional\SameCollection1; use Documents\Functional\SameCollection2; use Documents\Functional\SameCollection3; +use Documents\Functional\SimpleEmbedAndReference; use Documents\Group; use Documents\GuestServer; use Documents\Manager; use Documents\Phonenumber; +use Documents\Profile; use Documents\Project; use Documents\Song; use Documents\SubCategory; use Documents\User; +use Documents\UserUpsert; +use Documents\UserUpsertChild; +use Documents\UserUpsertIdStrategyNone; use MongoDB\BSON\ObjectId; class FunctionalTest extends BaseTest @@ -44,9 +49,9 @@ class FunctionalTest extends BaseTest public function provideUpsertObjects() { return [ - ['Documents\\UserUpsert', new ObjectId('4f18f593acee41d724000005'), 'user'], - ['Documents\\UserUpsertIdStrategyNone', 'jwage', 'user'], - ['Documents\\UserUpsertChild', new ObjectId('4f18f593acee41d724000005'), 'child'], + [UserUpsert::class, new ObjectId('4f18f593acee41d724000005'), 'user'], + [UserUpsertIdStrategyNone::class, 'jwage', 'user'], + [UserUpsertChild::class, new ObjectId('4f18f593acee41d724000005'), 'child'], ]; } @@ -116,7 +121,7 @@ public function testUpsertObject($className, $id, $discriminator) public function testInheritedAssociationMappings() { - $class = $this->dm->getClassMetadata('Documents\UserUpsertChild'); + $class = $this->dm->getClassMetadata(UserUpsertChild::class); $this->assertTrue(isset($class->associationMappings['groups'])); } @@ -136,7 +141,7 @@ public function testNestedCategories() $root->setName('Root Changed'); $this->dm->flush(); - $test = $this->dm->getDocumentCollection('Documents\Category')->findOne(); + $test = $this->dm->getDocumentCollection(Category::class)->findOne(); $this->assertEquals('Child 1 Changed', $test['children'][0]['name']); $this->assertEquals('Child 2 Changed', $test['children'][0]['children'][0]['name']); $this->assertEquals('Root Changed', $test['name']); @@ -156,7 +161,7 @@ public function testManyEmbedded() $songs->add(new Song('Song #3')); $this->dm->flush(); - $test = $this->dm->getDocumentCollection('Documents\Album')->findOne(['name' => 'Jon']); + $test = $this->dm->getDocumentCollection(Album::class)->findOne(['name' => 'Jon']); $this->assertEquals('Song #1 Changed', $test['songs'][0]['name']); $album->setName('jwage'); @@ -166,7 +171,7 @@ public function testManyEmbedded() unset($songs[0]); $this->dm->flush(); - $test = $this->dm->getDocumentCollection('Documents\Album')->findOne(['name' => 'jwage']); + $test = $this->dm->getDocumentCollection(Album::class)->findOne(['name' => 'jwage']); $this->assertEquals('jwage', $test['name']); $this->assertEquals('ok', $test['songs'][0]['name']); @@ -179,7 +184,7 @@ public function testManyEmbedded() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getDocumentCollection('Documents\Album')->findOne(['name' => 'jwage']); + $test = $this->dm->getDocumentCollection(Album::class)->findOne(['name' => 'jwage']); $this->assertFalse(isset($test['songs'])); } @@ -201,7 +206,7 @@ public function testNewEmbedded() $subAddress->setCity('New Sub-City'); $this->dm->flush(); - $test = $this->dm->getDocumentCollection('Documents\Project')->findOne(['name' => 'Project']); + $test = $this->dm->getDocumentCollection(Project::class)->findOne(['name' => 'Project']); $this->assertEquals('New Sub-City', $test['address']['subAddress']['city']); $this->assertEquals('New City', $test['address']['city']); @@ -217,7 +222,7 @@ public function testPersistingNewDocumentWithOnlyOneReference() $this->dm->clear(); - $server = $this->dm->getReference('Documents\GuestServer', $id); + $server = $this->dm->getReference(GuestServer::class, $id); $agent = new Agent(); $agent->server = $server; @@ -225,7 +230,7 @@ public function testPersistingNewDocumentWithOnlyOneReference() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getDocumentCollection('Documents\Agent')->findOne(); + $test = $this->dm->getDocumentCollection(Agent::class)->findOne(); $this->assertEquals('servers', $test['server']['$ref']); $this->assertTrue(isset($test['server']['$id'])); @@ -242,23 +247,23 @@ public function testCollection() $this->dm->flush(); $this->dm->clear(); - $coll = $this->dm->getDocumentCollection('Documents\User'); + $coll = $this->dm->getDocumentCollection(User::class); $document = $coll->findOne(['username' => 'joncolltest']); $this->assertCount(2, $document['logs']); - $document = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'joncolltest']); + $document = $this->dm->getRepository(User::class)->findOneBy(['username' => 'joncolltest']); $this->assertCount(2, $document->getLogs()); $document->log(['test']); $this->dm->flush(); $this->dm->clear(); - $document = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'joncolltest']); + $document = $this->dm->getRepository(User::class)->findOneBy(['username' => 'joncolltest']); $this->assertCount(3, $document->getLogs()); $document->setLogs(['ok', 'test']); $this->dm->flush(); $this->dm->clear(); - $document = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'joncolltest']); + $document = $this->dm->getRepository(User::class)->findOneBy(['username' => 'joncolltest']); $this->assertEquals(['ok', 'test'], $document->getLogs()); } @@ -272,7 +277,7 @@ public function testSameObjectValuesInCollection() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'testing']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'testing']); $this->assertCount(2, $user->getPhonenumbers()); } @@ -287,14 +292,14 @@ public function testIncrement() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $user->incrementCount(5); $user->incrementFloatCount(5); $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $this->assertSame(105, $user->getCount()); $this->assertSame(105.0, $user->getFloatCount()); @@ -303,7 +308,7 @@ public function testIncrement() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $this->assertSame(50, $user->getCount()); $this->assertSame(50.0, $user->getFloatCount()); } @@ -319,14 +324,14 @@ public function testIncrementWithFloat() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $user->incrementCount(1.337); $user->incrementFloatCount(1.337); $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $this->assertSame(101, $user->getCount()); $this->assertSame(101.337, $user->getFloatCount()); @@ -335,7 +340,7 @@ public function testIncrementWithFloat() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $this->assertSame(110, $user->getCount()); $this->assertSame(110.5, $user->getFloatCount()); } @@ -351,7 +356,7 @@ public function testIncrementSetsNull() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $this->assertSame(10, $user->getCount()); $this->assertSame(10.0, $user->getFloatCount()); @@ -360,7 +365,7 @@ public function testIncrementSetsNull() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $this->assertSame(11, $user->getCount()); $this->assertSame(11.0, $user->getFloatCount()); @@ -369,7 +374,7 @@ public function testIncrementSetsNull() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jon']); + $user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jon']); $this->assertNull($user->getCount()); $this->assertNull($user->getFloatCount()); } @@ -410,7 +415,7 @@ public function testTest() $this->dm->flush(); $this->dm->clear(); - $result = $this->dm->createQueryBuilder('Documents\Manager') + $result = $this->dm->createQueryBuilder(Manager::class) ->field('name')->equals('Manager') ->hydrate(false) ->getQuery() @@ -424,7 +429,7 @@ public function testTest() public function testNotAnnotatedDocument() { - $this->dm->getDocumentCollection('Documents\Functional\NotAnnotatedDocument')->drop(); + $this->dm->getDocumentCollection(NotAnnotatedDocument::class)->drop(); $test = new NotAnnotatedDocument(); $test->field = 'test'; @@ -433,21 +438,21 @@ public function testNotAnnotatedDocument() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->find('Documents\Functional\NotAnnotatedDocument', $test->id); + $test = $this->dm->find(NotAnnotatedDocument::class, $test->id); $this->assertNotNull($test); $this->assertFalse(isset($test->transientField)); } public function testNullFieldValuesAllowed() { - $this->dm->getDocumentCollection('Documents\Functional\NullFieldValues')->drop(); + $this->dm->getDocumentCollection(NullFieldValues::class)->drop(); $test = new NullFieldValues(); $test->field = null; $this->dm->persist($test); $this->dm->flush(); - $document = $this->dm->createQueryBuilder('Documents\Functional\NullFieldValues') + $document = $this->dm->createQueryBuilder(NullFieldValues::class) ->hydrate(false) ->getQuery() ->getSingleResult(); @@ -455,18 +460,18 @@ public function testNullFieldValuesAllowed() $this->assertNotNull($document); $this->assertNull($document['field']); - $document = $this->dm->find('Documents\Functional\NullFieldValues', $test->id); + $document = $this->dm->find(NullFieldValues::class, $test->id); $document->field = 'test'; $this->dm->flush(); $this->dm->clear(); - $document = $this->dm->find('Documents\Functional\NullFieldValues', $test->id); + $document = $this->dm->find(NullFieldValues::class, $test->id); $this->assertEquals('test', $document->field); $document->field = null; $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->createQueryBuilder('Documents\Functional\NullFieldValues') + $test = $this->dm->createQueryBuilder(NullFieldValues::class) ->hydrate(false) ->getQuery() ->getSingleResult(); @@ -476,7 +481,7 @@ public function testNullFieldValuesAllowed() public function testSimplerEmbedAndReference() { - $class = $this->dm->getClassMetadata('Documents\Functional\SimpleEmbedAndReference'); + $class = $this->dm->getClassMetadata(SimpleEmbedAndReference::class); $this->assertEquals('many', $class->fieldMappings['embedMany']['type']); $this->assertEquals('one', $class->fieldMappings['embedOne']['type']); $this->assertEquals('many', $class->fieldMappings['referenceMany']['type']); @@ -485,7 +490,7 @@ public function testSimplerEmbedAndReference() public function testNotSavedFields() { - $collection = $this->dm->getDocumentCollection('Documents\Functional\NotSaved'); + $collection = $this->dm->getDocumentCollection(NotSaved::class); $collection->drop(); $test = [ '_id' => new ObjectId(), @@ -493,7 +498,7 @@ public function testNotSavedFields() 'notSaved' => 'test', ]; $collection->insertOne($test); - $notSaved = $this->dm->find('Documents\Functional\NotSaved', $test['_id']); + $notSaved = $this->dm->find(NotSaved::class, $test['_id']); $this->assertEquals('Jonathan Wage', $notSaved->name); $this->assertEquals('test', $notSaved->notSaved); @@ -531,7 +536,7 @@ public function testTypeClassMissing() $this->dm->clear(); /** @var FavoritesUser $test */ - $test = $this->dm->find('Documents\Functional\FavoritesUser', $user->getId()); + $test = $this->dm->find(FavoritesUser::class, $user->getId()); /** @var PersistentCollection $collection */ $collection = $test->getFavorites(); @@ -549,7 +554,7 @@ public function testTypeClass() $this->dm->clear(); /** @var Bar $test */ - $test = $this->dm->find('Documents\Bars\Bar', $bar->getId()); + $test = $this->dm->find(Bar::class, $bar->getId()); /** @var PersistentCollection $collection */ $collection = $test->getLocations(); @@ -588,24 +593,24 @@ public function testFavoritesReference() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getDocumentCollection('Documents\Functional\FavoritesUser')->findOne(['name' => 'favorites']); + $test = $this->dm->getDocumentCollection(FavoritesUser::class)->findOne(['name' => 'favorites']); $this->assertTrue(isset($test['favorites'][0]['type'])); $this->assertEquals('project', $test['favorites'][0]['type']); $this->assertEquals('group', $test['favorites'][1]['type']); $this->assertTrue(isset($test['favorite']['_doctrine_class_name'])); - $this->assertEquals('Documents\Project', $test['favorite']['_doctrine_class_name']); + $this->assertEquals(Project::class, $test['favorite']['_doctrine_class_name']); - $user = $this->dm->getRepository('Documents\Functional\FavoritesUser')->findOneBy(['name' => 'favorites']); + $user = $this->dm->getRepository(FavoritesUser::class)->findOneBy(['name' => 'favorites']); $favorites = $user->getFavorites(); - $this->assertInstanceOf('Documents\Project', $favorites[0]); - $this->assertInstanceOf('Documents\Group', $favorites[1]); + $this->assertInstanceOf(Project::class, $favorites[0]); + $this->assertInstanceOf(Group::class, $favorites[1]); $embedded = $user->getEmbedded(); - $this->assertInstanceOf('Documents\Address', $embedded[0]); - $this->assertInstanceOf('Documents\Phonenumber', $embedded[1]); + $this->assertInstanceOf(Address::class, $embedded[0]); + $this->assertInstanceOf(Phonenumber::class, $embedded[1]); - $this->assertInstanceOf('Documents\Address', $user->getEmbed()); - $this->assertInstanceOf('Documents\Project', $user->getFavorite()); + $this->assertInstanceOf(Address::class, $user->getEmbed()); + $this->assertInstanceOf(Project::class, $user->getFavorite()); } public function testPreUpdate() @@ -629,11 +634,11 @@ public function testPreUpdate() $this->dm->flush(); $this->dm->clear(); - $product = $this->dm->getRepository('Documents\Functional\PreUpdateTestProduct')->findOneBy(['name' => 'Product']); + $product = $this->dm->getRepository(PreUpdateTestProduct::class)->findOneBy(['name' => 'Product']); - $this->assertInstanceOf('Documents\Functional\PreUpdateTestSellable', $product->sellable); - $this->assertInstanceOf('Documents\Functional\PreUpdateTestProduct', $product->sellable->getProduct()); - $this->assertInstanceOf('Documents\Functional\PreUpdateTestSeller', $product->sellable->getSeller()); + $this->assertInstanceOf(PreUpdateTestSellable::class, $product->sellable); + $this->assertInstanceOf(PreUpdateTestProduct::class, $product->sellable->getProduct()); + $this->assertInstanceOf(PreUpdateTestSeller::class, $product->sellable->getSeller()); $product = new PreUpdateTestProduct(); $product->name = 'Product2'; @@ -643,14 +648,14 @@ public function testPreUpdate() $sellable = new PreUpdateTestSellable(); $sellable->product = $product; - $sellable->seller = $this->dm->getRepository('Documents\Functional\PreUpdateTestSeller')->findOneBy(['name' => 'Seller']); + $sellable->seller = $this->dm->getRepository(PreUpdateTestSeller::class)->findOneBy(['name' => 'Seller']); $product->sellable = $sellable; $this->dm->flush(); $this->dm->clear(); - $product = $this->dm->getRepository('Documents\Functional\PreUpdateTestProduct')->findOneBy(['name' => 'Product2']); + $product = $this->dm->getRepository(PreUpdateTestProduct::class)->findOneBy(['name' => 'Product2']); $this->assertEquals('Seller', $product->sellable->getSeller()->getName()); $this->assertEquals('Product2', $product->sellable->getProduct()->getName()); } @@ -671,33 +676,33 @@ public function testSameCollectionTest() $this->dm->persist($test3); $this->dm->flush(); - $test = $this->dm->getRepository('Documents\Functional\SameCollection1')->findOneBy(['name' => 'test1']); + $test = $this->dm->getRepository(SameCollection1::class)->findOneBy(['name' => 'test1']); $this->assertNotNull($test); - $this->assertInstanceOf('Documents\Functional\SameCollection1', $test); + $this->assertInstanceOf(SameCollection1::class, $test); - $test = $this->dm->getRepository('Documents\Functional\SameCollection2')->findOneBy(['name' => 'test2']); + $test = $this->dm->getRepository(SameCollection2::class)->findOneBy(['name' => 'test2']); $this->assertNotNull($test); - $this->assertInstanceOf('Documents\Functional\SameCollection2', $test); + $this->assertInstanceOf(SameCollection2::class, $test); - $test = $this->dm->getRepository('Documents\Functional\SameCollection1')->findOneBy(['name' => 'test3']); + $test = $this->dm->getRepository(SameCollection1::class)->findOneBy(['name' => 'test3']); $this->assertNotNull($test); - $this->assertInstanceOf('Documents\Functional\SameCollection1', $test); + $this->assertInstanceOf(SameCollection1::class, $test); - $test = $this->dm->getRepository('Documents\Functional\SameCollection2')->findOneBy(['name' => 'test1']); + $test = $this->dm->getRepository(SameCollection2::class)->findOneBy(['name' => 'test1']); $this->assertNull($test); $qb = $this->dm->createQueryBuilder([ - 'Documents\Functional\SameCollection1', - 'Documents\Functional\SameCollection2', + SameCollection1::class, + SameCollection2::class, ]); $q = $qb->getQuery(); $test = $q->execute()->toArray(); $this->assertCount(3, $test); - $test = $this->dm->getRepository('Documents\Functional\SameCollection1')->findAll(); + $test = $this->dm->getRepository(SameCollection1::class)->findAll(); $this->assertCount(2, $test); - $qb = $this->dm->createQueryBuilder('Documents\Functional\SameCollection1'); + $qb = $this->dm->createQueryBuilder(SameCollection1::class); $query = $qb->getQuery(); $test = $query->execute()->toArray(); $this->assertCount(2, $test); @@ -709,8 +714,8 @@ public function testSameCollectionTest() public function testNotSameCollectionThrowsException() { $test = $this->dm->createQueryBuilder([ - 'Documents\User', - 'Documents\Profile', + User::class, + Profile::class, ])->getQuery()->execute(); } @@ -739,12 +744,12 @@ public function testEmbeddedNesting() $this->dm->flush(); $this->dm->clear(); - $check = $this->dm->getRepository('Documents\Functional\EmbeddedTestLevel0')->find($test->id); + $check = $this->dm->getRepository(EmbeddedTestLevel0::class)->find($test->id); $this->assertEquals('test', $check->name); - $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel1', $check->level1[0]); - $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel1', $check->level1[1]); - $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel2', $check->level1[1]->level2[0]); - $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel2', $check->level1[1]->level2[1]); + $this->assertInstanceOf(EmbeddedTestLevel1::class, $check->level1[0]); + $this->assertInstanceOf(EmbeddedTestLevel1::class, $check->level1[1]); + $this->assertInstanceOf(EmbeddedTestLevel2::class, $check->level1[1]->level2[0]); + $this->assertInstanceOf(EmbeddedTestLevel2::class, $check->level1[1]->level2[1]); $this->assertCount(2, $check->level1); $this->assertCount(2, $check->level1[1]->level2); } @@ -766,7 +771,7 @@ public function testEmbeddedInheritance() $this->dm->clear(); // fetch the level0b from db - $test = $this->dm->find('Documents\Functional\EmbeddedTestLevel0b', $test->id); + $test = $this->dm->find(EmbeddedTestLevel0b::class, $test->id); // add a level2 in the level0b.level1 $level2 = new EmbeddedTestLevel2(); @@ -781,7 +786,7 @@ public function testEmbeddedInheritance() $this->dm->clear(); // fetch again - $test = $this->dm->find('Documents\Functional\EmbeddedTestLevel0b', $test->id); + $test = $this->dm->find(EmbeddedTestLevel0b::class, $test->id); // Uh oh, the level2 was not persisted! $this->assertCount(1, $test->oneLevel1->level2); @@ -805,7 +810,7 @@ public function testModifyGroupsArrayDirectly() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertNotNull($user); // remove two of the groups and pass the groups back into the User @@ -820,7 +825,7 @@ public function testModifyGroupsArrayDirectly() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertCount(1, $user->getGroups()); } @@ -843,7 +848,7 @@ public function testReplaceEntireGroupsArray() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertNotNull($user); // Issue is collection must be initialized @@ -861,7 +866,7 @@ public function testReplaceEntireGroupsArray() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertCount(1, $user->getGroups()); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php index ed35491b6f..04ab331e2a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php @@ -61,7 +61,7 @@ public function testIdentityMap() $this->dm->persist($user); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()); $user = $qb->getQuery()->getSingleResult(); @@ -87,7 +87,7 @@ public function testIdentityMap() $user4 = $qb->getQuery()->getSingleResult(); $this->assertEquals('changed', $user4->getUsername()); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->findAndUpdate() ->returnNew(true) ->hydrate(true) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/InheritanceTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/InheritanceTest.php index 9f27b64916..eeccc29c08 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/InheritanceTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/InheritanceTest.php @@ -31,7 +31,7 @@ public function testCollectionPerClassInheritance() $this->assertNotSame('', $user->getId()); $this->assertNotSame('', $user->getProfile()->getProfileId()); - $qb = $this->dm->createQueryBuilder('Documents\SpecialUser') + $qb = $this->dm->createQueryBuilder(SpecialUser::class) ->field('id') ->equals($user->getId()); $query = $qb->getQuery(); @@ -53,7 +53,7 @@ public function testSingleCollectionInhertiance() $this->dm->persist($subProject); $this->dm->flush(); - $coll = $this->dm->getDocumentCollection('Documents\SubProject'); + $coll = $this->dm->getDocumentCollection(SubProject::class); $document = $coll->findOne(['name' => 'Sub Project']); $this->assertEquals('sub-project', $document['type']); @@ -61,28 +61,28 @@ public function testSingleCollectionInhertiance() $this->dm->persist($project); $this->dm->flush(); - $coll = $this->dm->getDocumentCollection('Documents\OtherSubProject'); + $coll = $this->dm->getDocumentCollection(OtherSubProject::class); $document = $coll->findOne(['name' => 'Other Sub Project']); $this->assertEquals('other-sub-project', $document['type']); $this->dm->clear(); - $document = $this->dm->getRepository('Documents\SubProject')->findOneBy(['name' => 'Sub Project']); - $this->assertInstanceOf('Documents\SubProject', $document); + $document = $this->dm->getRepository(SubProject::class)->findOneBy(['name' => 'Sub Project']); + $this->assertInstanceOf(SubProject::class, $document); - $document = $this->dm->getRepository('Documents\SubProject')->findOneBy(['name' => 'Sub Project']); - $this->assertInstanceOf('Documents\SubProject', $document); + $document = $this->dm->getRepository(SubProject::class)->findOneBy(['name' => 'Sub Project']); + $this->assertInstanceOf(SubProject::class, $document); - $document = $this->dm->getRepository('Documents\Project')->findOneBy(['name' => 'Sub Project']); - $this->assertInstanceOf('Documents\SubProject', $document); + $document = $this->dm->getRepository(Project::class)->findOneBy(['name' => 'Sub Project']); + $this->assertInstanceOf(SubProject::class, $document); $this->dm->clear(); $id = $document->getId(); - $document = $this->dm->find('Documents\Project', $id); - $this->assertInstanceOf('Documents\SubProject', $document); + $document = $this->dm->find(Project::class, $id); + $this->assertInstanceOf(SubProject::class, $document); - $document = $this->dm->getRepository('Documents\Project')->findOneBy(['name' => 'Other Sub Project']); - $this->assertInstanceOf('Documents\OtherSubProject', $document); + $document = $this->dm->getRepository(Project::class)->findOneBy(['name' => 'Other Sub Project']); + $this->assertInstanceOf(OtherSubProject::class, $document); } public function testPrePersistIsCalledFromMappedSuperClass() @@ -108,13 +108,13 @@ public function testInheritanceProxy() $this->dm->flush(); $this->dm->clear(); - $developer = $this->dm->find('Documents\Developer', $developer->getId()); + $developer = $this->dm->find(Developer::class, $developer->getId()); $projects = $developer->getProjects(); $this->assertEquals(3, $projects->count()); - $this->assertInstanceOf('Documents\Project', $projects[0]); - $this->assertInstanceOf('Documents\SubProject', $projects[1]); - $this->assertInstanceOf('Documents\OtherSubProject', $projects[2]); + $this->assertInstanceOf(Project::class, $projects[0]); + $this->assertInstanceOf(SubProject::class, $projects[1]); + $this->assertInstanceOf(OtherSubProject::class, $projects[2]); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OwningAndInverseReferencesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OwningAndInverseReferencesTest.php index 842e16e494..4aa80ad98a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OwningAndInverseReferencesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OwningAndInverseReferencesTest.php @@ -41,8 +41,8 @@ public function testOneToOne() $this->dm->flush(); $this->dm->clear(); - $customer = $this->dm->getRepository('Documents\Customer')->find($customer->id); - $this->assertInstanceOf('Documents\Cart', $customer->cart); + $customer = $this->dm->getRepository(Customer::class)->find($customer->id); + $this->assertInstanceOf(Cart::class, $customer->cart); $this->assertEquals($customer->cart->id, $customer->cart->id); $check = $this->dm->getDocumentCollection(get_class($customer))->findOne(); @@ -58,8 +58,8 @@ public function testOneToOne() $this->assertArrayHasKey('cart', $check); $this->assertEquals('ok', $check['cart']); - $customer = $this->dm->getRepository('Documents\Customer')->find($customer->id); - $this->assertInstanceOf('Documents\Cart', $customer->cart); + $customer = $this->dm->getRepository(Customer::class)->find($customer->id); + $this->assertInstanceOf(Cart::class, $customer->cart); $this->assertEquals('ok', $customer->cartTest); } @@ -75,7 +75,7 @@ public function testOneToManyBiDirectional() $check = $this->dm->getDocumentCollection(get_class($product))->findOne(); $this->assertArrayNotHasKey('tags', $check); - $check = $this->dm->getDocumentCollection('Documents\Feature')->findOne(); + $check = $this->dm->getDocumentCollection(Feature::class)->findOne(); $this->assertArrayHasKey('product', $check); $product = $this->dm->createQueryBuilder(get_class($product)) @@ -105,7 +105,7 @@ public function testOneToManySelfReferencing() ->field('children')->exists(false) ->getQuery() ->getSingleResult(); - $this->assertInstanceOf('Documents\BrowseNode', $root); + $this->assertInstanceOf(BrowseNode::class, $root); $this->assertCount(2, $root->children); unset($root->children[0]); @@ -131,17 +131,17 @@ public function testManyToMany() $check = $this->dm->getDocumentCollection(get_class($blogPost))->findOne(); $this->assertCount(1, $check['tags']); - $check = $this->dm->getDocumentCollection('Documents\Tag')->findOne(); + $check = $this->dm->getDocumentCollection(Tag::class)->findOne(); $this->assertArrayNotHasKey('blogPosts', $check); - $blogPost = $this->dm->createQueryBuilder('Documents\BlogPost') + $blogPost = $this->dm->createQueryBuilder(BlogPost::class) ->getQuery() ->getSingleResult(); $this->assertCount(1, $blogPost->tags); $this->dm->clear(); - $tag = $this->dm->createQueryBuilder('Documents\Tag') + $tag = $this->dm->createQueryBuilder(Tag::class) ->getQuery() ->getSingleResult(); $this->assertEquals('baseball', $tag->name); @@ -165,14 +165,14 @@ public function testManyToManySelfReferencing() $this->dm->flush(); $this->dm->clear(); - $check = $this->dm->createQueryBuilder('Documents\FriendUser') + $check = $this->dm->createQueryBuilder(FriendUser::class) ->field('name')->equals('fabpot') ->hydrate(false) ->getQuery() ->getSingleResult(); $this->assertArrayNotHasKey('friendsWithMe', $check); - $user = $this->dm->createQueryBuilder('Documents\FriendUser') + $user = $this->dm->createQueryBuilder(FriendUser::class) ->field('name')->equals('fabpot') ->getQuery() ->getSingleResult(); @@ -182,7 +182,7 @@ public function testManyToManySelfReferencing() $this->dm->clear(); - $user = $this->dm->createQueryBuilder('Documents\FriendUser') + $user = $this->dm->createQueryBuilder(FriendUser::class) ->field('name')->equals('romanb') ->getQuery() ->getSingleResult(); @@ -192,7 +192,7 @@ public function testManyToManySelfReferencing() $this->dm->clear(); - $user = $this->dm->createQueryBuilder('Documents\FriendUser') + $user = $this->dm->createQueryBuilder(FriendUser::class) ->field('name')->equals('jwage') ->getQuery() ->getSingleResult(); @@ -224,7 +224,7 @@ public function testSortLimitAndSkipReferences() $this->dm->flush(); $this->dm->clear(); - $blogPost = $this->dm->createQueryBuilder('Documents\BlogPost') + $blogPost = $this->dm->createQueryBuilder(BlogPost::class) ->getQuery() ->getSingleResult(); $this->assertEquals('Comment 1', $blogPost->comments[0]->text); @@ -234,14 +234,14 @@ public function testSortLimitAndSkipReferences() $this->dm->clear(); - $comment = $this->dm->createQueryBuilder('Documents\Comment') + $comment = $this->dm->createQueryBuilder(Comment::class) ->getQuery() ->getSingleResult(); $this->assertEquals('Test', $comment->parent->getName()); $this->dm->clear(); - $blogPost = $this->dm->createQueryBuilder('Documents\BlogPost') + $blogPost = $this->dm->createQueryBuilder(BlogPost::class) ->getQuery() ->getSingleResult(); $this->assertEquals('Comment 1', $blogPost->firstComment->getText()); @@ -253,7 +253,7 @@ public function testSortLimitAndSkipReferences() $this->dm->clear(); - $blogPost = $this->dm->createQueryBuilder('Documents\BlogPost') + $blogPost = $this->dm->createQueryBuilder(BlogPost::class) ->getQuery() ->getSingleResult(); @@ -262,7 +262,7 @@ public function testSortLimitAndSkipReferences() $this->dm->flush(); $this->dm->clear(); - $blogPost = $this->dm->createQueryBuilder('Documents\BlogPost') + $blogPost = $this->dm->createQueryBuilder(BlogPost::class) ->getQuery() ->getSingleResult(); $this->assertCount(2, $blogPost->adminComments); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/PersistingTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/PersistingTest.php index c9f6d929f8..53c96ba968 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/PersistingTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/PersistingTest.php @@ -44,14 +44,14 @@ public function testUpdate() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertNotNull($user); $user->setUsername('w00t'); $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertNotNull($user); $this->assertEquals('w00t', $user->getUsername()); $this->assertEquals('cool', $user->getInheritedProperty()); @@ -70,7 +70,7 @@ public function testDetach() $this->dm->flush(); $this->dm->clear(); - $user2 = $this->dm->find('Documents\User', $user->getId()); + $user2 = $this->dm->find(User::class, $user->getId()); $this->assertNotNull($user2); $this->assertEquals('jon', $user2->getUsername()); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php index c5f62b518a..aef91230b3 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php @@ -39,8 +39,8 @@ public function testAddElemMatch() $this->dm->persist($user); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\User'); - $embeddedQb = $this->dm->createQueryBuilder('Documents\Phonenumber'); + $qb = $this->dm->createQueryBuilder(User::class); + $embeddedQb = $this->dm->createQueryBuilder(Phonenumber::class); $qb->field('phonenumbers')->elemMatch($embeddedQb->expr()->field('phonenumber')->equals('6155139185')); $query = $qb->getQuery(); @@ -62,8 +62,8 @@ public function testAddElemMatchWithDeepFields() $this->dm->persist($user2); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\User'); - $embeddedQb = $this->dm->createQueryBuilder('Documents\Phonenumber'); + $qb = $this->dm->createQueryBuilder(User::class); + $embeddedQb = $this->dm->createQueryBuilder(Phonenumber::class); $qb->field('phonenumbers')->elemMatch($embeddedQb->expr()->field('lastCalledBy.$id')->equals(new ObjectId($user1->getId()))); $query = $qb->getQuery(); @@ -79,7 +79,7 @@ public function testAddNot() $this->dm->persist($user); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\User'); + $qb = $this->dm->createQueryBuilder(User::class); $qb->field('username')->not($qb->expr()->in(['boo'])); $query = $qb->getQuery(); $user = $query->getSingleResult(); @@ -114,14 +114,14 @@ public function testDistinct() $this->dm->persist($user); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->distinct('count') ->field('username')->equals('distinct_test'); $q = $qb->getQuery(); $results = $q->execute(); $this->assertEquals([1, 2, 3], $results); - $results = $this->dm->createQueryBuilder('Documents\User') + $results = $this->dm->createQueryBuilder(User::class) ->distinct('count') ->field('username')->equals('distinct_test') ->getQuery() @@ -151,7 +151,7 @@ public function testDistinctWithDifferentDbName() public function testFindQuery() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->where("function() { return this.username == 'boo' }"); $query = $qb->getQuery(); $user = $query->getSingleResult(); @@ -160,7 +160,7 @@ public function testFindQuery() public function testUpdateQuery() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->updateOne() ->field('username') ->set('crap') @@ -174,7 +174,7 @@ public function testUpdateQuery() public function testUpsertUpdateQuery() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->updateOne() ->upsert(true) ->field('username') @@ -183,7 +183,7 @@ public function testUpsertUpdateQuery() $query = $qb->getQuery(); $result = $query->execute(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->find() ->field('username')->equals('crap'); $query = $qb->getQuery(); @@ -214,14 +214,14 @@ public function testMultipleUpdateQuery() $this->dm->persist($user); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->updateMany() ->field('username')->equals('multiple_test') ->field('username')->set('foo'); $q = $qb->getQuery(); $results = $q->execute(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->find() ->field('username')->equals('foo'); $q = $qb->getQuery(); @@ -243,7 +243,7 @@ public function testRemoveQuery() public function testIncUpdateQuery() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->updateOne() ->field('hits')->inc(5) ->field('username')->equals('boo'); @@ -251,7 +251,7 @@ public function testIncUpdateQuery() $query->execute(); $query->execute(); - $qb->find('Documents\User') + $qb->find(User::class) ->hydrate(false); $query = $qb->getQuery(); $user = $query->getSingleResult(); @@ -260,14 +260,14 @@ public function testIncUpdateQuery() public function testUnsetFieldUpdateQuery() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->updateOne() ->field('hits')->unsetField() ->field('username')->equals('boo'); $query = $qb->getQuery(); $result = $query->execute(); - $qb->find('Documents\User') + $qb->find(User::class) ->hydrate(false); $query = $qb->getQuery(); $user = $query->getSingleResult(); @@ -277,14 +277,14 @@ public function testUnsetFieldUpdateQuery() public function testUnsetField() { $qb = $this->dm->createQueryBuilder() - ->updateOne('Documents\User') + ->updateOne(User::class) ->field('nullTest') ->type('null') ->unsetField('nullTest'); $query = $qb->getQuery(); $query->execute(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('nullTest')->type('null'); $query = $qb->getQuery(); $user = $query->getSingleResult(); @@ -321,7 +321,7 @@ public function testDateRange() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\Article'); + $qb = $this->dm->createQueryBuilder(Article::class); $qb->field('createdAt')->range( new UTCDateTime(strtotime('1985-09-01 01:00:00') * 1000), new UTCDateTime(strtotime('1985-09-04') * 1000) @@ -340,11 +340,11 @@ public function testQueryIsIterable() $this->dm->persist($article); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\Article'); + $qb = $this->dm->createQueryBuilder(Article::class); $query = $qb->getQuery(); $this->assertInstanceOf(\IteratorAggregate::class, $query); foreach ($query as $article) { - $this->assertEquals('Documents\Article', get_class($article)); + $this->assertEquals(Article::class, get_class($article)); } } @@ -359,7 +359,7 @@ public function testQueryReferences() $this->dm->persist($user); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('groups')->references($group); $query = $qb->getQuery(); $user2 = $query->getSingleResult(); @@ -368,7 +368,7 @@ public function testQueryReferences() public function testQueryWhereIn() { - $qb = $this->dm->createQueryBuilder('Documents\User'); + $qb = $this->dm->createQueryBuilder(User::class); $choices = ['a', 'b']; $qb->field('username')->in($choices); $expected = [ @@ -379,7 +379,7 @@ public function testQueryWhereIn() public function testQueryWhereInReferenceId() { - $qb = $this->dm->createQueryBuilder('Documents\User'); + $qb = $this->dm->createQueryBuilder(User::class); $choices = [new ObjectId(), new ObjectId()]; $qb->field('account.$id')->in($choices); $expected = [ @@ -391,7 +391,7 @@ public function testQueryWhereInReferenceId() public function testQueryWhereOneValueOfCollection() { - $qb = $this->dm->createQueryBuilder('Documents\Article'); + $qb = $this->dm->createQueryBuilder(Article::class); $qb->field('tags')->equals('pet'); $expected = ['tags' => 'pet']; $this->assertSame($expected, $qb->getQueryArray()); @@ -401,7 +401,7 @@ public function testQueryWhereOneValueOfCollection() /** search for articles where tags exactly equal [pet, blue] */ public function testQueryWhereAllValuesOfCollection() { - $qb = $this->dm->createQueryBuilder('Documents\Article'); + $qb = $this->dm->createQueryBuilder(Article::class); $qb->field('tags')->equals(['pet', 'blue']); $expected = [ 'tags' => ['pet', 'blue'], diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php index fe616141a4..9f78479495 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php @@ -27,7 +27,7 @@ public function setUp() public function testHintIsNotSetByDefault() { - $query = $this->dm->getRepository('Documents\User') + $query = $this->dm->getRepository(User::class) ->createQueryBuilder() ->getQuery(); @@ -45,7 +45,7 @@ public function testHintIsNotSetByDefault() */ public function testHintIsSetOnQuery($readPreference, array $tags = []) { - $query = $this->dm->getRepository('Documents\User') + $query = $this->dm->getRepository(User::class) ->createQueryBuilder() ->setReadPreference(new ReadPreference($readPreference, $tags)) ->getQuery(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php index eb7bd82f39..9a899a9207 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php @@ -20,7 +20,7 @@ public function testSavesEmbeddedDocumentsInReferencedDocument() $this->dm->flush(); $this->dm->clear(); - $project = $this->dm->find('Documents\Project', $project->getId()); + $project = $this->dm->find(Project::class, $project->getId()); $subProjects = new ArrayCollection(); $subProject1 = new SubProject('Sub Project #1'); @@ -44,7 +44,7 @@ public function testSavesEmbeddedDocumentsInReferencedDocument() $this->dm->flush(); $this->dm->clear(); - $project = $this->dm->find('Documents\Project', $project->getId()); + $project = $this->dm->find(Project::class, $project->getId()); $subProjects = $project->getSubProjects(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceRepositoryMethodTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceRepositoryMethodTest.php index c3345a49ce..ba371e7304 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceRepositoryMethodTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceRepositoryMethodTest.php @@ -27,7 +27,7 @@ public function testOneToOne() $this->dm->flush(); $this->dm->clear(); - $blogPost = $this->dm->createQueryBuilder('Documents\BlogPost') + $blogPost = $this->dm->createQueryBuilder(BlogPost::class) ->getQuery() ->getSingleResult(); @@ -73,7 +73,7 @@ public function testOneToMany() public function testSetStrategy() { - $repo = $this->dm->getRepository('Documents\BlogPost'); + $repo = $this->dm->getRepository(BlogPost::class); $blogPost = new BlogPost('Test'); @@ -82,7 +82,7 @@ public function testSetStrategy() $this->dm->flush(); $this->dm->clear(); - $blogPost = $this->dm->createQueryBuilder('Documents\BlogPost') + $blogPost = $this->dm->createQueryBuilder(BlogPost::class) ->getQuery() ->getSingleResult(); $this->assertEquals('Comment', $blogPost->repoCommentsSet[0]->getText()); @@ -97,7 +97,7 @@ public function testRepositoryMethodWithoutMappedBy() $this->dm->flush(); $this->dm->clear(); - $blogPost = $this->dm->createQueryBuilder('Documents\BlogPost') + $blogPost = $this->dm->createQueryBuilder(BlogPost::class) ->getQuery() ->getSingleResult(); $this->assertCount(1, $blogPost->repoCommentsWithoutMappedBy); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php index 30a2f4eb7d..7f8d84a13f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php @@ -35,7 +35,7 @@ public function testManyDeleteReference() $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id') ->equals($user->getId()); $query = $qb->getQuery(); @@ -44,7 +44,7 @@ public function testManyDeleteReference() $this->dm->remove($user2); $this->dm->flush(); - $qb = $this->dm->createQueryBuilder('Documents\Group'); + $qb = $this->dm->createQueryBuilder(Group::class); $query = $qb->getQuery(); $groups = $query->execute(); @@ -64,7 +64,7 @@ public function testLazyLoadReference() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()); $query = $qb->getQuery(); @@ -124,7 +124,7 @@ public function testOneEmbedded() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()); $query = $qb->getQuery(); $user2 = $query->getSingleResult(); @@ -141,7 +141,7 @@ public function testManyEmbedded() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()); $query = $qb->getQuery(); $user2 = $query->getSingleResult(); @@ -187,7 +187,7 @@ public function testManyReference() $this->assertNotSame('', $groups[1]->getId()); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id') ->equals($user->getId()); $query = $qb->getQuery(); @@ -215,7 +215,7 @@ public function testManyReference() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()); $query = $qb->getQuery(); $user3 = $query->getSingleResult(); @@ -233,7 +233,7 @@ public function testFlushInitializesEmptyPersistentCollection() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->find($user->getId()); + $user = $this->dm->getRepository(User::class)->find($user->getId()); $user->addGroup(new Group('Group 1')); $user->addGroup(new Group('Group 2')); @@ -255,7 +255,7 @@ public function testFlushInitializesNotEmptyPersistentCollection() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository('Documents\User')->find($user->getId()); + $user = $this->dm->getRepository(User::class)->find($user->getId()); $user->addGroup(new Group('Group 1')); $user->addGroup(new Group('Group 2')); @@ -286,7 +286,7 @@ public function testManyReferenceWithAddToSetStrategy() $this->assertNotSame('', $groups[1]->getId()); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id') ->equals($user->getId()); $query = $qb->getQuery(); @@ -314,7 +314,7 @@ public function testManyReferenceWithAddToSetStrategy() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('id')->equals($user->getId()); $query = $qb->getQuery(); $user3 = $query->getSingleResult(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/RemoveTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/RemoveTest.php index 4cc9841c17..9baa015c4d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/RemoveTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/RemoveTest.php @@ -33,16 +33,16 @@ public function testRemove() $this->dm->remove($user); $this->dm->flush(); - $account = $this->dm->find('Documents\Account', $account->getId()); + $account = $this->dm->find(Account::class, $account->getId()); $this->assertNull($account); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $this->assertNull($user); } public function testUnsetFromEmbeddedCollection() { - $userRepository = $this->dm->getRepository('Documents\User'); + $userRepository = $this->dm->getRepository(User::class); $user = new User(); $user->addGroup(new Group('group1')); @@ -68,8 +68,8 @@ public function testUnsetFromEmbeddedCollection() public function testUnsetFromReferencedCollectionWithCascade() { - $developerRepository = $this->dm->getRepository('Documents\Developer'); - $projectRepository = $this->dm->getRepository('Documents\Project'); + $developerRepository = $this->dm->getRepository(Developer::class); + $projectRepository = $this->dm->getRepository(Project::class); // Developer owns the one-to-many relationship and cascades $developer = new Developer('developer'); @@ -125,8 +125,8 @@ public function testUnsetFromReferencedCollectionWithCascade() public function testUnsetFromReferencedCollectionWithoutCascade() { - $articleRepository = $this->dm->getRepository('Documents\CmsArticle'); - $commentRepository = $this->dm->getRepository('Documents\CmsComment'); + $articleRepository = $this->dm->getRepository(CmsArticle::class); + $commentRepository = $this->dm->getRepository(CmsComment::class); // CmsArticle owns the one-to-many relationship but does not cascade $article = new CmsArticle(); @@ -184,8 +184,8 @@ public function testUnsetFromReferencedCollectionWithoutCascade() public function testUnsetFromReferencedCollectionWithCascadeAndMappedBy() { - $blogPostRepository = $this->dm->getRepository('Documents\BlogPost'); - $commentRepository = $this->dm->getRepository('Documents\Comment'); + $blogPostRepository = $this->dm->getRepository(BlogPost::class); + $commentRepository = $this->dm->getRepository(Comment::class); /* CmsComment owns the one-to-many relationship, since BlogPost uses * mappedBy. Both sides cascade operations. diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/RepositoriesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/RepositoriesTest.php index 64e5d6165d..5ecf8017f1 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/RepositoriesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/RepositoriesTest.php @@ -20,7 +20,7 @@ public function setUp() $this->dm->persist($this->user); $this->dm->flush(); - $this->repository = $this->dm->getRepository('Documents\User'); + $this->repository = $this->dm->getRepository(User::class); } public function testFindAll() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/SimpleReferencesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/SimpleReferencesTest.php index f7302789d7..e09a00473d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/SimpleReferencesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/SimpleReferencesTest.php @@ -35,13 +35,13 @@ public function setUp() public function testIndexes() { - $indexes = $this->dm->getSchemaManager()->getDocumentIndexes('Documents\SimpleReferenceUser'); + $indexes = $this->dm->getSchemaManager()->getDocumentIndexes(SimpleReferenceUser::class); $this->assertEquals(['userId' => 1], $indexes[0]['keys']); } public function testStorage() { - $test = $this->dm->getDocumentCollection('Documents\SimpleReferenceUser')->findOne(); + $test = $this->dm->getDocumentCollection(SimpleReferenceUser::class)->findOne(); $this->assertNotNull($test); $this->assertInstanceOf(ObjectId::class, $test['userId']); $this->assertInstanceOf(ObjectId::class, $test['users'][0]); @@ -49,26 +49,26 @@ public function testStorage() public function testQuery() { - $this->user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jwage']); + $this->user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jwage']); - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('user')->references($this->user); $this->assertEquals(['userId' => new ObjectId($this->user->getId())], $qb->getQuery()->debug('query')); - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('user')->equals($this->user->getId()); $this->assertEquals(['userId' => new ObjectId($this->user->getId())], $qb->getQuery()->debug('query')); - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('user')->in([$this->user->getId()]); $this->assertEquals(['userId' => ['$in' => [new ObjectId($this->user->getId())]]], $qb->getQuery()->debug('query')); } public function testProxy() { - $this->user = $this->dm->getRepository('Documents\User')->findOneBy(['username' => 'jwage']); + $this->user = $this->dm->getRepository(User::class)->findOneBy(['username' => 'jwage']); - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('user')->references($this->user); $this->assertEquals(['userId' => new ObjectId($this->user->getId())], $qb->getQuery()->debug('query')); @@ -86,7 +86,7 @@ public function testProxy() public function testPersistentCollectionOwningSide() { - $test = $this->dm->getRepository('Documents\SimpleReferenceUser')->findOneBy([]); + $test = $this->dm->getRepository(SimpleReferenceUser::class)->findOneBy([]); $users = $test->getUsers()->toArray(); $this->assertEquals(2, $test->getUsers()->count()); $this->assertEquals('jwage', current($users)->getUsername()); @@ -95,40 +95,40 @@ public function testPersistentCollectionOwningSide() public function testPersistentCollectionInverseSide() { - $user = $this->dm->getRepository('Documents\User')->findOneBy([]); + $user = $this->dm->getRepository(User::class)->findOneBy([]); $test = $user->getSimpleReferenceManyInverse()->toArray(); $this->assertEquals('test', current($test)->getName()); } public function testOneInverseSide() { - $user = $this->dm->getRepository('Documents\User')->findOneBy([]); + $user = $this->dm->getRepository(User::class)->findOneBy([]); $test = $user->getSimpleReferenceOneInverse(); $this->assertEquals('test', $test->getName()); } public function testQueryForNonIds() { - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('user')->equals(null); $this->assertEquals(['userId' => null], $qb->getQueryArray()); - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('user')->notEqual(null); $this->assertEquals(['userId' => ['$ne' => null]], $qb->getQueryArray()); - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('user')->exists(true); $this->assertEquals(['userId' => ['$exists' => true]], $qb->getQueryArray()); } public function testRemoveDocumentByEmptyRefMany() { - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('users')->equals([]); $this->assertEquals(['users' => []], $qb->getQueryArray()); - $qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser'); + $qb = $this->dm->createQueryBuilder(SimpleReferenceUser::class); $qb->field('users')->equals(new \stdClass()); $this->assertEquals(['users' => new \stdClass()], $qb->getQueryArray()); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/SimpleTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/SimpleTest.php index 8f88b63a38..5ed79c97b6 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/SimpleTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/SimpleTest.php @@ -20,14 +20,14 @@ public function testSimple() $this->dm->flush(); $this->dm->clear(); - $bar = $this->dm->find('Documents\Bars\Bar', $bar->getId()); + $bar = $this->dm->find(Bar::class, $bar->getId()); $locations = $bar->getLocations(); unset($locations[0]); $this->dm->flush(); - $test = $this->dm->getDocumentCollection('Documents\Bars\Bar')->findOne(); + $test = $this->dm->getDocumentCollection(Bar::class)->findOne(); $this->assertCount(2, $test['locations']); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php index bc53f095f5..8c2c0573bf 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php @@ -7,6 +7,7 @@ use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs; use Doctrine\ODM\MongoDB\Events; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Proxy\Proxy; use Doctrine\ODM\MongoDB\Tests\BaseTest; class GH936Test extends BaseTest @@ -26,7 +27,7 @@ public function testRemoveCascadesThroughProxyDocuments() $foo = $this->dm->find(GH936Document::class, $foo->id); - $this->assertInstanceOf(\Doctrine\ODM\MongoDB\Proxy\Proxy::class, $foo->ref); + $this->assertInstanceOf(Proxy::class, $foo->ref); $this->dm->remove($foo); $this->dm->flush(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM140Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM140Test.php index 67c1d58536..4638811c05 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM140Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM140Test.php @@ -94,7 +94,7 @@ public function testAddingAnotherEmbeddedDocument() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getRepository('Documents\Functional\EmbeddedTestLevel0')->findOneBy(['name' => 'test']); + $test = $this->dm->getRepository(EmbeddedTestLevel0::class)->findOneBy(['name' => 'test']); $this->assertCount(1, $test->level1); $this->assertCount(2, $test->level1[0]->level2); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php index 50a8d31645..28dc9be579 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php @@ -6,6 +6,7 @@ use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Documents\Account; +use Documents\Address; use Documents\Group; use Documents\Phonenumber; use Documents\Profile; @@ -117,7 +118,7 @@ public function testDriver() 'name' => 'address', 'type' => 'one', 'embedded' => true, - 'targetDocument' => 'Documents\Address', + 'targetDocument' => Address::class, 'collectionClass' => null, 'isCascadeDetach' => true, 'isCascadeMerge' => true,