diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/ExprTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/ExprTest.php index 58116c720d..932af960ed 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/ExprTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/ExprTest.php @@ -114,7 +114,7 @@ public function testCallingCaseWithoutSwitchThrowsException() $expr = $this->createExpr(); $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::case requires a valid switch statement (call switch() first).'); + $this->expectExceptionMessage(Expr::class . '::case requires a valid switch statement (call switch() first).'); $expr->case('$field'); } @@ -124,7 +124,7 @@ public function testCallingThenWithoutCaseThrowsException() $expr = $this->createExpr(); $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::then requires a valid case statement (call case() first).'); + $this->expectExceptionMessage(Expr::class . '::then requires a valid case statement (call case() first).'); $expr->then('$field'); } @@ -138,7 +138,7 @@ public function testCallingThenWithoutCaseAfterSuccessfulCaseThrowsException() ->then('$field'); $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::then requires a valid case statement (call case() first).'); + $this->expectExceptionMessage(Expr::class . '::then requires a valid case statement (call case() first).'); $expr->then('$field'); } @@ -148,7 +148,7 @@ public function testCallingDefaultWithoutSwitchThrowsException() $expr = $this->createExpr(); $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::default requires a valid switch statement (call switch() first).'); + $this->expectExceptionMessage(Expr::class . '::default requires a valid switch statement (call switch() first).'); $expr->default('$field'); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/MatchTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/MatchTest.php index 83085bdd50..d7c8cba731 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/MatchTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/MatchTest.php @@ -8,6 +8,8 @@ use Doctrine\ODM\MongoDB\Query\Expr; use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationTestTrait; use Doctrine\ODM\MongoDB\Tests\BaseTest; +use Documents\User; +use GeoJson\Geometry\Geometry; use MongoDB\BSON\UTCDateTime; class MatchTest extends BaseTest @@ -95,7 +97,7 @@ public function provideProxiedExprMethods() public function testTypeConversion() { - $builder = $this->dm->createAggregationBuilder('Documents\User'); + $builder = $this->dm->createAggregationBuilder(User::class); $date = new \DateTime(); $mongoDate = new UTCDateTime((int) $date->format('Uv')); @@ -116,7 +118,7 @@ public function testTypeConversion() private function getMockGeometry() { - return $this->getMockBuilder('GeoJson\Geometry\Geometry') + return $this->getMockBuilder(Geometry::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/OperatorTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/OperatorTest.php index 2d457fb4c8..619b3711ff 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/OperatorTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/OperatorTest.php @@ -4,6 +4,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Aggregation\Stage; +use Doctrine\ODM\MongoDB\Aggregation\Expr; use Doctrine\ODM\MongoDB\Aggregation\Stage\Operator; use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationOperatorsProviderTrait; use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationTestTrait; @@ -78,7 +79,7 @@ public function testCallingCaseWithoutSwitchThrowsException() $stage = $this->getStubStage(); $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::case requires a valid switch statement (call switch() first).'); + $this->expectExceptionMessage(Expr::class . '::case requires a valid switch statement (call switch() first).'); $stage->case('$field'); } @@ -88,7 +89,7 @@ public function testCallingThenWithoutCaseThrowsException() $stage = $this->getStubStage(); $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::then requires a valid case statement (call case() first).'); + $this->expectExceptionMessage(Expr::class . '::then requires a valid case statement (call case() first).'); $stage->then('$field'); } @@ -102,7 +103,7 @@ public function testCallingThenWithoutCaseAfterSuccessfulCaseThrowsException() ->then('$field'); $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::then requires a valid case statement (call case() first).'); + $this->expectExceptionMessage(Expr::class . '::then requires a valid case statement (call case() first).'); $stage->then('$field'); } @@ -112,7 +113,7 @@ public function testCallingDefaultWithoutSwitchThrowsException() $stage = $this->getStubStage(); $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::default requires a valid switch statement (call switch() first).'); + $this->expectExceptionMessage(Expr::class . '::default requires a valid switch statement (call switch() first).'); $stage->default('$field'); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php b/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php index 7ee1e4ad8c..d2eacfeacc 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php @@ -7,6 +7,7 @@ use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; +use Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter; use Doctrine\ODM\MongoDB\UnitOfWork; use MongoDB\Client; use MongoDB\Model\DatabaseInfo; @@ -71,8 +72,8 @@ protected function getConfiguration() $config->setDefaultDB(DOCTRINE_MONGODB_DATABASE); $config->setMetadataDriverImpl($this->createMetadataDriverImpl()); - $config->addFilter('testFilter', 'Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter'); - $config->addFilter('testFilter2', 'Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter'); + $config->addFilter('testFilter', Filter::class); + $config->addFilter('testFilter2', Filter::class); return $config; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php index c51b85246f..634f755d53 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php @@ -4,10 +4,26 @@ namespace Doctrine\ODM\MongoDB\Tests; +use Doctrine\Common\EventManager; +use Doctrine\ODM\MongoDB\Aggregation\Builder as AggregationBuilder; +use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; +use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory; use Doctrine\ODM\MongoDB\MongoDBException; +use Doctrine\ODM\MongoDB\Proxy\ProxyFactory; +use Doctrine\ODM\MongoDB\Query\Builder as QueryBuilder; +use Doctrine\ODM\MongoDB\Query\FilterCollection; +use Doctrine\ODM\MongoDB\SchemaManager; +use Doctrine\ODM\MongoDB\UnitOfWork; +use Documents\BaseCategory; +use Documents\BaseCategoryRepository; +use Documents\BlogPost; +use Documents\Category; use Documents\CmsPhonenumber; +use Documents\CmsUser; +use Documents\CustomRepository\Document; +use Documents\CustomRepository\Repository; use Documents\Tournament\ParticipantSolo; use Documents\User; use MongoDB\BSON\ObjectId; @@ -18,17 +34,17 @@ class DocumentManagerTest extends BaseTest { public function testCustomRepository() { - $this->assertInstanceOf('Documents\CustomRepository\Repository', $this->dm->getRepository('Documents\CustomRepository\Document')); + $this->assertInstanceOf(Repository::class, $this->dm->getRepository(Document::class)); } public function testCustomRepositoryMappedsuperclass() { - $this->assertInstanceOf('Documents\BaseCategoryRepository', $this->dm->getRepository('Documents\BaseCategory')); + $this->assertInstanceOf(BaseCategoryRepository::class, $this->dm->getRepository(BaseCategory::class)); } public function testCustomRepositoryMappedsuperclassChild() { - $this->assertInstanceOf('Documents\BaseCategoryRepository', $this->dm->getRepository('Documents\Category')); + $this->assertInstanceOf(BaseCategoryRepository::class, $this->dm->getRepository(Category::class)); } public function testGetConnection() @@ -38,53 +54,53 @@ public function testGetConnection() public function testGetMetadataFactory() { - $this->assertInstanceOf('\Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory', $this->dm->getMetadataFactory()); + $this->assertInstanceOf(ClassMetadataFactory::class, $this->dm->getMetadataFactory()); } public function testGetConfiguration() { - $this->assertInstanceOf('\Doctrine\ODM\MongoDB\Configuration', $this->dm->getConfiguration()); + $this->assertInstanceOf(Configuration::class, $this->dm->getConfiguration()); } public function testGetUnitOfWork() { - $this->assertInstanceOf('\Doctrine\ODM\MongoDB\UnitOfWork', $this->dm->getUnitOfWork()); + $this->assertInstanceOf(UnitOfWork::class, $this->dm->getUnitOfWork()); } public function testGetProxyFactory() { - $this->assertInstanceOf('\Doctrine\ODM\MongoDB\Proxy\ProxyFactory', $this->dm->getProxyFactory()); + $this->assertInstanceOf(ProxyFactory::class, $this->dm->getProxyFactory()); } public function testGetEventManager() { - $this->assertInstanceOf('\Doctrine\Common\EventManager', $this->dm->getEventManager()); + $this->assertInstanceOf(EventManager::class, $this->dm->getEventManager()); } public function testGetSchemaManager() { - $this->assertInstanceOf('\Doctrine\ODM\MongoDB\SchemaManager', $this->dm->getSchemaManager()); + $this->assertInstanceOf(SchemaManager::class, $this->dm->getSchemaManager()); } public function testCreateQueryBuilder() { - $this->assertInstanceOf('\Doctrine\ODM\MongoDB\Query\Builder', $this->dm->createQueryBuilder()); + $this->assertInstanceOf(QueryBuilder::class, $this->dm->createQueryBuilder()); } public function testCreateAggregationBuilder() { - $this->assertInstanceOf('\Doctrine\ODM\MongoDB\Aggregation\Builder', $this->dm->createAggregationBuilder('Documents\BlogPost')); + $this->assertInstanceOf(AggregationBuilder::class, $this->dm->createAggregationBuilder(BlogPost::class)); } public function testGetFilterCollection() { - $this->assertInstanceOf('\Doctrine\ODM\MongoDB\Query\FilterCollection', $this->dm->getFilterCollection()); + $this->assertInstanceOf(FilterCollection::class, $this->dm->getFilterCollection()); } public function testGetPartialReference() { $id = new ObjectId(); - $user = $this->dm->getPartialReference('Documents\CmsUser', $id); + $user = $this->dm->getPartialReference(CmsUser::class, $id); $this->assertTrue($this->dm->contains($user)); $this->assertEquals($id, $user->id); $this->assertNull($user->getName()); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php index 2543b1aeb1..b6a20bee85 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Tests; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Documents\Account; use Documents\Address; @@ -20,11 +21,11 @@ class DocumentRepositoryTest extends BaseTest { public function testMatchingAcceptsCriteriaWithNullWhereExpression() { - $repository = $this->dm->getRepository('Documents\User'); + $repository = $this->dm->getRepository(User::class); $criteria = new Criteria(); $this->assertNull($criteria->getWhereExpression()); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $repository->matching($criteria)); + $this->assertInstanceOf(Collection::class, $repository->matching($criteria)); } public function testFindByRefOneFull() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleCallbacksTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleCallbacksTest.php index d06ecf95c3..6e1411e9d5 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleCallbacksTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleCallbacksTest.php @@ -4,6 +4,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Events; +use DateTime; use Doctrine\ODM\MongoDB\Event; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Tests\BaseTest; @@ -27,18 +28,18 @@ public function testPreUpdateChangingValue() $user = $this->createUser(); $this->dm->clear(); - $user = $this->dm->find(__NAMESPACE__ . '\User', $user->id); - $this->assertInstanceOf('DateTime', $user->createdAt); - $this->assertInstanceOf('DateTime', $user->profile->createdAt); + $user = $this->dm->find(User::class, $user->id); + $this->assertInstanceOf(DateTime::class, $user->createdAt); + $this->assertInstanceOf(DateTime::class, $user->profile->createdAt); $user->name = 'jon changed'; $user->profile->name = 'changed'; $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find(__NAMESPACE__ . '\User', $user->id); - $this->assertInstanceOf('DateTime', $user->updatedAt); - $this->assertInstanceOf('DateTime', $user->profile->updatedAt); + $user = $this->dm->find(User::class, $user->id); + $this->assertInstanceOf(DateTime::class, $user->updatedAt); + $this->assertInstanceOf(DateTime::class, $user->profile->updatedAt); } public function testPreAndPostPersist() @@ -81,7 +82,7 @@ public function testPreLoadAndPostLoad() $user = $this->createUser(); $this->dm->clear(); - $user = $this->dm->find(__NAMESPACE__ . '\User', $user->id); + $user = $this->dm->find(User::class, $user->id); $this->assertTrue($user->preLoad); $this->assertTrue($user->profile->preLoad); @@ -129,7 +130,7 @@ public function testEmbedManyEvent() $this->assertTrue($profile->postUpdate); $this->dm->clear(); - $user = $this->dm->find(__NAMESPACE__ . '\User', $user->id); + $user = $this->dm->find(User::class, $user->id); $profile = $user->profiles[0]; $this->assertTrue($profile->preLoad); @@ -175,7 +176,7 @@ public function testMultipleLevelsOfEmbedded() $this->assertTrue($profile->postUpdate); $this->dm->clear(); - $user = $this->dm->find(__NAMESPACE__ . '\User', $user->id); + $user = $this->dm->find(User::class, $user->id); $profile = $user->profile->profile; $profile->name = '2nd level changed again'; @@ -312,7 +313,7 @@ abstract class BaseDocument public function prePersist(Event\LifecycleEventArgs $e) { $this->prePersist = true; - $this->createdAt = new \DateTime(); + $this->createdAt = new DateTime(); } /** @ODM\PostPersist */ @@ -325,7 +326,7 @@ public function postPersist(Event\LifecycleEventArgs $e) public function preUpdate(Event\PreUpdateEventArgs $e) { $this->preUpdate = true; - $this->updatedAt = new \DateTime(); + $this->updatedAt = new DateTime(); } /** @ODM\PostUpdate */ diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php index f019c2b48d..a89a44d1a7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php @@ -12,6 +12,9 @@ class LifecycleListenersTest extends BaseTest { + /** @var MyEventListener */ + private $listener; + private function getDocumentManager() { $this->listener = new MyEventListener(); @@ -40,8 +43,8 @@ public function testLifecycleListeners() $dm->flush(); $called = [ - Events::prePersist => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], - Events::postPersist => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], + Events::prePersist => [TestDocument::class], + Events::postPersist => [TestDocument::class], ]; $this->assertEquals($called, $this->listener->called); $this->listener->called = []; @@ -52,19 +55,19 @@ public function testLifecycleListeners() $dm->clear(); $called = [ - Events::prePersist => ['Doctrine\ODM\MongoDB\Tests\Events\TestEmbeddedDocument'], - Events::preUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], - Events::postUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], - Events::postPersist => ['Doctrine\ODM\MongoDB\Tests\Events\TestEmbeddedDocument'], + Events::prePersist => [TestEmbeddedDocument::class], + Events::preUpdate => [TestDocument::class], + Events::postUpdate => [TestDocument::class], + Events::postPersist => [TestEmbeddedDocument::class], ]; $this->assertEquals($called, $this->listener->called); $this->listener->called = []; - $document = $dm->find(__NAMESPACE__ . '\TestDocument', $test->id); + $document = $dm->find(TestDocument::class, $test->id); $document->embedded->initialize(); $called = [ - Events::preLoad => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument', 'Doctrine\ODM\MongoDB\Tests\Events\TestEmbeddedDocument'], - Events::postLoad => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument', 'Doctrine\ODM\MongoDB\Tests\Events\TestEmbeddedDocument'], + Events::preLoad => [TestDocument::class, TestEmbeddedDocument::class], + Events::postLoad => [TestDocument::class, TestEmbeddedDocument::class], ]; $this->assertEquals($called, $this->listener->called); $this->listener->called = []; @@ -73,8 +76,8 @@ public function testLifecycleListeners() $dm->flush(); $called = [ - Events::preUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument', 'Doctrine\ODM\MongoDB\Tests\Events\TestEmbeddedDocument'], - Events::postUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument', 'Doctrine\ODM\MongoDB\Tests\Events\TestEmbeddedDocument'], + Events::preUpdate => [TestDocument::class, TestEmbeddedDocument::class], + Events::postUpdate => [TestDocument::class, TestEmbeddedDocument::class], ]; $this->assertEquals($called, $this->listener->called); $this->listener->called = []; @@ -83,8 +86,8 @@ public function testLifecycleListeners() $dm->flush(); $called = [ - Events::preRemove => ['Doctrine\ODM\MongoDB\Tests\Events\TestEmbeddedDocument', 'Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], - Events::postRemove => ['Doctrine\ODM\MongoDB\Tests\Events\TestEmbeddedDocument', 'Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], + Events::preRemove => [TestEmbeddedDocument::class, TestDocument::class], + Events::postRemove => [TestEmbeddedDocument::class, TestDocument::class], ]; $this->assertEquals($called, $this->listener->called); $this->listener->called = []; @@ -103,8 +106,8 @@ public function testLifecycleListeners() $dm->clear(); $called = [ - Events::preUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], - Events::postUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], + Events::preUpdate => [TestDocument::class], + Events::postUpdate => [TestDocument::class], ]; $this->assertEquals($called, $this->listener->called); $this->listener->called = []; @@ -121,17 +124,17 @@ public function testMultipleLevelsOfEmbeddedDocsPrePersist() $dm->flush(); $dm->clear(); - $test = $dm->find(__NAMESPACE__ . '\TestProfile', $test->id); + $test = $dm->find(TestProfile::class, $test->id); $this->listener->called = []; $test->image->thumbnails[] = new Thumbnail('Thumbnail #1'); $dm->flush(); $called = [ - Events::prePersist => ['Doctrine\ODM\MongoDB\Tests\Events\Thumbnail'], - Events::preUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestProfile', 'Doctrine\ODM\MongoDB\Tests\Events\Image'], - Events::postUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestProfile', 'Doctrine\ODM\MongoDB\Tests\Events\Image'], - Events::postPersist => ['Doctrine\ODM\MongoDB\Tests\Events\Thumbnail'], + Events::prePersist => [Thumbnail::class], + Events::preUpdate => [TestProfile::class, Image::class], + Events::postUpdate => [TestProfile::class, Image::class], + Events::postPersist => [Thumbnail::class], ]; $this->assertEquals($called, $this->listener->called); $this->listener->called = []; @@ -139,8 +142,8 @@ public function testMultipleLevelsOfEmbeddedDocsPrePersist() $test->image->thumbnails[0]->name = 'ok'; $dm->flush(); $called = [ - Events::preUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestProfile', 'Doctrine\ODM\MongoDB\Tests\Events\Image', 'Doctrine\ODM\MongoDB\Tests\Events\Thumbnail'], - Events::postUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestProfile', 'Doctrine\ODM\MongoDB\Tests\Events\Image', 'Doctrine\ODM\MongoDB\Tests\Events\Thumbnail'], + Events::preUpdate => [TestProfile::class, Image::class, Thumbnail::class], + Events::postUpdate => [TestProfile::class, Image::class, Thumbnail::class], ]; $this->assertEquals($called, $this->listener->called); $this->listener->called = []; @@ -160,8 +163,8 @@ public function testChangeToReferenceFieldTriggersEvents() $this->listener->called = []; $called = [ - Events::preUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], - Events::postUpdate => ['Doctrine\ODM\MongoDB\Tests\Events\TestDocument'], + Events::preUpdate => [TestDocument::class], + Events::postUpdate => [TestDocument::class], ]; $document = $dm->getRepository(get_class($document))->find($document->id); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/AlsoLoadTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/AlsoLoadTest.php index a14c03a665..4dd9520583 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/AlsoLoadTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/AlsoLoadTest.php @@ -19,9 +19,9 @@ public function testPropertyAlsoLoadDoesNotInterfereWithBasicHydration() 'zip' => 'zip', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertEquals('foo', $document->foo, '"foo" gets its own value and ignores "bar" and "zip"'); $this->assertEquals('bar', $document->bar, '"bar" is hydrated normally'); @@ -32,9 +32,9 @@ public function testPropertyAlsoLoadMayOverwriteDefaultPropertyValue() { $document = ['zip' => 'zip']; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertEquals('zip', $document->zap, '"zap" gets value from "zip", overwriting its default value'); $this->assertEquals('zip', $document->zip, '"zip" is hydrated normally'); @@ -47,9 +47,9 @@ public function testPropertyAlsoLoadShortCircuitsAfterFirstFieldIsFound() 'zip' => 'zip', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertEquals(null, $document->foo, '"foo" gets null value from "bar" and ignores "zip"'); $this->assertEquals('zip', $document->baz, '"baz" gets value from "zip" and ignores "bar"'); @@ -61,9 +61,9 @@ public function testPropertyAlsoLoadChecksMultipleFields() { $document = ['zip' => 'zip']; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertEquals('zip', $document->foo, '"foo" gets value from "zip" since "bar" was missing'); $this->assertNull($document->bar, '"bar" is not hydrated'); @@ -77,9 +77,9 @@ public function testPropertyAlsoLoadBeatsMethodAlsoLoad() 'testOld' => 'testOld', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertEquals('testNew', $document->test, '"test" gets value from "testNew"'); $this->assertEquals('testNew', $document->testNew, '"testNew" is hydrated normally'); @@ -93,9 +93,9 @@ public function testMethodAlsoLoadDoesNotInterfereWithBasicHydration() 'name' => 'Kris Wallsmith', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertEquals('Jonathan', $document->firstName, '"firstName" gets value from exploded "name" but is overwritten with normal hydration'); $this->assertEquals('Wallsmith', $document->lastName, '"lastName" gets value from exploded "name"'); @@ -106,9 +106,9 @@ public function testMethodAlsoLoadMayOverwriteDefaultPropertyValue() { $document = ['testOld' => null]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertNull($document->test, '"test" gets value from "testOld", overwriting its default value'); $this->assertNull($document->testOld, '"testOld" is hydrated normally"'); @@ -123,9 +123,9 @@ public function testMethodAlsoLoadShortCircuitsAfterFirstFieldIsFound() 'testOlder' => 'testOlder', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertEquals('Jonathan Wage', $document->name, '"name" is hydrated normally'); $this->assertEquals('Kris Wallsmith', $document->fullName, '"fullName" is hydrated normally'); @@ -144,9 +144,9 @@ public function testMethodAlsoLoadChecksMultipleFields() 'testOlder' => 'testOlder', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadDocument::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadDocument')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadDocument::class)->findOneBy([]); $this->assertNull($document->name, '"name" is not hydrated'); $this->assertEquals('Kris Wallsmith', $document->fullName, '"fullName" is hydrated normally'); @@ -169,7 +169,7 @@ public function testNotSaved() $this->dm->persist($document); $this->dm->flush(); - $document = $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadDocument')->findOne(); + $document = $this->dm->getDocumentCollection(AlsoLoadDocument::class)->findOne(); $this->assertEquals('Jonathan', $document['firstName'], '"firstName" is hydrated normally'); $this->assertEquals('Wage', $document['lastName'], '"lastName" is hydrated normally'); @@ -186,9 +186,9 @@ public function testMethodAlsoLoadParentInheritance() 'testOlder' => 'testOlder', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadChild')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadChild::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadChild')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadChild::class)->findOneBy([]); $this->assertEquals('buzz', $document->fizz, '"fizz" gets value from "buzz"'); $this->assertEquals('test', $document->test, '"test" is hydrated normally, since "testOldest" was missing and parent method was overridden'); @@ -201,9 +201,9 @@ public function testMethodAlsoLoadGrandparentInheritance() 'testReallyOldest' => 'testReallyOldest', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\AlsoLoadGrandchild')->insertOne($document); + $this->dm->getDocumentCollection(AlsoLoadGrandchild::class)->insertOne($document); - $document = $this->dm->getRepository(__NAMESPACE__ . '\AlsoLoadGrandchild')->findOneBy([]); + $document = $this->dm->getRepository(AlsoLoadGrandchild::class)->findOneBy([]); $this->assertEquals('buzz', $document->fizz, '"fizz" gets value from "buzz"'); $this->assertEquals('testReallyOldest', $document->test, '"test" gets value from "testReallyOldest"'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionPersisterTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionPersisterTest.php index 091de2695e..0c6ab233b7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionPersisterTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionPersisterTest.php @@ -19,7 +19,7 @@ public function testDeleteReferenceMany() $user = $this->getTestUser('jwage'); $persister->delete($user->phonenumbers, []); - $user = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $user = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertArrayNotHasKey('phonenumbers', $user, 'Test that the phonenumbers field was deleted'); } @@ -29,7 +29,7 @@ public function testDeleteEmbedMany() $user = $this->getTestUser('jwage'); $persister->delete($user->categories, []); - $user = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $user = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertArrayNotHasKey('categories', $user, 'Test that the categories field was deleted'); } @@ -41,7 +41,7 @@ public function testDeleteNestedEmbedMany() $persister->delete($user->categories[0]->children[0]->children, []); $persister->delete($user->categories[0]->children[1]->children, []); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $check = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertFalse(isset($check['categories']['0']['children'][0]['children'])); $this->assertFalse(isset($check['categories']['0']['children'][1]['children'])); @@ -49,7 +49,7 @@ public function testDeleteNestedEmbedMany() $persister->delete($user->categories[0]->children, []); $persister->delete($user->categories[1]->children, []); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $check = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertFalse(isset($check['categories'][0]['children']), 'Test that the nested children categories field was deleted'); $this->assertTrue(isset($check['categories'][0]), 'Test that the category with the children still exists'); @@ -74,7 +74,7 @@ public function testDeleteRows() $this->dm->flush(); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $check = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertFalse(isset($check['phonenumbers'][0])); $this->assertFalse(isset($check['phonenumbers'][1])); @@ -89,7 +89,7 @@ public function testDeleteRows() unset($user->categories[1]); $this->dm->flush(); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $check = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertFalse(isset($check['categories'][0])); $this->assertFalse(isset($check['categories'][1])); } @@ -101,7 +101,7 @@ public function testInsertRows() $user->phonenumbers[] = new CollectionPersisterPhonenumber('6155139185'); $this->dm->flush(); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $check = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertCount(4, $check['phonenumbers']); $this->assertEquals((string) $check['phonenumbers'][2]['$id'], $user->phonenumbers[2]->id); $this->assertEquals((string) $check['phonenumbers'][3]['$id'], $user->phonenumbers[3]->id); @@ -110,7 +110,7 @@ public function testInsertRows() $user->categories[] = new CollectionPersisterCategory('Test'); $this->dm->flush(); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $check = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertCount(4, $check['categories']); $user->categories[3]->children[0] = new CollectionPersisterCategory('Test'); @@ -119,7 +119,7 @@ public function testInsertRows() $user->categories[3]->children[1]->children[1] = new CollectionPersisterCategory('Test'); $this->dm->flush(); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterUser')->findOne(['username' => 'jwage']); + $check = $this->dm->getDocumentCollection(CollectionPersisterUser::class)->findOne(['username' => 'jwage']); $this->assertCount(2, $check['categories'][3]['children']); $this->assertCount(2, $check['categories'][3]['children']['1']['children']); } @@ -172,7 +172,7 @@ public function testNestedEmbedManySetStrategy() $this->dm->persist($post); $this->dm->flush(); - $doc = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterPost')->findOne(['post' => 'postA']); + $doc = $this->dm->getDocumentCollection(CollectionPersisterPost::class)->findOne(['post' => 'postA']); $this->assertCount(1, $doc['comments']); $this->assertEquals($commentA->comment, $doc['comments']['a']['comment']); @@ -193,7 +193,7 @@ public function testNestedEmbedManySetStrategy() $this->dm->persist($post); $this->dm->flush(); - $doc = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterPost')->findOne(['post' => 'postA']); + $doc = $this->dm->getDocumentCollection(CollectionPersisterPost::class)->findOne(['post' => 'postA']); $this->assertCount(2, $doc['comments']); $this->assertEquals($commentA->comment, $doc['comments']['a']['comment']); @@ -213,7 +213,7 @@ public function testNestedEmbedManySetStrategy() $this->dm->persist($post); $this->dm->flush(); - $doc = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterPost')->findOne(['post' => 'postA']); + $doc = $this->dm->getDocumentCollection(CollectionPersisterPost::class)->findOne(['post' => 'postA']); $this->assertCount(2, $doc['comments']); $this->assertEquals($commentA->comment, $doc['comments']['a']['comment']); @@ -230,7 +230,7 @@ public function testNestedEmbedManySetStrategy() $this->dm->persist($post); $this->dm->flush(); - $doc = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CollectionPersisterPost')->findOne(['post' => 'postA']); + $doc = $this->dm->getDocumentCollection(CollectionPersisterPost::class)->findOne(['post' => 'postA']); $this->assertCount(1, $doc['comments']); $this->assertEquals($commentA->comment, $doc['comments']['a']['comment']); 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/CustomFieldNameTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomFieldNameTest.php index 3cde001660..cd4c29eae7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomFieldNameTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomFieldNameTest.php @@ -17,7 +17,7 @@ public function testInsertSetsLoginInsteadOfUsername() $this->dm->persist($test); $this->dm->flush(); - $test = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CustomFieldName')->findOne(); + $test = $this->dm->getDocumentCollection(CustomFieldName::class)->findOne(); $this->assertArrayHasKey('login', $test); $this->assertEquals('test', $test['login']); } @@ -31,7 +31,7 @@ public function testHydration() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->find(__NAMESPACE__ . '\CustomFieldName', $test->id); + $test = $this->dm->find(CustomFieldName::class, $test->id); $this->assertNotNull($test); $this->assertEquals('test', $test->username); } @@ -45,12 +45,12 @@ public function testUpdateSetsLoginInsteadOfUsername() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->find(__NAMESPACE__ . '\CustomFieldName', $test->id); + $test = $this->dm->find(CustomFieldName::class, $test->id); $test->username = 'ok'; $this->dm->flush(); - $test = $this->dm->getDocumentCollection(__NAMESPACE__ . '\CustomFieldName')->findOne(); + $test = $this->dm->getDocumentCollection(CustomFieldName::class)->findOne(); $this->assertArrayHasKey('login', $test); $this->assertEquals('ok', $test['login']); } @@ -64,7 +64,7 @@ public function testFindOneQueryIsPrepared() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getRepository(__NAMESPACE__ . '\CustomFieldName')->findOneBy(['username' => 'test']); + $test = $this->dm->getRepository(CustomFieldName::class)->findOneBy(['username' => 'test']); $this->assertNotNull($test); $this->assertEquals('test', $test->username); } @@ -78,7 +78,7 @@ public function testFindQueryIsPrepared() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getRepository(__NAMESPACE__ . '\CustomFieldName')->findOneBy(['username' => 'test']); + $test = $this->dm->getRepository(CustomFieldName::class)->findOneBy(['username' => 'test']); $this->assertNotNull($test); $this->assertEquals('test', $test->username); } @@ -92,7 +92,7 @@ public function testQueryBuilderAndDqlArePrepared() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\CustomFieldName')->field('username')->equals('test'); + $qb = $this->dm->createQueryBuilder(CustomFieldName::class)->field('username')->equals('test'); $query = $qb->getQuery(); $test = $query->getSingleResult(); $this->assertNotNull($test); 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/CustomTypeTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomTypeTest.php index 5f2a4360cb..de4880e240 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomTypeTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomTypeTest.php @@ -16,7 +16,7 @@ class CustomTypeTest extends BaseTest { public static function setUpBeforeClass() { - Type::addType('date_collection', __NAMESPACE__ . '\DateCollectionType'); + Type::addType('date_collection', DateCollectionType::class); } public function testCustomTypeValueConversions() @@ -29,7 +29,7 @@ public function testCustomTypeValueConversions() $this->dm->clear(); - $country = $this->dm->find(__NAMESPACE__ . '\Country', $country->id); + $country = $this->dm->find(Country::class, $country->id); $this->assertContainsOnly('DateTime', $country->nationalHolidays); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DatabasesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DatabasesTest.php index 2ed1efc757..7c95a449b6 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DatabasesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DatabasesTest.php @@ -11,12 +11,12 @@ class DatabasesTest extends BaseTest { public function testCustomDatabase() { - $this->assertEquals('test_custom', $this->dm->getDocumentDatabase(__NAMESPACE__ . '\CustomDatabaseTest')->getDatabaseName()); + $this->assertEquals('test_custom', $this->dm->getDocumentDatabase(CustomDatabaseTest::class)->getDatabaseName()); } public function testDefaultDatabase() { - $this->assertEquals('test_default', $this->dm->getDocumentDatabase(__NAMESPACE__ . '\DefaultDatabaseTest')->getDatabaseName()); + $this->assertEquals('test_default', $this->dm->getDocumentDatabase(DefaultDatabaseTest::class)->getDatabaseName()); } protected function getConfiguration() 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/DiscriminatorsDefaultValueTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DiscriminatorsDefaultValueTest.php index d261ac66f9..739aff6c77 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DiscriminatorsDefaultValueTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DiscriminatorsDefaultValueTest.php @@ -29,21 +29,21 @@ public function testLoadDocumentWithDefaultValue() $this->dm->flush(); $this->dm->clear(); - $childWithDiscriminator = $this->dm->find(__NAMESPACE__ . '\ChildDocumentWithDiscriminator', $firstChildWithoutDiscriminator->getId()); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorSimple', $childWithDiscriminator); + $childWithDiscriminator = $this->dm->find(ChildDocumentWithDiscriminator::class, $firstChildWithoutDiscriminator->getId()); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorSimple::class, $childWithDiscriminator); $this->assertSame('firstWithoutDiscriminator', $childWithDiscriminator->getType(), 'New mapping correctly loads legacy document'); - $parentWithDiscriminator = $this->dm->find(__NAMESPACE__ . '\ParentDocumentWithDiscriminator', $parentWithoutDiscriminator->getId()); + $parentWithDiscriminator = $this->dm->find(ParentDocumentWithDiscriminator::class, $parentWithoutDiscriminator->getId()); $this->assertNotNull($parentWithDiscriminator); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorSimple', $parentWithDiscriminator->getReferencedChild(), 'Referenced document correctly respects defaultDiscriminatorValue in referenceOne mapping'); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorSimple', $parentWithDiscriminator->getEmbeddedChild(), 'Embedded document correctly respects defaultDiscriminatorValue in referenceOne mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorSimple::class, $parentWithDiscriminator->getReferencedChild(), 'Referenced document correctly respects defaultDiscriminatorValue in referenceOne mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorSimple::class, $parentWithDiscriminator->getEmbeddedChild(), 'Embedded document correctly respects defaultDiscriminatorValue in referenceOne mapping'); foreach ($parentWithDiscriminator->getReferencedChildren() as $child) { - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorSimple', $child, 'Referenced document correctly respects defaultDiscriminatorValue in referenceMany mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorSimple::class, $child, 'Referenced document correctly respects defaultDiscriminatorValue in referenceMany mapping'); } foreach ($parentWithDiscriminator->getEmbeddedChildren() as $child) { - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorSimple', $child, 'Embedded document correctly respects defaultDiscriminatorValue in referenceMany mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorSimple::class, $child, 'Embedded document correctly respects defaultDiscriminatorValue in referenceMany mapping'); } } @@ -61,25 +61,25 @@ public function testLoadDocumentWithDifferentChild() $this->dm->flush(); $this->dm->clear(); - $parentWithDiscriminator = $this->dm->find(__NAMESPACE__ . '\ParentDocumentWithDiscriminator', $parentWithDiscriminator->getId()); + $parentWithDiscriminator = $this->dm->find(ParentDocumentWithDiscriminator::class, $parentWithDiscriminator->getId()); $this->assertNotNull($parentWithDiscriminator); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorComplex', $parentWithDiscriminator->getReferencedChild(), 'Referenced document respects discriminatorValue if it is present in referenceOne mapping'); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorComplex', $parentWithDiscriminator->getEmbeddedChild(), 'Embedded document respects discriminatorValue if it is present in referenceOne mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorComplex::class, $parentWithDiscriminator->getReferencedChild(), 'Referenced document respects discriminatorValue if it is present in referenceOne mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorComplex::class, $parentWithDiscriminator->getEmbeddedChild(), 'Embedded document respects discriminatorValue if it is present in referenceOne mapping'); // Check referenceMany mapping $referencedChildren = $parentWithDiscriminator->getReferencedChildren()->toArray(); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorComplex', $referencedChildren[0], 'Referenced document respects discriminatorValue if it is present in referenceMany mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorComplex::class, $referencedChildren[0], 'Referenced document respects discriminatorValue if it is present in referenceMany mapping'); $this->assertSame('firstWithDiscriminator', $referencedChildren[0]->getType()); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorSimple', $referencedChildren[1], 'Referenced document respects discriminatorValue if it is present in referenceMany mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorSimple::class, $referencedChildren[1], 'Referenced document respects discriminatorValue if it is present in referenceMany mapping'); $this->assertSame('secondWithDiscriminator', $referencedChildren[1]->getType()); // Check embedMany mapping $referencedChildren = $parentWithDiscriminator->getEmbeddedChildren()->toArray(); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorComplex', $referencedChildren[0], 'Referenced document respects discriminatorValue if it is present in referenceMany mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorComplex::class, $referencedChildren[0], 'Referenced document respects discriminatorValue if it is present in referenceMany mapping'); $this->assertSame('firstWithDiscriminator', $referencedChildren[0]->getType()); - $this->assertInstanceOf(__NAMESPACE__ . '\ChildDocumentWithDiscriminatorSimple', $referencedChildren[1], 'Referenced document respects discriminatorValue if it is present in referenceMany mapping'); + $this->assertInstanceOf(ChildDocumentWithDiscriminatorSimple::class, $referencedChildren[1], 'Referenced document respects discriminatorValue if it is present in referenceMany mapping'); $this->assertSame('secondWithDiscriminator', $referencedChildren[1]->getType()); } } 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/EmbeddedReferenceTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedReferenceTest.php index 2fbdc0754b..661edc9c74 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedReferenceTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedReferenceTest.php @@ -48,7 +48,7 @@ public function testReferencedDocumentInsideEmbeddedDocument() $this->dm->flush(); $this->dm->clear(); - $offer = $this->dm->getRepository(__NAMESPACE__ . '\Offer')->findOneBy(['name' => 'My Offer']); + $offer = $this->dm->getRepository(Offer::class)->findOneBy(['name' => 'My Offer']); // Should be: 1 Link, 5 referenced documents // Actual Result: 1 link, 10 referenced documents diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php index dc3ae2363b..ca7a73cc84 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\PersistentCollection; use Doctrine\ODM\MongoDB\Tests\BaseTest; use Documents\Address; use Documents\Functional\EmbeddedTestLevel0; @@ -35,7 +36,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 +50,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 +63,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 +74,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 +107,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 +143,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 +161,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(); @@ -242,7 +243,7 @@ public function testRemoveEmbeddedManyDocument() ->getQuery() ->getSingleResult(); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\PersistentCollection', $test->level1); + $this->assertInstanceOf(PersistentCollection::class, $test->level1); // verify that test has no more level1 $this->assertEquals(0, $test->level1->count()); @@ -382,7 +383,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 +391,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 +415,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 +447,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 +465,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..dbdd181883 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FunctionalTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FunctionalTest.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\PersistentCollection; use Doctrine\ODM\MongoDB\Tests\BaseTest; use Documents\Account; @@ -29,14 +30,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 +50,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 +122,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 +142,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 +162,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 +172,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 +185,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 +207,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 +223,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 +231,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 +248,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 +278,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 +293,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 +309,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 +325,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 +341,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 +357,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 +366,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 +375,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 +416,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 +430,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 +439,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 +461,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 +482,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 +491,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 +499,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 +537,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,11 +555,11 @@ 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(); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\ClassMetadata', $collection->getTypeClass()); + $this->assertInstanceOf(ClassMetadata::class, $collection->getTypeClass()); } public function testFavoritesReference() @@ -588,24 +594,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 +635,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 +649,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 +677,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 +715,8 @@ public function testSameCollectionTest() public function testNotSameCollectionThrowsException() { $test = $this->dm->createQueryBuilder([ - 'Documents\User', - 'Documents\Profile', + User::class, + Profile::class, ])->getQuery()->execute(); } @@ -739,12 +745,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 +772,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 +787,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 +811,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 +826,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 +849,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 +867,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/IdTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdTest.php index 313819917f..e676e7571f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdTest.php @@ -4,6 +4,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional; +use Doctrine\ODM\MongoDB\Id\UuidGenerator; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Tests\BaseTest; @@ -31,15 +32,15 @@ public function testUuidId() $id = $user->id; $this->dm->clear(); - $check1 = $this->dm->getRepository(__NAMESPACE__ . '\UuidUser')->findOneBy(['id' => $id]); + $check1 = $this->dm->getRepository(UuidUser::class)->findOneBy(['id' => $id]); $this->assertNotNull($check1); - $check2 = $this->dm->createQueryBuilder(__NAMESPACE__ . '\UuidUser') + $check2 = $this->dm->createQueryBuilder(UuidUser::class) ->field('id')->equals($id)->getQuery()->getSingleResult(); $this->assertNotNull($check2); $this->assertSame($check1, $check2); - $check3 = $this->dm->createQueryBuilder(__NAMESPACE__ . '\UuidUser') + $check3 = $this->dm->createQueryBuilder(UuidUser::class) ->field('name')->equals('Jonathan H. Wage')->getQuery()->getSingleResult(); $this->assertNotNull($check3); $this->assertSame($check2, $check3); @@ -54,15 +55,15 @@ public function testAlnumIdChars() $this->dm->flush(); $this->dm->clear(); - $check1 = $this->dm->getRepository(__NAMESPACE__ . '\AlnumCharsUser')->findOneBy(['id' => 'x']); + $check1 = $this->dm->getRepository(AlnumCharsUser::class)->findOneBy(['id' => 'x']); $this->assertNotNull($check1); - $check2 = $this->dm->createQueryBuilder(__NAMESPACE__ . '\AlnumCharsUser') + $check2 = $this->dm->createQueryBuilder(AlnumCharsUser::class) ->field('id')->equals('x')->getQuery()->getSingleResult(); $this->assertNotNull($check2); $this->assertSame($check1, $check2); - $check3 = $this->dm->createQueryBuilder(__NAMESPACE__ . '\AlnumCharsUser') + $check3 = $this->dm->createQueryBuilder(AlnumCharsUser::class) ->field('name')->equals('Kathrine R. Cage')->getQuery()->getSingleResult(); $this->assertNotNull($check3); $this->assertSame($check2, $check3); @@ -90,15 +91,15 @@ public function testCollectionId() $this->assertEquals($reference1->id, 1); $this->assertEquals($reference2->id, 2); - $check1 = $this->dm->getRepository(__NAMESPACE__ . '\CollectionIdUser')->findOneBy(['id' => $user1->id]); - $check2 = $this->dm->getRepository(__NAMESPACE__ . '\CollectionIdUser')->findOneBy(['id' => $user2->id]); + $check1 = $this->dm->getRepository(CollectionIdUser::class)->findOneBy(['id' => $user1->id]); + $check2 = $this->dm->getRepository(CollectionIdUser::class)->findOneBy(['id' => $user2->id]); $this->assertNotNull($check1); $this->assertNotNull($check2); $this->assertEquals('referenced 1', $check1->reference->getName()); $this->assertEquals('referenced 2', $check2->reference->getName()); - $check = $this->dm->getRepository(__NAMESPACE__ . '\CollectionIdUser')->find($user1->id); + $check = $this->dm->getRepository(CollectionIdUser::class)->find($user1->id); $this->assertNotNull($check); } @@ -142,10 +143,10 @@ public function testEmbeddedDocumentWithId() public function testIdGeneratorInstance() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\UuidUser'); + $class = $this->dm->getClassMetadata(UuidUser::class); $this->assertEquals(ClassMetadata::GENERATOR_TYPE_UUID, $class->generatorType); $this->assertEquals(['salt' => 'test'], $class->generatorOptions); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Id\UuidGenerator', $class->idGenerator); + $this->assertInstanceOf(UuidGenerator::class, $class->idGenerator); $this->assertEquals('test', $class->idGenerator->getSalt()); $serialized = serialize($class); @@ -153,7 +154,7 @@ public function testIdGeneratorInstance() $this->assertEquals(ClassMetadata::GENERATOR_TYPE_UUID, $class->generatorType); $this->assertEquals(['salt' => 'test'], $class->generatorOptions); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Id\UuidGenerator', $class->idGenerator); + $this->assertInstanceOf(UuidGenerator::class, $class->idGenerator); $this->assertEquals('test', $class->idGenerator->getSalt()); } @@ -178,8 +179,8 @@ public function testEqualButNotIdenticalIds($user1Id, $user2Id) $this->assertSame($user1->id, $user1Id); $this->assertSame($user2->id, $user2Id); - $user1 = $this->dm->find(__NAMESPACE__ . '\CustomIdUser', $user1Id); - $user2 = $this->dm->find(__NAMESPACE__ . '\CustomIdUser', $user2Id); + $user1 = $this->dm->find(CustomIdUser::class, $user1Id); + $user2 = $this->dm->find(CustomIdUser::class, $user2Id); $this->assertNotSame($user1, $user2); $this->assertSame($user1->id, $user1Id); 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/IndexesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IndexesTest.php index 91f886b145..4f1cbef125 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/IndexesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IndexesTest.php @@ -11,7 +11,6 @@ class IndexesTest extends BaseTest { private function uniqueTest($class) { - $class = __NAMESPACE__ . '\\' . $class; $this->dm->getSchemaManager()->ensureDocumentIndexes($class); $test = new $class(); @@ -36,7 +35,7 @@ private function uniqueTest($class) public function testEmbeddedIndexes() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\DocumentWithEmbeddedIndexes'); + $class = $this->dm->getClassMetadata(DocumentWithEmbeddedIndexes::class); $sm = $this->dm->getSchemaManager(); $indexes = $sm->getDocumentIndexes($class->name); @@ -55,7 +54,7 @@ public function testEmbeddedIndexes() public function testDiscriminatedEmbeddedIndexes() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\DocumentWithIndexInDiscriminatedEmbeds'); + $class = $this->dm->getClassMetadata(DocumentWithIndexInDiscriminatedEmbeds::class); $sm = $this->dm->getSchemaManager(); $indexes = $sm->getDocumentIndexes($class->name); @@ -71,7 +70,7 @@ public function testDiscriminatedEmbeddedIndexes() public function testDiscriminatorIndexes() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\DocumentWithDiscriminatorIndex'); + $class = $this->dm->getClassMetadata(DocumentWithDiscriminatorIndex::class); $sm = $this->dm->getSchemaManager(); $indexes = $sm->getDocumentIndexes($class->name); @@ -81,35 +80,35 @@ public function testDiscriminatorIndexes() public function testIndexDefinitions() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\UniqueOnFieldTest'); + $class = $this->dm->getClassMetadata(UniqueOnFieldTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); $this->assertTrue(isset($indexes[0]['options']['unique'])); $this->assertEquals(true, $indexes[0]['options']['unique']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\UniqueOnDocumentTest'); + $class = $this->dm->getClassMetadata(UniqueOnDocumentTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); $this->assertTrue(isset($indexes[0]['options']['unique'])); $this->assertEquals(true, $indexes[0]['options']['unique']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\IndexesOnDocumentTest'); + $class = $this->dm->getClassMetadata(IndexesOnDocumentTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); $this->assertTrue(isset($indexes[0]['options']['unique'])); $this->assertEquals(true, $indexes[0]['options']['unique']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\PartialIndexOnDocumentTest'); + $class = $this->dm->getClassMetadata(PartialIndexOnDocumentTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); $this->assertTrue(isset($indexes[0]['options']['partialFilterExpression'])); $this->assertSame(['counter' => ['$gt' => 5]], $indexes[0]['options']['partialFilterExpression']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\UniqueSparseOnFieldTest'); + $class = $this->dm->getClassMetadata(UniqueSparseOnFieldTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); @@ -118,7 +117,7 @@ public function testIndexDefinitions() $this->assertTrue(isset($indexes[0]['options']['sparse'])); $this->assertEquals(true, $indexes[0]['options']['sparse']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\UniqueSparseOnDocumentTest'); + $class = $this->dm->getClassMetadata(UniqueSparseOnDocumentTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); @@ -127,7 +126,7 @@ public function testIndexDefinitions() $this->assertTrue(isset($indexes[0]['options']['sparse'])); $this->assertEquals(true, $indexes[0]['options']['sparse']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\SparseIndexesOnDocumentTest'); + $class = $this->dm->getClassMetadata(SparseIndexesOnDocumentTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); @@ -136,7 +135,7 @@ public function testIndexDefinitions() $this->assertTrue(isset($indexes[0]['options']['sparse'])); $this->assertEquals(true, $indexes[0]['options']['sparse']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\MultipleFieldsUniqueIndexTest'); + $class = $this->dm->getClassMetadata(MultipleFieldsUniqueIndexTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); @@ -145,7 +144,7 @@ public function testIndexDefinitions() $this->assertTrue(isset($indexes[0]['options']['unique'])); $this->assertEquals(true, $indexes[0]['options']['unique']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\MultipleFieldsUniqueSparseIndexTest'); + $class = $this->dm->getClassMetadata(MultipleFieldsUniqueSparseIndexTest::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); @@ -156,7 +155,7 @@ public function testIndexDefinitions() $this->assertTrue(isset($indexes[0]['options']['sparse'])); $this->assertEquals(true, $indexes[0]['options']['sparse']); - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\MultipleFieldIndexes'); + $class = $this->dm->getClassMetadata(MultipleFieldIndexes::class); $indexes = $class->getIndexes(); $this->assertTrue(isset($indexes[0]['keys']['username'])); $this->assertEquals(1, $indexes[0]['keys']['username']); @@ -176,7 +175,7 @@ public function testIndexDefinitions() */ public function testUniqueIndexOnField() { - $this->uniqueTest('UniqueOnFieldTest'); + $this->uniqueTest(UniqueOnFieldTest::class); } /** @@ -185,7 +184,7 @@ public function testUniqueIndexOnField() */ public function testUniqueIndexOnDocument() { - $this->uniqueTest('UniqueOnDocumentTest'); + $this->uniqueTest(UniqueOnDocumentTest::class); } /** @@ -194,7 +193,7 @@ public function testUniqueIndexOnDocument() */ public function testIndexesOnDocument() { - $this->uniqueTest('IndexesOnDocumentTest'); + $this->uniqueTest(IndexesOnDocumentTest::class); } /** @@ -203,7 +202,7 @@ public function testIndexesOnDocument() */ public function testMultipleFieldsUniqueIndexOnDocument() { - $this->uniqueTest('MultipleFieldsUniqueIndexTest'); + $this->uniqueTest(MultipleFieldsUniqueIndexTest::class); } /** @@ -212,14 +211,14 @@ public function testMultipleFieldsUniqueIndexOnDocument() */ public function testMultipleFieldIndexes() { - $this->uniqueTest('MultipleFieldIndexes'); + $this->uniqueTest(MultipleFieldIndexes::class); } public function testPartialIndexCreation() { $this->requireMongoDB32('This test is not applicable to server versions < 3.2.0'); - $className = __NAMESPACE__ . '\PartialIndexOnDocumentTest'; + $className = PartialIndexOnDocumentTest::class; $this->dm->getSchemaManager()->ensureDocumentIndexes($className); $indexes = $this->dm->getSchemaManager()->getDocumentIndexes($className); 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/LifecycleTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/LifecycleTest.php index b2a9b94311..78ed76895e 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/LifecycleTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/LifecycleTest.php @@ -26,7 +26,7 @@ public function testEventOnDoubleFlush() $this->dm->clear(); - $parent = $this->dm->getRepository(__NAMESPACE__ . '\ParentObject')->find($parent->getId()); + $parent = $this->dm->getRepository(ParentObject::class)->find($parent->getId()); $this->assertNotNull($parent); $this->assertEquals('parent #changed', $parent->getName()); $this->assertCount(1, $parent->getChildren()); @@ -45,7 +45,7 @@ public function testEventEmptyFlush() $this->dm->flush(); $this->dm->clear(); - $parent = $this->dm->getRepository(__NAMESPACE__ . '\ParentObject')->find($parent->getId()); + $parent = $this->dm->getRepository(ParentObject::class)->find($parent->getId()); $this->assertNotNull($parent); $this->assertCount(1, $parent->getChildren()); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/LockTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/LockTest.php index 04149ee385..474ffb64e3 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/LockTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/LockTest.php @@ -256,7 +256,7 @@ public function testPessimisticReadLockThrowsExceptionOnRemove() $this->dm->persist($article); $this->dm->flush(); - $coll = $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt'); + $coll = $this->dm->getDocumentCollection(LockInt::class); $coll->replaceOne(['_id' => new ObjectId($article->id)], ['locked' => LockMode::PESSIMISTIC_READ]); $this->expectException(LockException::class); @@ -273,7 +273,7 @@ public function testPessimisticReadLockThrowsExceptionOnUpdate() $this->dm->persist($article); $this->dm->flush(); - $coll = $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt'); + $coll = $this->dm->getDocumentCollection(LockInt::class); $coll->replaceOne(['_id' => new ObjectId($article->id)], ['locked' => LockMode::PESSIMISTIC_READ]); $this->expectException(LockException::class); @@ -290,7 +290,7 @@ public function testPessimisticWriteLockThrowExceptionOnRemove() $this->dm->persist($article); $this->dm->flush(); - $coll = $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt'); + $coll = $this->dm->getDocumentCollection(LockInt::class); $coll->replaceOne(['_id' => new ObjectId($article->id)], ['locked' => LockMode::PESSIMISTIC_WRITE]); $this->expectException(LockException::class); @@ -307,7 +307,7 @@ public function testPessimisticWriteLockThrowExceptionOnUpdate() $this->dm->persist($article); $this->dm->flush(); - $coll = $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt'); + $coll = $this->dm->getDocumentCollection(LockInt::class); $coll->replaceOne(['_id' => new ObjectId($article->id)], ['locked' => LockMode::PESSIMISTIC_WRITE]); $this->expectException(LockException::class); @@ -324,13 +324,13 @@ public function testPessimisticWriteLockThrowExceptionOnRead() $this->dm->persist($article); $this->dm->flush(); - $coll = $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt'); + $coll = $this->dm->getDocumentCollection(LockInt::class); $coll->replaceOne(['_id' => new ObjectId($article->id)], ['locked' => LockMode::PESSIMISTIC_WRITE]); $this->expectException(LockException::class); $this->dm->clear(); - $article = $this->dm->find(__NAMESPACE__ . '\LockInt', $article->id); + $article = $this->dm->find(LockInt::class, $article->id); } public function testPessimisticReadLockFunctional() @@ -346,7 +346,7 @@ public function testPessimisticReadLockFunctional() $article->title = 'test'; $this->dm->flush(); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt')->findOne(); + $check = $this->dm->getDocumentCollection(LockInt::class)->findOne(); $this->assertEquals(2, $check['version']); $this->assertArrayNotHasKey('locked', $check); $this->assertEquals('test', $check['title']); @@ -365,7 +365,7 @@ public function testPessimisticWriteLockFunctional() $article->title = 'test'; $this->dm->flush(); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt')->findOne(); + $check = $this->dm->getDocumentCollection(LockInt::class)->findOne(); $this->assertEquals(2, $check['version']); $this->assertArrayNotHasKey('locked', $check); $this->assertEquals('test', $check['title']); @@ -375,14 +375,14 @@ public function testInvalidLockDocument() { $this->expectException(MongoDBException::class); $this->expectExceptionMessage('Invalid lock field type string. Lock field must be int.'); - $this->dm->getClassMetadata(__NAMESPACE__ . '\InvalidLockDocument'); + $this->dm->getClassMetadata(InvalidLockDocument::class); } public function testInvalidVersionDocument() { $this->expectException(MongoDBException::class); $this->expectExceptionMessage('Invalid version field type string. Version field must be int or date.'); - $this->dm->getClassMetadata(__NAMESPACE__ . '\InvalidVersionDocument'); + $this->dm->getClassMetadata(InvalidVersionDocument::class); } /** @@ -396,7 +396,7 @@ public function testUpdatingCollectionRespectsVersionNumber() $this->dm->flush(); // simulate another request updating document in the meantime - $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt')->updateOne( + $this->dm->getDocumentCollection(LockInt::class)->updateOne( ['_id' => new ObjectId($d->id)], ['$set' => ['version' => 2]] ); @@ -416,7 +416,7 @@ public function testDeletingCollectionRespectsVersionNumber() $this->dm->flush(); // simulate another request updating document in the meantime - $this->dm->getDocumentCollection(__NAMESPACE__ . '\LockInt')->updateOne( + $this->dm->getDocumentCollection(LockInt::class)->updateOne( ['_id' => new ObjectId($d->id)], ['$set' => ['version' => 2]] ); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/MappedSuperclassTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/MappedSuperclassTest.php index f6d190b3b3..aea4d163ad 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/MappedSuperclassTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/MappedSuperclassTest.php @@ -27,12 +27,12 @@ public function testCRUD() $this->dm->flush(); $this->dm->clear(); - $e2 = $this->dm->find('Doctrine\ODM\MongoDB\Tests\Functional\DocumentSubClass', 1); + $e2 = $this->dm->find(DocumentSubClass::class, 1); $this->assertNotNull($e2); $this->assertEquals(1, $e2->getId()); $this->assertEquals('Roman', $e2->getName()); $this->assertNotNull($e2->getMappedRelated1()); - $this->assertInstanceOf(__NAMESPACE__ . '\MappedSuperclassRelated1', $e2->getMappedRelated1()); + $this->assertInstanceOf(MappedSuperclassRelated1::class, $e2->getMappedRelated1()); $this->assertEquals(42, $e2->getMapped1()); $this->assertEquals('bar', $e2->getMapped2()); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php index 0f2b32004b..966bcaca7a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php @@ -33,14 +33,14 @@ public function testSimple() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getDocumentCollection(__NAMESPACE__ . '\Order')->findOne(); + $test = $this->dm->getDocumentCollection(Order::class)->findOne(); $this->assertInstanceOf(ObjectId::class, $test['product']['_id']); $this->assertEquals('Order', $test['title']); $this->assertEquals('Product', $test['product']['title']); - $doc = $this->dm->find(__NAMESPACE__ . '\Order', $order->id); - $this->assertInstanceOf(__NAMESPACE__ . '\Order', $order); + $doc = $this->dm->find(Order::class, $order->id); + $this->assertInstanceOf(Order::class, $order); $this->assertInternalType('string', $doc->product->id); $this->assertEquals((string) $test['product']['_id'], $doc->product->id); $this->assertEquals('Order', $doc->title); @@ -48,22 +48,22 @@ public function testSimple() $this->dm->clear(); - $order = $this->dm->find(__NAMESPACE__ . '\Order', $order->id); - $this->assertInstanceOf(__NAMESPACE__ . '\Order', $order); + $order = $this->dm->find(Order::class, $order->id); + $this->assertInstanceOf(Order::class, $order); - $product = $this->dm->find(__NAMESPACE__ . '\Product', $product->id); - $this->assertInstanceOf(__NAMESPACE__ . '\Product', $product); + $product = $this->dm->find(Product::class, $product->id); + $this->assertInstanceOf(Product::class, $product); $order->product->title = 'tesgttttt'; $this->dm->flush(); $this->dm->clear(); - $test1 = $this->dm->getDocumentCollection(__NAMESPACE__ . '\Product')->findOne(); - $test2 = $this->dm->getDocumentCollection(__NAMESPACE__ . '\Order')->findOne(); + $test1 = $this->dm->getDocumentCollection(Product::class)->findOne(); + $test2 = $this->dm->getDocumentCollection(Order::class)->findOne(); $this->assertNotEquals($test1['title'], $test2['product']['title']); - $order = $this->dm->find(__NAMESPACE__ . '\Order', $order->id); - $product = $this->dm->find(__NAMESPACE__ . '\Product', $product->id); + $order = $this->dm->find(Order::class, $order->id); + $product = $this->dm->find(Product::class, $product->id); $this->assertNotEquals($product->title, $order->product->title); } @@ -76,7 +76,7 @@ public function testNestedCategories() $this->dm->flush(); $this->dm->clear(); - $category = $this->dm->find(__NAMESPACE__ . '\Category', $category->getId()); + $category = $this->dm->find(Category::class, $category->getId()); $this->assertNotNull($category); $category->setName('Root Changed'); $children = $category->getChildren(); @@ -87,7 +87,7 @@ public function testNestedCategories() $this->dm->flush(); $this->dm->clear(); - $category = $this->dm->find(__NAMESPACE__ . '\Category', $category->getId()); + $category = $this->dm->find(Category::class, $category->getId()); $children = $category->getChildren(); $this->assertEquals('Child 1 Changed', $children[0]->getName()); @@ -107,7 +107,7 @@ public function testNestedReference() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->getRepository(__NAMESPACE__ . '\Hierarchy')->findOneBy(['name' => 'Root']); + $test = $this->dm->getRepository(Hierarchy::class)->findOneBy(['name' => 'Root']); $this->assertNotNull($test); $child1 = $test->getChild('Child 1')->setName('Child 1 Changed'); @@ -118,22 +118,22 @@ public function testNestedReference() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->find(__NAMESPACE__ . '\Hierarchy', $test->getId()); + $test = $this->dm->find(Hierarchy::class, $test->getId()); $this->assertNotNull($test); $this->assertEquals('Root Changed', $test->getName()); $this->assertEquals('Child 1 Changed', $test->getChild(0)->getName()); $this->assertEquals('Child 2 Changed', $test->getChild(1)->getName()); - $child3 = $this->dm->getRepository(__NAMESPACE__ . '\Hierarchy')->findOneBy(['name' => 'Child 3']); + $child3 = $this->dm->getRepository(Hierarchy::class)->findOneBy(['name' => 'Child 3']); $this->assertNotNull($child3); $child3->setName('Child 3 Changed'); $this->dm->flush(); - $child3 = $this->dm->getRepository(__NAMESPACE__ . '\Hierarchy')->findOneBy(['name' => 'Child 3 Changed']); + $child3 = $this->dm->getRepository(Hierarchy::class)->findOneBy(['name' => 'Child 3 Changed']); $this->assertNotNull($child3); $this->assertEquals('Child 3 Changed', $child3->getName()); - $test = $this->dm->getDocumentCollection(__NAMESPACE__ . '\Hierarchy')->findOne(['name' => 'Child 1 Changed']); + $test = $this->dm->getDocumentCollection(Hierarchy::class)->findOne(['name' => 'Child 1 Changed']); $this->assertArrayNotHasKey('children', $test, 'Test empty array is not stored'); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php index e961772e8b..d611d97d0b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php @@ -145,7 +145,7 @@ public function testClearAndAddEmbedMany() */ private function getUserRepository() { - return $this->dm->getRepository('Doctrine\ODM\MongoDB\Tests\Functional\OrphanRemovalCascadeUser'); + return $this->dm->getRepository(OrphanRemovalCascadeUser::class); } /** @@ -153,7 +153,7 @@ private function getUserRepository() */ private function getAddressRepository() { - return $this->dm->getRepository('Doctrine\ODM\MongoDB\Tests\Functional\OrphanRemovalCascadeAddress'); + return $this->dm->getRepository(OrphanRemovalCascadeAddress::class); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php index 37bb9fd98f..d350225349 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php @@ -249,7 +249,7 @@ public function testOrphanRemovalWhenRemovingAndAddingSameElement() */ private function getUserRepository() { - return $this->dm->getRepository('Doctrine\ODM\MongoDB\Tests\Functional\OrphanRemovalUser'); + return $this->dm->getRepository(OrphanRemovalUser::class); } /** @@ -257,7 +257,7 @@ private function getUserRepository() */ private function getProfileRepository() { - return $this->dm->getRepository('Doctrine\ODM\MongoDB\Tests\Functional\OrphanRemovalProfile'); + return $this->dm->getRepository(OrphanRemovalProfile::class); } } 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/ReferenceDiscriminatorsTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceDiscriminatorsTest.php index 2d40377387..a7419ee993 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceDiscriminatorsTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceDiscriminatorsTest.php @@ -12,11 +12,11 @@ class ReferenceDiscriminatorsTest extends BaseTest public function setUp() { parent::setUp(); - $this->dm->getSchemaManager()->ensureDocumentIndexes(__NAMESPACE__ . '\CommentableAction'); - $this->dm->getSchemaManager()->ensureDocumentIndexes(__NAMESPACE__ . '\GroupMainActivityStreamItem'); - $this->dm->getSchemaManager()->ensureDocumentIndexes(__NAMESPACE__ . '\GroupMembersActivityStreamItem'); - $this->dm->getSchemaManager()->ensureDocumentIndexes(__NAMESPACE__ . '\UserDashboardActivityStreamItem'); - $this->dm->getSchemaManager()->ensureDocumentIndexes(__NAMESPACE__ . '\UserProfileActivityStreamItem'); + $this->dm->getSchemaManager()->ensureDocumentIndexes(CommentableAction::class); + $this->dm->getSchemaManager()->ensureDocumentIndexes(GroupMainActivityStreamItem::class); + $this->dm->getSchemaManager()->ensureDocumentIndexes(GroupMembersActivityStreamItem::class); + $this->dm->getSchemaManager()->ensureDocumentIndexes(UserDashboardActivityStreamItem::class); + $this->dm->getSchemaManager()->ensureDocumentIndexes(UserProfileActivityStreamItem::class); } /** @@ -33,11 +33,11 @@ public function testReferenceDiscriminators() $this->dm->flush(); $this->dm->clear(); - $commentableAction = $this->dm->find(__NAMESPACE__ . '\CommentableAction', $commentableAction->getId()); - $groupMainActivityStreamItem = $this->dm->find(__NAMESPACE__ . '\GroupMainActivityStreamItem', $groupMainActivityStreamItem->getId()); - $groupMemberActivityStreamItem = $this->dm->find(__NAMESPACE__ . '\GroupMembersActivityStreamItem', $groupMemberActivityStreamItem->getId()); - $userDashboardActivityStreamItem = $this->dm->find(__NAMESPACE__ . '\UserDashboardActivityStreamItem', $userDashboardActivityStreamItem->getId()); - $userProfileActivityStreamItem = $this->dm->find(__NAMESPACE__ . '\UserProfileActivityStreamItem', $userProfileActivityStreamItem->getId()); + $commentableAction = $this->dm->find(CommentableAction::class, $commentableAction->getId()); + $groupMainActivityStreamItem = $this->dm->find(GroupMainActivityStreamItem::class, $groupMainActivityStreamItem->getId()); + $groupMemberActivityStreamItem = $this->dm->find(GroupMembersActivityStreamItem::class, $groupMemberActivityStreamItem->getId()); + $userDashboardActivityStreamItem = $this->dm->find(UserDashboardActivityStreamItem::class, $userDashboardActivityStreamItem->getId()); + $userProfileActivityStreamItem = $this->dm->find(UserProfileActivityStreamItem::class, $userProfileActivityStreamItem->getId()); $this->assertSame($commentableAction, $groupMainActivityStreamItem->getAction()); $this->assertSame($commentableAction, $groupMemberActivityStreamItem->getAction()); @@ -66,17 +66,17 @@ public function testReferenceDiscriminatorsRaceCondition() $this->dm->flush(); $this->dm->clear(); - $commentableAction1 = $this->dm->find(__NAMESPACE__ . '\CommentableAction', $commentableAction1->getId()); - $groupMainActivityStreamItem1 = $this->dm->find(__NAMESPACE__ . '\GroupMainActivityStreamItem', $groupMainActivityStreamItem1->getId()); - $groupMemberActivityStreamItem1 = $this->dm->find(__NAMESPACE__ . '\GroupMembersActivityStreamItem', $groupMemberActivityStreamItem1->getId()); - $userDashboardActivityStreamItem1 = $this->dm->find(__NAMESPACE__ . '\UserDashboardActivityStreamItem', $userDashboardActivityStreamItem1->getId()); - $userProfileActivityStreamItem1 = $this->dm->find(__NAMESPACE__ . '\UserProfileActivityStreamItem', $userProfileActivityStreamItem1->getId()); - - $commentableAction2 = $this->dm->find(__NAMESPACE__ . '\CommentableAction', $commentableAction2->getId()); - $groupMainActivityStreamItem2 = $this->dm->find(__NAMESPACE__ . '\GroupMainActivityStreamItem', $groupMainActivityStreamItem2->getId()); - $groupMemberActivityStreamItem2 = $this->dm->find(__NAMESPACE__ . '\GroupMembersActivityStreamItem', $groupMemberActivityStreamItem2->getId()); - $userDashboardActivityStreamItem2 = $this->dm->find(__NAMESPACE__ . '\UserDashboardActivityStreamItem', $userDashboardActivityStreamItem2->getId()); - $userProfileActivityStreamItem2 = $this->dm->find(__NAMESPACE__ . '\UserProfileActivityStreamItem', $userProfileActivityStreamItem2->getId()); + $commentableAction1 = $this->dm->find(CommentableAction::class, $commentableAction1->getId()); + $groupMainActivityStreamItem1 = $this->dm->find(GroupMainActivityStreamItem::class, $groupMainActivityStreamItem1->getId()); + $groupMemberActivityStreamItem1 = $this->dm->find(GroupMembersActivityStreamItem::class, $groupMemberActivityStreamItem1->getId()); + $userDashboardActivityStreamItem1 = $this->dm->find(UserDashboardActivityStreamItem::class, $userDashboardActivityStreamItem1->getId()); + $userProfileActivityStreamItem1 = $this->dm->find(UserProfileActivityStreamItem::class, $userProfileActivityStreamItem1->getId()); + + $commentableAction2 = $this->dm->find(CommentableAction::class, $commentableAction2->getId()); + $groupMainActivityStreamItem2 = $this->dm->find(GroupMainActivityStreamItem::class, $groupMainActivityStreamItem2->getId()); + $groupMemberActivityStreamItem2 = $this->dm->find(GroupMembersActivityStreamItem::class, $groupMemberActivityStreamItem2->getId()); + $userDashboardActivityStreamItem2 = $this->dm->find(UserDashboardActivityStreamItem::class, $userDashboardActivityStreamItem2->getId()); + $userProfileActivityStreamItem2 = $this->dm->find(UserProfileActivityStreamItem::class, $userProfileActivityStreamItem2->getId()); $this->assertSame($commentableAction1, $groupMainActivityStreamItem1->getAction()); $this->assertSame($commentableAction1, $groupMemberActivityStreamItem1->getAction()); 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/GH1294Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1294Test.php index d6eafc37a3..c657ccba9d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1294Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1294Test.php @@ -12,8 +12,6 @@ class GH1294Test extends BaseTest { public function testRegexSearchOnIdentifierWithUuidStrategy() { - $userClass = __NAMESPACE__ . '\GH1294User'; - $user1 = new GH1294User(); $user1->id = 'aaa111aaa'; $user1->name = 'Steven'; @@ -27,7 +25,7 @@ public function testRegexSearchOnIdentifierWithUuidStrategy() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder($userClass); + $qb = $this->dm->createQueryBuilder(GH1294User::class); $res = $qb->field('id') ->equals(new Regex('^bbb.*$', 'i')) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1346Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1346Test.php index a9acd170d2..c4d3e50460 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1346Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1346Test.php @@ -26,8 +26,8 @@ public function testPublicProperty() $this->dm->flush(); $this->dm->clear(); - $gH1346Document = $this->dm->getRepository(__NAMESPACE__ . '\GH1346Document')->find($gH1346Document->getId()); - $referenced2 = $this->dm->getRepository(__NAMESPACE__ . '\GH1346ReferencedDocument')->find($referenced2->getId()); + $gH1346Document = $this->dm->getRepository(GH1346Document::class)->find($gH1346Document->getId()); + $referenced2 = $this->dm->getRepository(GH1346ReferencedDocument::class)->find($referenced2->getId()); $gH1346Document->addReference($referenced2); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH232Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH232Test.php index 58cdcabf20..9788caa607 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH232Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH232Test.php @@ -30,7 +30,7 @@ public function testReferencedDocumentInsideEmbeddedDocument() $this->dm->flush(); $this->dm->clear(); - $product = $this->dm->getRepository(__NAMESPACE__ . '\Product')->findOneBy(['name' => 'Product']); + $product = $this->dm->getRepository(Product::class)->findOneBy(['name' => 'Product']); $this->assertEquals(1, $product->subproducts->count()); $this->assertEquals(1, $product->subproducts[0]->prices->count()); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH385Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH385Test.php index c7452dfc84..077f3cb045 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH385Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH385Test.php @@ -4,6 +4,7 @@ namespace Doctrine\ODM\MongoDB\Tests; +use Documents\User; use MongoDB\BSON\ObjectId; class GH385Test extends BaseTest @@ -12,7 +13,7 @@ public function testQueryBuilderShouldPrepareUnmappedFields() { $identifier = new ObjectId(); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->upsert() ->updateOne() ->field('id')->equals($identifier) @@ -25,7 +26,7 @@ public function testQueryBuilderShouldPrepareUnmappedFields() $qb->getQuery()->execute(); - $check = $this->dm->getDocumentCollection('Documents\User')->findOne(['_id' => $identifier]); + $check = $this->dm->getDocumentCollection(User::class)->findOne(['_id' => $identifier]); $this->assertNotNull($check); $this->assertTrue(isset($check['foo']['bar']['level3a'])); $this->assertTrue(isset($check['foo']['bar']['level3b'])); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH389Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH389Test.php index 036e0e7109..af06fb11f0 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH389Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH389Test.php @@ -24,10 +24,10 @@ public function testDiscriminatorEmptyEmbeddedDocument() unset($rootDocument); //Get root document - $rootDocument = $this->dm->getRepository(__NAMESPACE__ . '\RootDocument')->find($rootDocumentId); + $rootDocument = $this->dm->getRepository(RootDocument::class)->find($rootDocumentId); //Test - $this->assertInstanceOf(__NAMESPACE__ . '\EmptyEmbeddedDocument', $rootDocument->getEmptyEmbeddedDocument()); + $this->assertInstanceOf(EmptyEmbeddedDocument::class, $rootDocument->getEmptyEmbeddedDocument()); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH426Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH426Test.php index f8f83b9078..957884a44f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH426Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH426Test.php @@ -19,13 +19,13 @@ public function testTest() $this->dm->flush(); $this->dm->clear(); - $form = $this->dm->find('Doctrine\ODM\MongoDB\Tests\Functional\Ticket\GH426Form', $form->id); + $form = $this->dm->find(GH426Form::class, $form->id); $this->assertEquals(2, $form->fields->count()); $this->assertSame($form->fields[0], $form->firstField); $this->assertSame($form->fields[1], $form->lastField); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Tests\Functional\Ticket\GH426Field', $form->firstField); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Tests\Functional\Ticket\GH426Field', $form->lastField); + $this->assertInstanceOf(GH426Field::class, $form->firstField); + $this->assertInstanceOf(GH426Field::class, $form->lastField); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH435Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH435Test.php index 5808ecdffb..8cb9f48207 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH435Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH435Test.php @@ -11,14 +11,14 @@ class GH435Test extends BaseTest { public function testOverridingFieldsType() { - $parent = $this->dm->getClassMetadata(__NAMESPACE__ . '\GH435Parent'); + $parent = $this->dm->getClassMetadata(GH435Parent::class); $this->assertArrayHasKey('id', $parent->fieldMappings['id']); $this->assertTrue($parent->fieldMappings['id']['id']); $this->assertEquals('id', $parent->fieldMappings['id']['type']); $this->assertEquals('int', $parent->fieldMappings['test']['type']); - $child = $this->dm->getClassMetadata(__NAMESPACE__ . '\GH435Child'); + $child = $this->dm->getClassMetadata(GH435Child::class); $this->assertEquals('string', $child->fieldMappings['test']['type']); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php index 9285c5acfd..6b8b10edf0 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php @@ -255,7 +255,7 @@ private function assertBsonType($bsonType, $documentId, $fieldName) $criteria[$fieldName] = ['$type' => $bsonType]; } - $this->assertNotNull($this->dm->getRepository(__NAMESPACE__ . '\GH453Document')->findOneBy($criteria)); + $this->assertNotNull($this->dm->getRepository(GH453Document::class)->findOneBy($criteria)); } private function assertBsonArrayAndValue($expectedValue, $documentId, $fieldName) @@ -288,7 +288,7 @@ private function assertBsonTypeAndValue($bsonType, $expectedValue, $documentId, $criteria['$and'][] = [$fieldName => ['$type' => $bsonType]]; } - $this->assertNotNull($this->dm->getRepository(__NAMESPACE__ . '\GH453Document')->findOneBy($criteria)); + $this->assertNotNull($this->dm->getRepository(GH453Document::class)->findOneBy($criteria)); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH467Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH467Test.php index 9cb246c263..c01cc04cb0 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH467Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH467Test.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\PersistentCollection; use Doctrine\ODM\MongoDB\Tests\BaseTest; class GH467Test extends BaseTest @@ -20,9 +21,9 @@ public function testMergeDocumentWithUnsetCollectionFields() $doc = $this->dm->merge($doc); $this->assertNull($doc->col, 'Unset basic collections are not initialized'); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\PersistentCollection', $doc->embedMany, 'Unset EmbedMany collections are initialized as empty PersistentCollections'); + $this->assertInstanceOf(PersistentCollection::class, $doc->embedMany, 'Unset EmbedMany collections are initialized as empty PersistentCollections'); $this->assertCount(0, $doc->embedMany, 'Unset EmbedMany collections are initialized as empty PersistentCollections'); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\PersistentCollection', $doc->refMany, 'Unset ReferenceMany collections are initialized as empty PersistentCollections'); + $this->assertInstanceOf(PersistentCollection::class, $doc->refMany, 'Unset ReferenceMany collections are initialized as empty PersistentCollections'); $this->assertCount(0, $doc->refMany, 'Unset ReferenceMany collections are initialized as empty PersistentCollections'); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH499Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH499Test.php index f006b671a8..47ae26602b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH499Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH499Test.php @@ -26,7 +26,7 @@ public function testSetRefMany() $this->dm->flush(); $this->dm->clear(); - $collection = $this->dm->getDocumentCollection(__NAMESPACE__ . '\GH499Document'); + $collection = $this->dm->getDocumentCollection(GH499Document::class); $a = $collection->findOne(['_id' => new ObjectId($a->getId())]); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php index 092f64a66c..edd962e241 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php @@ -7,6 +7,7 @@ use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; +use Doctrine\ODM\MongoDB\Proxy\Proxy; class GH520Test extends BaseTest { @@ -19,14 +20,14 @@ public function testPrimeWithGetSingleResult() $this->dm->flush(); $this->dm->clear(); - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH520Document') + $query = $this->dm->createQueryBuilder(GH520Document::class) ->field('id')->equals($document->id) ->field('ref')->prime(true) ->getQuery(); $document = $query->getSingleResult(); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $document->ref); + $this->assertInstanceOf(Proxy::class, $document->ref); $this->assertTrue($document->ref->__isInitialized()); } @@ -50,7 +51,7 @@ public function testPrimeWithGetSingleResultWillNotPrimeEntireResultSet() $primedIds = $ids; }; - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH520Document') + $query = $this->dm->createQueryBuilder(GH520Document::class) ->field('ref')->exists(true)->prime($primer) ->getQuery(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH560Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH560Test.php index 53ae20d164..4b0328f2f1 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH560Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH560Test.php @@ -30,8 +30,8 @@ public function testPersistListenersAreCalled($id) $this->dm->clear(); $called = [ - [Events::prePersist, __NAMESPACE__ . '\GH560Document'], - [Events::postPersist, __NAMESPACE__ . '\GH560Document'], + [Events::prePersist, GH560Document::class], + [Events::postPersist, GH560Document::class], ]; $this->assertEquals($called, $listener->called); @@ -47,7 +47,7 @@ public function testDocumentWithCustomIdStrategyIsSavedAndFoundFromDatabase($id) $this->dm->flush(); $this->dm->clear(); - $doc = $this->dm->find(__NAMESPACE__ . '\GH560Document', $id); + $doc = $this->dm->find(GH560Document::class, $id); $this->assertEquals($id, $doc->id); } @@ -72,8 +72,8 @@ public function testUpdateListenersAreCalled($id) $this->dm->clear(); $called = [ - [Events::preUpdate, __NAMESPACE__ . '\GH560Document'], - [Events::postUpdate, __NAMESPACE__ . '\GH560Document'], + [Events::preUpdate, GH560Document::class], + [Events::postUpdate, GH560Document::class], ]; $this->assertEquals($called, $listener->called); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH561Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH561Test.php index 17d1243eaa..8b1f06aa48 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH561Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH561Test.php @@ -22,16 +22,16 @@ public function testPersistMainDocument() $this->dm->flush(); $this->dm->clear(); - $document = $this->dm->find(__NAMESPACE__ . '\GH561Document', $document->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH561Document', $document); + $document = $this->dm->find(GH561Document::class, $document->id); + $this->assertInstanceOf(GH561Document::class, $document); $this->assertCount(1, $document->embeddedDocuments); $embeddedDocument = $document->embeddedDocuments->first(); - $this->assertInstanceOf(__NAMESPACE__ . '\GH561EmbeddedDocument', $embeddedDocument); + $this->assertInstanceOf(GH561EmbeddedDocument::class, $embeddedDocument); $this->assertCount(1, $embeddedDocument->embeddedDocuments); $anotherEmbeddedDocument = $embeddedDocument->embeddedDocuments->first(); - $this->assertInstanceOf(__NAMESPACE__ . '\GH561AnotherEmbeddedDocument', $anotherEmbeddedDocument); + $this->assertInstanceOf(GH561AnotherEmbeddedDocument::class, $anotherEmbeddedDocument); $this->assertEquals('foo', $anotherEmbeddedDocument->name); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH566Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH566Test.php index a2ba55c071..37df3e8fae 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH566Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH566Test.php @@ -13,7 +13,7 @@ class GH566Test extends BaseTest { public function testFoo() { - $class = __NAMESPACE__ . '\GH566Document'; + $class = GH566Document::class; $doc1 = new GH566Document(); $doc2 = new GH566Document(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH580Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH580Test.php index 880cc14aac..78ea405c47 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH580Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH580Test.php @@ -12,7 +12,7 @@ class GH580Test extends BaseTest { public function testDocumentPersisterShouldClearQueuedInsertsOnMongoException() { - $class = __NAMESPACE__ . '\GH580Document'; + $class = GH580Document::class; $schemaManager = $this->dm->getSchemaManager(); $schemaManager->updateDocumentIndexes($class); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php index 3633dcdfcf..608b9e9724 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ODM\MongoDB\DocumentNotFoundException; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Proxy\Proxy; use Doctrine\ODM\MongoDB\Tests\BaseTest; use function iterator_to_array; @@ -18,14 +19,14 @@ public function setUp() $this->dm->getFilterCollection()->enable('testFilter'); $filter = $this->dm->getFilterCollection()->getFilter('testFilter'); - $filter->setParameter('class', __NAMESPACE__ . '\GH593User'); + $filter->setParameter('class', GH593User::class); $filter->setParameter('field', 'deleted'); $filter->setParameter('value', false); } public function testReferenceManyOwningSidePreparesFilterCriteria() { - $class = __NAMESPACE__ . '\GH593User'; + $class = GH593User::class; $user1 = new GH593User(); $user2 = new GH593User(); @@ -55,11 +56,11 @@ public function testReferenceManyOwningSidePreparesFilterCriteria() */ $this->assertCount(2, $user1following); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user1following[0]); + $this->assertInstanceOf(Proxy::class, $user1following[0]); $this->assertTrue($user1following[0]->__isInitialized()); $this->assertEquals($user2->getId(), $user1following[0]->getId()); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user1following[1]); + $this->assertInstanceOf(Proxy::class, $user1following[1]); $this->assertFalse($user1following[1]->__isInitialized()); $this->assertEquals($user3->getId(), $user1following[1]->getId()); @@ -69,7 +70,7 @@ public function testReferenceManyOwningSidePreparesFilterCriteria() public function testReferenceManyInverseSidePreparesFilterCriteria() { - $class = __NAMESPACE__ . '\GH593User'; + $class = GH593User::class; $user1 = new GH593User(); $user2 = new GH593User(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php index 5685f9f7b5..34826930d4 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php @@ -15,14 +15,14 @@ public function setUp() $this->dm->getFilterCollection()->enable('testFilter'); $filter = $this->dm->getFilterCollection()->getFilter('testFilter'); - $filter->setParameter('class', __NAMESPACE__ . '\GH596Document'); + $filter->setParameter('class', GH596Document::class); $filter->setParameter('field', 'deleted'); $filter->setParameter('value', false); } public function testExpressionPreparationDoesNotInjectFilterCriteria() { - $class = __NAMESPACE__ . '\GH596Document'; + $class = GH596Document::class; $repository = $this->dm->getRepository($class); $qb = $repository->createQueryBuilder(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php index fc28e76af4..60aab25290 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php @@ -23,7 +23,7 @@ public function testEmbedManyGetsUnset() $this->assertPostDocument($expectedDocument, $post); // fill documents with comments - $post = $this->dm->find(__NAMESPACE__ . '\GH597Post', $post->getId()); + $post = $this->dm->find(GH597Post::class, $post->getId()); $post->comments = new ArrayCollection([ new GH597Comment('Comment 1'), new GH597Comment('Comment 2'), @@ -44,13 +44,13 @@ public function testEmbedManyGetsUnset() $this->assertPostDocument($expectedDocument, $post); // trigger update - $post = $this->dm->find(__NAMESPACE__ . '\GH597Post', $post->getId()); + $post = $this->dm->find(GH597Post::class, $post->getId()); $this->assertCount(3, $post->getComments()); $post->comments = null; $this->dm->flush(); $this->dm->clear(); - $post = $this->dm->find(__NAMESPACE__ . '\GH597Post', $post->getId()); + $post = $this->dm->find(GH597Post::class, $post->getId()); $this->assertCount(0, $post->getComments()); // make sure embedded documents got unset @@ -70,7 +70,7 @@ public function testReferenceManyGetsUnset() $this->assertPostDocument($expectedDocument, $post); // associate post with many GH597ReferenceMany documents - $post = $this->dm->find(__NAMESPACE__ . '\GH597Post', $post->getId()); + $post = $this->dm->find(GH597Post::class, $post->getId()); $referenceMany1 = new GH597ReferenceMany('one'); $this->dm->persist($referenceMany1); @@ -92,13 +92,13 @@ public function testReferenceManyGetsUnset() $this->assertPostDocument($expectedDocument, $post); // trigger update - $post = $this->dm->find(__NAMESPACE__ . '\GH597Post', $post->getId()); + $post = $this->dm->find(GH597Post::class, $post->getId()); $this->assertCount(2, $post->getReferenceMany()); $post->referenceMany = null; $this->dm->flush(); $this->dm->clear(); - $post = $this->dm->find(__NAMESPACE__ . '\GH597Post', $post->getId()); + $post = $this->dm->find(GH597Post::class, $post->getId()); $this->assertCount(0, $post->getReferenceMany()); // make sure reference-many documents got unset @@ -113,7 +113,7 @@ public function testReferenceManyGetsUnset() */ private function assertPostDocument(array $expected, GH597Post $post) { - $collection = $this->dm->getDocumentCollection(__NAMESPACE__ . '\GH597Post'); + $collection = $this->dm->getDocumentCollection(GH597Post::class); $document = $collection->findOne(['_id' => new ObjectId($post->getId())]); $this->assertEquals($expected, $document); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php index 842ead3b58..b0370be7e3 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ODM\MongoDB\DocumentNotFoundException; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Proxy\Proxy; use Doctrine\ODM\MongoDB\Tests\BaseTest; use function iterator_to_array; @@ -14,8 +15,8 @@ class GH602Test extends BaseTest { public function testReferenceManyOwningSidePreparesFilterCriteriaForDifferentClass() { - $thingClass = __NAMESPACE__ . '\GH602Thing'; - $userClass = __NAMESPACE__ . '\GH602User'; + $thingClass = GH602Thing::class; + $userClass = GH602User::class; $this->enableDeletedFilter($thingClass); $user1 = new GH602User(); @@ -46,11 +47,11 @@ public function testReferenceManyOwningSidePreparesFilterCriteriaForDifferentCla */ $this->assertCount(2, $user1likes); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user1likes[0]); + $this->assertInstanceOf(Proxy::class, $user1likes[0]); $this->assertTrue($user1likes[0]->__isInitialized()); $this->assertEquals($thing1->getId(), $user1likes[0]->getId()); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user1likes[1]); + $this->assertInstanceOf(Proxy::class, $user1likes[1]); $this->assertFalse($user1likes[1]->__isInitialized()); $this->assertEquals($thing2->getId(), $user1likes[1]->getId()); @@ -60,8 +61,8 @@ public function testReferenceManyOwningSidePreparesFilterCriteriaForDifferentCla public function testReferenceManyInverseSidePreparesFilterCriteriaForDifferentClass() { - $thingClass = __NAMESPACE__ . '\GH602Thing'; - $userClass = __NAMESPACE__ . '\GH602User'; + $thingClass = GH602Thing::class; + $userClass = GH602User::class; $this->enableDeletedFilter($userClass); $user1 = new GH602User(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH611Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH611Test.php index 651d4f0486..44fa76d6f1 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH611Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH611Test.php @@ -21,7 +21,7 @@ public function testPreparationofEmbeddedDocumentValues() $this->dm->flush(); $this->dm->clear(); - $document = $this->dm->find(__NAMESPACE__ . '\GH611Document', $documentId); + $document = $this->dm->find(GH611Document::class, $documentId); $this->assertSame($documentId, $document->id); $this->assertSame(1, $document->embedded->id); @@ -32,7 +32,7 @@ public function testPreparationofEmbeddedDocumentValues() $this->dm->flush(); $this->dm->clear(); - $document = $this->dm->find(__NAMESPACE__ . '\GH611Document', $documentId); + $document = $this->dm->find(GH611Document::class, $documentId); $this->assertSame($documentId, $document->id); $this->assertSame(2, $document->embedded->id); @@ -42,14 +42,14 @@ public function testPreparationofEmbeddedDocumentValues() $this->dm->flush(); $this->dm->clear(); - $document = $this->dm->find(__NAMESPACE__ . '\GH611Document', $documentId); + $document = $this->dm->find(GH611Document::class, $documentId); $this->assertSame($documentId, $document->id); $this->assertSame(3, $document->embedded->id); $this->assertSame('b', $document->embedded->name); // Update the embedded document's ID field via query builder - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH611Document') + $query = $this->dm->createQueryBuilder(GH611Document::class) ->updateOne() ->field('id')->equals($documentId) ->field('embedded._id')->exists(false) @@ -59,14 +59,14 @@ public function testPreparationofEmbeddedDocumentValues() $this->dm->clear(); - $document = $this->dm->find(__NAMESPACE__ . '\GH611Document', $documentId); + $document = $this->dm->find(GH611Document::class, $documentId); $this->assertSame($documentId, $document->id); $this->assertSame(4, $document->embedded->id); $this->assertSame('b', $document->embedded->name); // Update the entire embedded document with an array via query builder - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH611Document') + $query = $this->dm->createQueryBuilder(GH611Document::class) ->updateOne() ->field('id')->equals($documentId) ->field('embedded._id')->exists(false) @@ -76,14 +76,14 @@ public function testPreparationofEmbeddedDocumentValues() $this->dm->clear(); - $document = $this->dm->find(__NAMESPACE__ . '\GH611Document', $documentId); + $document = $this->dm->find(GH611Document::class, $documentId); $this->assertSame($documentId, $document->id); $this->assertSame(5, $document->embedded->id); $this->assertSame('c', $document->embedded->name); // Update the entire embedded document with an unmapped object via query builder - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH611Document') + $query = $this->dm->createQueryBuilder(GH611Document::class) ->updateOne() ->field('id')->equals($documentId) ->field('embedded._id')->exists(false) @@ -93,14 +93,14 @@ public function testPreparationofEmbeddedDocumentValues() $this->dm->clear(); - $document = $this->dm->find(__NAMESPACE__ . '\GH611Document', $documentId); + $document = $this->dm->find(GH611Document::class, $documentId); $this->assertSame($documentId, $document->id); $this->assertSame(6, $document->embedded->id); $this->assertSame('d', $document->embedded->name); // Update the entire embedded document with a mapped object via query builder - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH611Document') + $query = $this->dm->createQueryBuilder(GH611Document::class) ->updateOne() ->field('id')->equals($documentId) ->field('embedded._id')->exists(false) @@ -110,7 +110,7 @@ public function testPreparationofEmbeddedDocumentValues() $this->dm->clear(); - $document = $this->dm->find(__NAMESPACE__ . '\GH611Document', $documentId); + $document = $this->dm->find(GH611Document::class, $documentId); $this->assertSame($documentId, $document->id); $this->assertSame(7, $document->embedded->id); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH628Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH628Test.php index 1c9bec811e..b99c403408 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH628Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH628Test.php @@ -10,7 +10,7 @@ class GH628Test extends BaseTest { public function testQueryBuilderShouldOnlyPrepareFirstPartOfRawFields() { - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH628Document') + $query = $this->dm->createQueryBuilder(GH628Document::class) ->field('foo.bar.baz')->equals(1) ->getQuery() ->getQuery(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH665Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH665Test.php index ac9a5c91de..d0ccd1a0cb 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH665Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH665Test.php @@ -20,17 +20,17 @@ public function testUseAddToSetStrategyOnEmbeddedDocument() $this->dm->flush(); $this->dm->clear(); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\GH665Document') + $check = $this->dm->getDocumentCollection(GH665Document::class) ->findOne(['embeddedPushAll.name' => 'foo']); $this->assertNotNull($check); $this->assertSame($document->id, (string) $check['_id']); - $check = $this->dm->getDocumentCollection(__NAMESPACE__ . '\GH665Document') + $check = $this->dm->getDocumentCollection(GH665Document::class) ->findOne(['embeddedAddToSet.name' => 'bar']); $this->assertNotNull($check); $this->assertSame($document->id, (string) $check['_id']); - $persisted = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH665Document') + $persisted = $this->dm->createQueryBuilder(GH665Document::class) ->hydrate(false) ->field('id')->equals($document->id) ->getQuery() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH788Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH788Test.php index bfd9bd6e36..09ad1627a1 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH788Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH788Test.php @@ -24,11 +24,11 @@ public function testDocumentWithDiscriminatorMap() $this->dm->clear(); $doc = $this->dm->find(get_class($listed), $listed->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788DocumentListed', $doc); + $this->assertInstanceOf(GH788DocumentListed::class, $doc); $this->assertEquals('listed', $doc->name); $doc = $this->dm->find(get_class($unlisted), $unlisted->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788DocumentUnlisted', $doc); + $this->assertInstanceOf(GH788DocumentUnlisted::class, $doc); $this->assertEquals('unlisted', $doc->name); /* Attempting to find the unlisted class by the parent class will not @@ -60,9 +60,9 @@ public function testEmbedManyWithExternalDiscriminatorMap() $collection = $doc->externEmbedMany; $this->assertCount(2, $collection); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternEmbedListed', $collection[0]); + $this->assertInstanceOf(GH788ExternEmbedListed::class, $collection[0]); $this->assertEquals('listed', $collection[0]->name); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternEmbedUnlisted', $collection[1]); + $this->assertInstanceOf(GH788ExternEmbedUnlisted::class, $collection[1]); $this->assertEquals('unlisted', $collection[1]->name); } @@ -86,9 +86,9 @@ public function testEmbedManyWithInlineDiscriminatorMap() $collection = $doc->inlineEmbedMany; $this->assertCount(2, $collection); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788InlineEmbedListed', $collection[0]); + $this->assertInstanceOf(GH788InlineEmbedListed::class, $collection[0]); $this->assertEquals('listed', $collection[0]->name); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788InlineEmbedUnlisted', $collection[1]); + $this->assertInstanceOf(GH788InlineEmbedUnlisted::class, $collection[1]); $this->assertEquals('unlisted', $collection[1]->name); } @@ -112,9 +112,9 @@ public function testEmbedManyWithNoTargetAndExternalDiscriminatorMap() $collection = $doc->noTargetEmbedMany; $this->assertCount(2, $collection); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternEmbedListed', $collection[0]); + $this->assertInstanceOf(GH788ExternEmbedListed::class, $collection[0]); $this->assertEquals('listed', $collection[0]->name); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternEmbedUnlisted', $collection[1]); + $this->assertInstanceOf(GH788ExternEmbedUnlisted::class, $collection[1]); $this->assertEquals('unlisted', $collection[1]->name); } @@ -132,7 +132,7 @@ public function testEmbedOneWithExternalDiscriminatorMap() $doc = $this->dm->find(get_class($doc), $doc->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternEmbedUnlisted', $doc->externEmbedOne); + $this->assertInstanceOf(GH788ExternEmbedUnlisted::class, $doc->externEmbedOne); $this->assertEquals('unlisted', $doc->externEmbedOne->name); } @@ -150,7 +150,7 @@ public function testEmbedOneWithInlineDiscriminatorMap() $doc = $this->dm->find(get_class($doc), $doc->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788InlineEmbedUnlisted', $doc->inlineEmbedOne); + $this->assertInstanceOf(GH788InlineEmbedUnlisted::class, $doc->inlineEmbedOne); $this->assertEquals('unlisted', $doc->inlineEmbedOne->name); } @@ -168,7 +168,7 @@ public function testEmbedOneWithNoTargetAndExternalDiscriminatorMap() $doc = $this->dm->find(get_class($doc), $doc->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternEmbedUnlisted', $doc->noTargetEmbedOne); + $this->assertInstanceOf(GH788ExternEmbedUnlisted::class, $doc->noTargetEmbedOne); $this->assertEquals('unlisted', $doc->noTargetEmbedOne->name); } @@ -192,10 +192,10 @@ public function testRefManyWithExternalDiscriminatorMap() $collection = $doc->externRefMany; $this->assertCount(2, $collection); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternRefListed', $collection[0]); + $this->assertInstanceOf(GH788ExternRefListed::class, $collection[0]); $this->assertEquals($listed->id, $collection[0]->id); $this->assertEquals('listed', $collection[0]->name); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternRefUnlisted', $collection[1]); + $this->assertInstanceOf(GH788ExternRefUnlisted::class, $collection[1]); $this->assertEquals($unlisted->id, $collection[1]->id); $this->assertEquals('unlisted', $collection[1]->name); } @@ -220,10 +220,10 @@ public function testRefManyWithInlineDiscriminatorMap() $collection = $doc->inlineRefMany; $this->assertCount(2, $collection); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788InlineRefListed', $collection[0]); + $this->assertInstanceOf(GH788InlineRefListed::class, $collection[0]); $this->assertEquals($listed->id, $collection[0]->id); $this->assertEquals('listed', $collection[0]->name); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788InlineRefUnlisted', $collection[1]); + $this->assertInstanceOf(GH788InlineRefUnlisted::class, $collection[1]); $this->assertEquals($unlisted->id, $collection[1]->id); $this->assertEquals('unlisted', $collection[1]->name); } @@ -248,10 +248,10 @@ public function testRefManyWithNoTargetAndExternalDiscriminatorMap() $collection = $doc->noTargetRefMany; $this->assertCount(2, $collection); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternRefListed', $collection[0]); + $this->assertInstanceOf(GH788ExternRefListed::class, $collection[0]); $this->assertEquals($listed->id, $collection[0]->id); $this->assertEquals('listed', $collection[0]->name); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternRefUnlisted', $collection[1]); + $this->assertInstanceOf(GH788ExternRefUnlisted::class, $collection[1]); $this->assertEquals($unlisted->id, $collection[1]->id); $this->assertEquals('unlisted', $collection[1]->name); } @@ -270,7 +270,7 @@ public function testRefOneWithExternalDiscriminatorMap() $doc = $this->dm->find(get_class($doc), $doc->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternRefUnlisted', $doc->externRefOne); + $this->assertInstanceOf(GH788ExternRefUnlisted::class, $doc->externRefOne); $this->assertEquals($unlisted->id, $doc->externRefOne->id); $this->assertEquals('unlisted', $doc->externRefOne->name); } @@ -289,7 +289,7 @@ public function testRefOneWithInlineDiscriminatorMap() $doc = $this->dm->find(get_class($doc), $doc->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788InlineRefUnlisted', $doc->inlineRefOne); + $this->assertInstanceOf(GH788InlineRefUnlisted::class, $doc->inlineRefOne); $this->assertEquals($unlisted->id, $doc->inlineRefOne->id); $this->assertEquals('unlisted', $doc->inlineRefOne->name); } @@ -308,7 +308,7 @@ public function testRefOneWithNoTargetAndExternalDiscriminatorMap() $doc = $this->dm->find(get_class($doc), $doc->id); - $this->assertInstanceOf(__NAMESPACE__ . '\GH788ExternRefUnlisted', $doc->noTargetRefOne); + $this->assertInstanceOf(GH788ExternRefUnlisted::class, $doc->noTargetRefOne); $this->assertEquals($unlisted->id, $doc->noTargetRefOne->id); $this->assertEquals('unlisted', $doc->noTargetRefOne->name); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH816Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH816Test.php index 19d0fa85c1..839ca8c419 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH816Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH816Test.php @@ -13,22 +13,22 @@ public function testPersistAfterDetachWithIdSet() { $d=new GH816Document(); $d->_id=new ObjectId(); - $this->assertEmpty($this->dm->getRepository('Doctrine\ODM\MongoDB\Tests\GH816Document')->findAll()); + $this->assertEmpty($this->dm->getRepository(GH816Document::class)->findAll()); $this->dm->persist($d); $this->dm->detach($d); $this->dm->flush(); - $this->assertEmpty($this->dm->getRepository('Doctrine\ODM\MongoDB\Tests\GH816Document')->findAll()); + $this->assertEmpty($this->dm->getRepository(GH816Document::class)->findAll()); } public function testPersistAfterDetachWithTitleSet() { $d=new GH816Document(); $d->title='Test'; - $this->assertEmpty($this->dm->getRepository('Doctrine\ODM\MongoDB\Tests\GH816Document')->findAll()); + $this->assertEmpty($this->dm->getRepository(GH816Document::class)->findAll()); $this->dm->persist($d); $this->dm->detach($d); $this->dm->flush(); - $this->assertEmpty($this->dm->getRepository('Doctrine\ODM\MongoDB\Tests\GH816Document')->findAll()); + $this->assertEmpty($this->dm->getRepository(GH816Document::class)->findAll()); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php index b8917c143c..6d50959760 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Proxy\Proxy; use MongoDB\BSON\Binary; use function get_class; @@ -46,7 +47,7 @@ public function testA(\Closure $idGenerator) $this->assertEquals($idGenerator('parent'), $parent->id); $this->assertEquals('parent', $parent->name); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $parent->refOne); + $this->assertInstanceOf(Proxy::class, $parent->refOne); $this->assertFalse($parent->refOne->__isInitialized()); $this->assertEquals($idGenerator('childA'), $parent->refOne->id); $this->assertEquals('childA', $parent->refOne->name); @@ -57,12 +58,12 @@ public function testA(\Closure $idGenerator) /* These proxies will be initialized when we first access the collection * by DocumentPersister::loadReferenceManyCollectionOwningSide(). */ - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $parent->refMany[0]); + $this->assertInstanceOf(Proxy::class, $parent->refMany[0]); $this->assertTrue($parent->refMany[0]->__isInitialized()); $this->assertEquals($idGenerator('childB'), $parent->refMany[0]->id); $this->assertEquals('childB', $parent->refMany[0]->name); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $parent->refMany[1]); + $this->assertInstanceOf(Proxy::class, $parent->refMany[1]); $this->assertTrue($parent->refMany[1]->__isInitialized()); $this->assertEquals($idGenerator('childC'), $parent->refMany[1]->id); $this->assertEquals('childC', $parent->refMany[1]->name); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH880Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH880Test.php index a2887e80c0..71b5fbc81c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH880Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH880Test.php @@ -18,18 +18,18 @@ public function test880() $this->dm->persist($doc); } $this->dm->flush(); - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH880Document'); + $query = $this->dm->createQueryBuilder(GH880Document::class); $cursor = $query->find()->getQuery()->execute(); foreach ($cursor as $c) { $this->assertEquals(1, $c->category); } - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH880Document'); + $query = $this->dm->createQueryBuilder(GH880Document::class); $query->updateMany() ->field('category')->equals(1) ->field('category')->set(3) ->getQuery() ->execute(); - $query = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH880Document'); + $query = $this->dm->createQueryBuilder(GH880Document::class); // here ->refresh() was needed for the test to pass $cursor = $query->find()->refresh()->getQuery()->execute(); foreach ($cursor as $c) { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH897Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH897Test.php index 94cd1bb92d..575a334e4b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH897Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH897Test.php @@ -22,8 +22,8 @@ public function testRecomputeSingleDocumentChangesetForManagedDocumentWithoutCha $this->dm->flush(); $this->dm->clear(); - $documentA = $this->dm->find(__NAMESPACE__ . '\GH897A', $documentA->id); - $documentB = $this->dm->find(__NAMESPACE__ . '\GH897B', $documentB->id); + $documentA = $this->dm->find(GH897A::class, $documentA->id); + $documentB = $this->dm->find(GH897B::class, $documentB->id); $documentB->refOne = $documentA; /* Necessary to inject DocumentManager since it is not currently @@ -34,7 +34,7 @@ public function testRecomputeSingleDocumentChangesetForManagedDocumentWithoutCha $this->dm->flush(); $this->dm->clear(); - $documentA = $this->dm->find(__NAMESPACE__ . '\GH897A', $documentA->id); + $documentA = $this->dm->find(GH897A::class, $documentA->id); $this->assertSame('a-changed', $documentA->name); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH909Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH909Test.php index d97e8e25c9..971b1eacc6 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH909Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH909Test.php @@ -21,7 +21,7 @@ public function testManyReferenceAddAndPersist() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $groups = $user->getGroups(); $this->assertCount(2, $groups); @@ -59,7 +59,7 @@ public function testManyEmbeddedAddAndPersist() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->find('Documents\User', $user->getId()); + $user = $this->dm->find(User::class, $user->getId()); $phoneNumbers = $user->getPhoneNumbers(); $this->assertCount(2, $phoneNumbers); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH921Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH921Test.php index 93ca7921af..db0a29a8ef 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH921Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH921Test.php @@ -19,7 +19,7 @@ public function testPersistentCollectionCountAndIterationShouldBeConsistent() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getRepository(__NAMESPACE__ . '\GH921User')->findOneBy(['name' => 'smith']); + $user = $this->dm->getRepository(GH921User::class)->findOneBy(['name' => 'smith']); $postA = new GH921Post(); $user->addPost($postA); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH927Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH927Test.php index 9fbc1b2d27..76bf152cb0 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH927Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH927Test.php @@ -11,10 +11,10 @@ class GH927Test extends BaseTest { public function testInheritedClassHasAssociationMapping() { - $parentMetadata = $this->dm->getClassMetadata('Doctrine\ODM\MongoDB\Tests\Functional\Ticket\GH927Parent'); + $parentMetadata = $this->dm->getClassMetadata(GH927Parent::class); $this->assertArrayHasKey('reference', $parentMetadata->associationMappings); - $childMetadata = $this->dm->getClassMetadata('Doctrine\ODM\MongoDB\Tests\Functional\Ticket\GH927Child'); + $childMetadata = $this->dm->getClassMetadata(GH927Child::class); $this->assertArrayHasKey('reference', $childMetadata->associationMappings); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH928Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH928Test.php index 4618b1ba65..82c25b5fe1 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH928Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH928Test.php @@ -19,11 +19,11 @@ public function testNullIdCriteriaShouldNotRemoveEverything() $this->dm->flush(); $this->dm->clear(); - $collection = $this->dm->getDocumentCollection(__NAMESPACE__ . '\GH928Document'); + $collection = $this->dm->getDocumentCollection(GH928Document::class); $this->assertEquals(2, $collection->count()); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH928Document') + $qb = $this->dm->createQueryBuilder(GH928Document::class) ->remove() ->field('id')->equals(null) ->getQuery() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php index d8706dab7d..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 @@ -24,25 +25,23 @@ public function testRemoveCascadesThroughProxyDocuments() $this->dm->flush(); $this->dm->clear(); - $foo = $this->dm->find(GH936Document::CLASSNAME, $foo->id); + $foo = $this->dm->find(GH936Document::class, $foo->id); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $foo->ref); + $this->assertInstanceOf(Proxy::class, $foo->ref); $this->dm->remove($foo); $this->dm->flush(); $this->assertCount(3, $listener->removed); - $this->assertNull($this->dm->find(GH936Document::CLASSNAME, $foo->id)); - $this->assertNull($this->dm->find(GH936Document::CLASSNAME, $bar->id)); - $this->assertNull($this->dm->find(GH936Document::CLASSNAME, $baz->id)); + $this->assertNull($this->dm->find(GH936Document::class, $foo->id)); + $this->assertNull($this->dm->find(GH936Document::class, $bar->id)); + $this->assertNull($this->dm->find(GH936Document::class, $baz->id)); } } /** @ODM\Document */ class GH936Document { - public const CLASSNAME = __CLASS__; - /** @ODM\Id */ public $id; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH971Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH971Test.php index 6f15bcea1b..f6919d3baa 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH971Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH971Test.php @@ -18,7 +18,7 @@ public function testUpdateOfInheritedDocumentUsingFindAndUpdate() ]; //first query, create Car with name "Ferrari" - $this->dm->createQueryBuilder(__NAMESPACE__ . '\Car') + $this->dm->createQueryBuilder(Car::class) ->findAndUpdate() ->upsert(true) ->field('name')->equals($name) @@ -27,7 +27,7 @@ public function testUpdateOfInheritedDocumentUsingFindAndUpdate() ->getQuery()->execute(); //second query: update existing "Ferrari" with new feature - $this->dm->createQueryBuilder(__NAMESPACE__ . '\Car') + $this->dm->createQueryBuilder(Car::class) ->findAndUpdate() ->upsert(true) ->field('name')->equals($name) @@ -35,7 +35,7 @@ public function testUpdateOfInheritedDocumentUsingFindAndUpdate() ->field('features')->push($features[1]) ->getQuery()->execute(); - $results = $this->dm->getRepository(__NAMESPACE__ . '\Car')->findAll(); + $results = $this->dm->getRepository(Car::class)->findAll(); $this->assertCount(1, $results); } @@ -45,7 +45,7 @@ public function testUpdateOfInheritedDocumentUsingFindAndUpdate() */ public function testUpsertThrowsExceptionWithIndecisiveDiscriminator() { - $this->dm->createQueryBuilder(__NAMESPACE__ . '\Bicycle') + $this->dm->createQueryBuilder(Bicycle::class) ->findAndUpdate() ->upsert(true) ->field('name')->equals('Cool') @@ -55,7 +55,7 @@ public function testUpsertThrowsExceptionWithIndecisiveDiscriminator() public function testUpsertWillUseProvidedDiscriminator() { - $this->dm->createQueryBuilder(__NAMESPACE__ . '\Bicycle') + $this->dm->createQueryBuilder(Bicycle::class) ->findAndUpdate() ->upsert(true) ->field('type')->equals('tandem') @@ -63,7 +63,7 @@ public function testUpsertWillUseProvidedDiscriminator() ->field('features')->push('2 people') ->getQuery()->execute(); - $results = $this->dm->getRepository(__NAMESPACE__ . '\Tandem')->findAll(); + $results = $this->dm->getRepository(Tandem::class)->findAll(); $this->assertCount(1, $results); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM140Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM140Test.php index 79ddb27fe8..4638811c05 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM140Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM140Test.php @@ -28,7 +28,7 @@ public function testInsertingNestedEmbeddedCollections() $this->dm->flush(); $this->dm->clear(); - $category = $this->dm->getRepository(__NAMESPACE__ . '\Category')->findOneBy(['name' => 'My Category']); + $category = $this->dm->getRepository(Category::class)->findOneBy(['name' => 'My Category']); $post2 = new Post(); $post2->versions->add(new PostVersion('P2V1')); $post2->versions->add(new PostVersion('P2V2')); @@ -37,7 +37,7 @@ public function testInsertingNestedEmbeddedCollections() $this->dm->flush(); $this->dm->clear(); - $category = $this->dm->getRepository(__NAMESPACE__ . '\Category')->findOneBy(['name' => 'My Category']); + $category = $this->dm->getRepository(Category::class)->findOneBy(['name' => 'My Category']); // Should be: 1 Category, 2 Post, 2 PostVersion in each Post $this->assertEquals(2, $category->posts->count()); $this->assertEquals(2, $category->posts->get(0)->versions->count()); @@ -61,7 +61,7 @@ public function testInsertingEmbeddedCollectionWithRefMany() $this->dm->flush(); $this->dm->clear(); - $category = $this->dm->getRepository(__NAMESPACE__ . '\Category')->findOneBy(['name' => 'My Category']); + $category = $this->dm->getRepository(Category::class)->findOneBy(['name' => 'My Category']); $this->assertEquals(1, $category->posts->count()); $this->assertEquals(1, $category->posts->get(0)->comments->count()); } @@ -75,8 +75,8 @@ public function testAddingAnotherEmbeddedDocument() $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); $level1 = new EmbeddedTestLevel1(); $level1->name = 'test level 1 #1'; @@ -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); @@ -114,7 +114,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(2, $test->level1); $this->assertCount(2, $test->level1[0]->level2); $this->assertCount(2, $test->level1[1]->level2); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM43Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM43Test.php index ef45b34199..240d6daa6b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM43Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM43Test.php @@ -18,8 +18,8 @@ public function testTest() '_id' => new ObjectId(), 'name' => 'Jonathan Wage', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\Person')->insertOne($person); - $user = $this->dm->find(__NAMESPACE__ . '\Person', $person['_id']); + $this->dm->getDocumentCollection(Person::class)->insertOne($person); + $user = $this->dm->find(Person::class, $person['_id']); $this->assertEquals('Jonathan', $user->firstName); $this->assertEquals('Wage', $user->lastName); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM45Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM45Test.php index 812c5aad1f..02606b4e70 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM45Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM45Test.php @@ -18,7 +18,7 @@ public function testTest() $this->dm->flush(); $this->dm->clear(); - $a = $this->dm->find(__NAMESPACE__ . '\MODM45A', $a->getId()); + $a = $this->dm->find(MODM45A::class, $a->getId()); $c = ($a->getB() !== null); $this->assertTrue($c); // returns false, while expecting true } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM46Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM46Test.php index 0a18deb2c7..9558feae22 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM46Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM46Test.php @@ -16,9 +16,9 @@ public function testTest() '_id' => new ObjectId(), 'c' => ['value' => 'value'], ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\MODM46A')->insertOne($a); + $this->dm->getDocumentCollection(MODM46A::class)->insertOne($a); - $a = $this->dm->find(__NAMESPACE__ . '\MODM46A', $a['_id']); + $a = $this->dm->find(MODM46A::class, $a['_id']); $this->assertTrue(isset($a->b)); $this->assertEquals('value', $a->b->value); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM47Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM47Test.php index 779cb41114..23e804ebd2 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM47Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM47Test.php @@ -16,9 +16,9 @@ public function testTest() '_id' => new ObjectId(), 'c' => 'c value', ]; - $this->dm->getDocumentCollection(__NAMESPACE__ . '\MODM47A')->insertOne($a); + $this->dm->getDocumentCollection(MODM47A::class)->insertOne($a); - $a = $this->dm->find(__NAMESPACE__ . '\MODM47A', $a['_id']); + $a = $this->dm->find(MODM47A::class, $a['_id']); $this->assertEquals('c value', $a->b); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM48Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM48Test.php index edea9c4eb5..eadda08a9a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM48Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM48Test.php @@ -17,7 +17,7 @@ public function testTest() $this->dm->flush(); $this->dm->clear(); - $a = $this->dm->find(__NAMESPACE__ . '\MODM48A', $a->id); + $a = $this->dm->find(MODM48A::class, $a->id); $this->assertNotNull($a); $a->getB()->setVal('test'); @@ -25,7 +25,7 @@ public function testTest() $this->dm->flush(); $this->dm->clear(); - $a = $this->dm->find(__NAMESPACE__ . '\MODM48A', $a->id); + $a = $this->dm->find(MODM48A::class, $a->id); $this->assertEquals('test', $a->getB()->getVal()); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM56Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM56Test.php index 70fea20874..ff36e20c04 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM56Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM56Test.php @@ -23,7 +23,7 @@ public function testTest() $parent->children[] = $childTwo; $this->dm->flush(); - $test = $this->dm->getDocumentCollection(__NAMESPACE__ . '\MODM56Parent')->findOne(); + $test = $this->dm->getDocumentCollection(MODM56Parent::class)->findOne(); $this->assertEquals('Parent', $test['name']); $this->assertInstanceOf(UTCDateTime::class, $test['updatedAt']); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM62Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM62Test.php index 62dfebe510..a8edb2d5d7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM62Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM62Test.php @@ -20,7 +20,7 @@ public function testTest() $this->dm->flush(); $this->dm->clear(); - $test = $this->dm->find(__NAMESPACE__ . '\MODM62Document', $test->id); + $test = $this->dm->find(MODM62Document::class, $test->id); $this->assertEquals(['test', 'test2'], $test->b); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM65Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM65Test.php index b4b51042a5..1cfa747aee 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM65Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM65Test.php @@ -19,11 +19,11 @@ public function testTest() $this->dm->flush(); $this->dm->clear(); - $user = $this->dm->getDocumentCollection(__NAMESPACE__ . '\MODM65User')->findOne(); + $user = $this->dm->getDocumentCollection(MODM65User::class)->findOne(); $this->assertTrue(isset($user['snu']['lN'])); $this->assertTrue(isset($user['snu']['fN'])); - $user = $this->dm->find(__NAMESPACE__ . '\MODM65User', $user['_id']); + $user = $this->dm->find(MODM65User::class, $user['_id']); $this->assertEquals('Jonathan', $user->socialNetworkUser->firstName); $this->assertEquals('Wage', $user->socialNetworkUser->lastName); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM67Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM67Test.php index 24d77a5369..5c32d2132d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM67Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM67Test.php @@ -45,7 +45,7 @@ public function testDerivedClassListener() $dm->clear(); - $testDoc = $dm->find(__NAMESPACE__ . '\MODM67DerivedClass', $testDoc->id); + $testDoc = $dm->find(MODM67DerivedClass::class, $testDoc->id); $testDoc->embedOne->numAccesses = 1; $dm->flush(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM72Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM72Test.php index 301a0b2f09..44c07c0c25 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM72Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM72Test.php @@ -11,7 +11,7 @@ class MODM72Test extends BaseTest { public function testTest() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\MODM72User'); + $class = $this->dm->getClassMetadata(MODM72User::class); $this->assertEquals(['test' => 'test'], $class->fieldMappings['name']['options']); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php index d3b4aa82a9..2f8e182cfa 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php @@ -39,7 +39,7 @@ public function testDocumentIdWithSameProxyId() $dm->flush(); $dm->clear(); - $doc1 = $dm->find(__NAMESPACE__ . '\MODM81TestDocument', $doc1->getId()); + $doc1 = $dm->find(MODM81TestDocument::class, $doc1->getId()); $doc1->setName('Document1Change'); $this->assertSame($doc1, $doc1->getEmbeddedDocuments()->get(0)->getRefTodocument1()); @@ -47,7 +47,7 @@ public function testDocumentIdWithSameProxyId() $dm->flush(); $dm->clear(); - $doc1 = $dm->find(__NAMESPACE__ . '\MODM81TestDocument', $doc1->getId()); + $doc1 = $dm->find(MODM81TestDocument::class, $doc1->getId()); $this->assertNotNull($doc1); $this->assertEquals('Document1Change', $doc1->getName()); @@ -56,7 +56,7 @@ public function testDocumentIdWithSameProxyId() $dm->flush(); $dm->clear(); - $doc1 = $dm->find(__NAMESPACE__ . '\MODM81TestDocument', $doc1->getId()); + $doc1 = $dm->find(MODM81TestDocument::class, $doc1->getId()); $this->assertEquals('Document1ProxyChange', $doc1->getName()); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM83Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM83Test.php index 727ab0c12e..608c9798bd 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM83Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM83Test.php @@ -38,15 +38,15 @@ public function testDocumentWithEmbeddedDocumentNotUpdated() $dm->flush(); $dm->clear(); - $won = $dm->find(__NAMESPACE__ . '\MODM83TestDocument', $won->id); - $too = $dm->find(__NAMESPACE__ . '\MODM83OtherDocument', $too->id); + $won = $dm->find(MODM83TestDocument::class, $won->id); + $too = $dm->find(MODM83OtherDocument::class, $too->id); $too->name = 'Bob'; $dm->flush(); $dm->clear(); $called = [ - Events::preUpdate => [__NAMESPACE__ . '\MODM83OtherDocument'], - Events::postUpdate => [__NAMESPACE__ . '\MODM83OtherDocument'], + Events::preUpdate => [MODM83OtherDocument::class], + Events::postUpdate => [MODM83OtherDocument::class], ]; $this->assertEquals($called, $this->listener->called); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM88Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM88Test.php index 2ce8ad3e16..84d22cf167 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM88Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM88Test.php @@ -18,7 +18,7 @@ public function testTest() $this->dm->flush(); $this->dm->clear(); - $qb = $this->dm->createQueryBuilder('Documents\Article') + $qb = $this->dm->createQueryBuilder(Article::class) ->select('_id', 'title'); $q = $qb->getQuery(); $document = $q->getSingleResult(); @@ -29,7 +29,7 @@ public function testTest() $document->setTitle('changed'); $this->dm->flush(); - $check = $this->dm->getDocumentCollection('Documents\Article')->findOne(); + $check = $this->dm->getDocumentCollection(Article::class)->findOne(); $this->assertEquals('changed', $check['title']); $this->assertEquals('Test Body', $check['body']); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM90Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM90Test.php index abb03e992b..edb1deff46 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM90Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM90Test.php @@ -35,7 +35,7 @@ public function testDocumentWithEmbeddedDocumentNotUpdatedOnFlush() $dm->flush(); $dm->clear(); - $testDoc = $dm->find(__NAMESPACE__ . '\MODM90TestDocument', $testDoc->id); + $testDoc = $dm->find(MODM90TestDocument::class, $testDoc->id); // run a flush, in theory, nothing should be flushed. $dm->flush(); @@ -62,7 +62,7 @@ public function testDiscriminatorFieldValuePresentIfRealProperty() $dm->flush(); $dm->clear(); - $testDoc = $dm->find(__NAMESPACE__ . '\MODM90TestDocument', $testDoc->id); + $testDoc = $dm->find(MODM90TestDocument::class, $testDoc->id); $this->assertEquals($testDoc->embedded->type, 'test2'); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM91Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM91Test.php index 7860556aa7..5f64795b61 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM91Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM91Test.php @@ -35,7 +35,7 @@ public function testDocumentWithEmbeddedDocumentNotUpdated() $dm->flush(); $dm->clear(); - $testDoc = $dm->find(__NAMESPACE__ . '\MODM91TestDocument', $testDoc->id); + $testDoc = $dm->find(MODM91TestDocument::class, $testDoc->id); $dm->flush(); $dm->clear(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM92Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM92Test.php index f5b5b71733..e68cde64c8 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM92Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM92Test.php @@ -21,7 +21,7 @@ public function testDocumentWithEmbeddedDocuments() $this->dm->flush(); $this->dm->clear(); - $testDoc = $this->dm->find(__NAMESPACE__ . '\MODM92TestDocument', $testDoc->id); + $testDoc = $this->dm->find(MODM92TestDocument::class, $testDoc->id); $this->assertEquals($embeddedDocuments, $testDoc->embeddedDocuments->toArray()); $embeddedDocuments = [new MODM92TestEmbeddedDocument('bar')]; @@ -31,7 +31,7 @@ public function testDocumentWithEmbeddedDocuments() $this->dm->flush(); $this->dm->clear(); - $testDoc = $this->dm->find(__NAMESPACE__ . '\MODM92TestDocument', $testDoc->id); + $testDoc = $this->dm->find(MODM92TestDocument::class, $testDoc->id); $this->assertEquals($embeddedDocuments, $testDoc->embeddedDocuments->toArray()); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM95Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM95Test.php index ec08cd1d32..af9d90c612 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM95Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM95Test.php @@ -21,7 +21,7 @@ public function testDocumentWithEmbeddedDocuments() $this->dm->flush(); $this->dm->clear(); - $testDoc = $this->dm->find(__NAMESPACE__ . '\MODM95TestDocument', $testDoc->id); + $testDoc = $this->dm->find(MODM95TestDocument::class, $testDoc->id); $this->assertEquals($embeddedDocuments, $testDoc->embeddedDocuments->toArray()); @@ -29,14 +29,14 @@ public function testDocumentWithEmbeddedDocuments() $this->dm->flush(); $this->dm->clear(); - $testDocLoad = $this->dm->find(__NAMESPACE__ . '\MODM95TestDocument', $testDoc->id); + $testDocLoad = $this->dm->find(MODM95TestDocument::class, $testDoc->id); $this->assertNull($testDocLoad); $this->dm->persist($testDoc); $this->dm->flush(); $this->dm->clear(); - $testDocLoad = $this->dm->find(__NAMESPACE__ . '\MODM95TestDocument', $testDoc->id); + $testDocLoad = $this->dm->find(MODM95TestDocument::class, $testDoc->id); $this->assertNotNull($testDocLoad); $this->assertEquals($embeddedDocuments, $testDocLoad->embeddedDocuments->toArray()); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php b/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php index 50c36b8918..38085f50e4 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php @@ -4,21 +4,24 @@ namespace Doctrine\ODM\MongoDB\Tests; +use DateTime; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\PersistentCollection; +use Doctrine\ODM\MongoDB\Proxy\Proxy; use Doctrine\ODM\MongoDB\Query\Query; class HydratorTest extends BaseTest { public function testHydrator() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\HydrationClosureUser'); + $class = $this->dm->getClassMetadata(HydrationClosureUser::class); $user = new HydrationClosureUser(); $this->dm->getHydratorFactory()->hydrate($user, [ '_id' => 1, 'title' => null, 'name' => 'jon', - 'birthdate' => new \DateTime('1961-01-01'), + 'birthdate' => new DateTime('1961-01-01'), 'referenceOne' => ['$id' => '1'], 'referenceMany' => [ ['$id' => '1'], @@ -33,25 +36,25 @@ public function testHydrator() $this->assertEquals(1, $user->id); $this->assertNull($user->title); $this->assertEquals('jon', $user->name); - $this->assertInstanceOf('DateTime', $user->birthdate); - $this->assertInstanceOf(__NAMESPACE__ . '\HydrationClosureReferenceOne', $user->referenceOne); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\PersistentCollection', $user->referenceMany); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user->referenceMany[0]); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user->referenceMany[1]); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\PersistentCollection', $user->embedMany); + $this->assertInstanceOf(DateTime::class, $user->birthdate); + $this->assertInstanceOf(HydrationClosureReferenceOne::class, $user->referenceOne); + $this->assertInstanceOf(PersistentCollection::class, $user->referenceMany); + $this->assertInstanceOf(Proxy::class, $user->referenceMany[0]); + $this->assertInstanceOf(Proxy::class, $user->referenceMany[1]); + $this->assertInstanceOf(PersistentCollection::class, $user->embedMany); $this->assertEquals('jon', $user->embedOne->name); $this->assertEquals('jon', $user->embedMany[0]->name); } public function testReadOnly() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\HydrationClosureUser'); + $class = $this->dm->getClassMetadata(HydrationClosureUser::class); $user = new HydrationClosureUser(); $this->dm->getHydratorFactory()->hydrate($user, [ '_id' => 1, 'name' => 'maciej', - 'birthdate' => new \DateTime('1961-01-01'), + 'birthdate' => new DateTime('1961-01-01'), 'embedOne' => ['name' => 'maciej'], 'embedMany' => [ ['name' => 'maciej'], diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php index 20bf5abaab..4aa3e18a47 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php @@ -21,7 +21,7 @@ abstract protected function _loadDriver(); */ public function testLoadMapping() { - $className = __NAMESPACE__ . '\AbstractMappingDriverUser'; + $className = AbstractMappingDriverUser::class; $mappingDriver = $this->_loadDriver(); $class = new ClassMetadata($className); @@ -118,12 +118,12 @@ public function testAssociationMappings($class) */ public function testGetAssociationTargetClass($class) { - $this->assertEquals('Doctrine\ODM\MongoDB\Tests\Mapping\Address', $class->getAssociationTargetClass('address')); - $this->assertEquals('Doctrine\ODM\MongoDB\Tests\Mapping\Group', $class->getAssociationTargetClass('groups')); - $this->assertEquals('Doctrine\ODM\MongoDB\Tests\Mapping\Phonenumber', $class->getAssociationTargetClass('phonenumbers')); - $this->assertEquals('Doctrine\ODM\MongoDB\Tests\Mapping\Phonenumber', $class->getAssociationTargetClass('morePhoneNumbers')); - $this->assertEquals('Doctrine\ODM\MongoDB\Tests\Mapping\Phonenumber', $class->getAssociationTargetClass('embeddedPhonenumber')); - $this->assertEquals('Doctrine\ODM\MongoDB\Tests\Mapping\Phonenumber', $class->getAssociationTargetClass('otherPhonenumbers')); + $this->assertEquals(Address::class, $class->getAssociationTargetClass('address')); + $this->assertEquals(Group::class, $class->getAssociationTargetClass('groups')); + $this->assertEquals(Phonenumber::class, $class->getAssociationTargetClass('phonenumbers')); + $this->assertEquals(Phonenumber::class, $class->getAssociationTargetClass('morePhoneNumbers')); + $this->assertEquals(Phonenumber::class, $class->getAssociationTargetClass('embeddedPhonenumber')); + $this->assertEquals(Phonenumber::class, $class->getAssociationTargetClass('otherPhonenumbers')); } /** @@ -273,7 +273,7 @@ public function testDiscriminator($class) $this->assertTrue(isset($class->discriminatorMap)); $this->assertTrue(isset($class->defaultDiscriminatorValue)); $this->assertEquals('discr', $class->discriminatorField); - $this->assertEquals(['default' => 'Doctrine\ODM\MongoDB\Tests\Mapping\AbstractMappingDriverUser'], $class->discriminatorMap); + $this->assertEquals(['default' => AbstractMappingDriverUser::class], $class->discriminatorMap); $this->assertEquals('default', $class->defaultDiscriminatorValue); return $class; @@ -290,8 +290,8 @@ public function testEmbedDiscriminator($class) $this->assertTrue(isset($class->fieldMappings['otherPhonenumbers']['defaultDiscriminatorValue'])); $this->assertEquals('discr', $class->fieldMappings['otherPhonenumbers']['discriminatorField']); $this->assertEquals([ - 'home' => 'Doctrine\ODM\MongoDB\Tests\Mapping\HomePhonenumber', - 'work' => 'Doctrine\ODM\MongoDB\Tests\Mapping\WorkPhonenumber', + 'home' => HomePhonenumber::class, + 'work' => WorkPhonenumber::class, ], $class->fieldMappings['otherPhonenumbers']['discriminatorMap']); $this->assertEquals('home', $class->fieldMappings['otherPhonenumbers']['defaultDiscriminatorValue']); @@ -309,8 +309,8 @@ public function testReferenceDiscriminator($class) $this->assertTrue(isset($class->fieldMappings['phonenumbers']['defaultDiscriminatorValue'])); $this->assertEquals('discr', $class->fieldMappings['phonenumbers']['discriminatorField']); $this->assertEquals([ - 'home' => 'Doctrine\ODM\MongoDB\Tests\Mapping\HomePhonenumber', - 'work' => 'Doctrine\ODM\MongoDB\Tests\Mapping\WorkPhonenumber', + 'home' => HomePhonenumber::class, + 'work' => WorkPhonenumber::class, ], $class->fieldMappings['phonenumbers']['discriminatorMap']); $this->assertEquals('home', $class->fieldMappings['phonenumbers']['defaultDiscriminatorValue']); @@ -521,13 +521,13 @@ public static function loadMetadata(ClassMetadata $metadata) ]); $metadata->mapOneReference([ 'fieldName' => 'address', - 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Address', + 'targetDocument' => Address::class, 'cascade' => [0 => 'remove'], ]); $metadata->mapManyReference([ 'fieldName' => 'phonenumbers', - 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', - 'collectionClass' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\PhonenumberCollection', + 'targetDocument' => Phonenumber::class, + 'collectionClass' => PhonenumberCollection::class, 'cascade' => [1 => 'persist'], 'discriminatorField' => 'discr', 'discriminatorMap' => [ @@ -539,12 +539,12 @@ public static function loadMetadata(ClassMetadata $metadata) $metadata->mapManyReference([ 'fieldName' => 'morePhoneNumbers', 'name' => 'more_phone_numbers', - 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', - 'collectionClass' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\PhonenumberCollection', + 'targetDocument' => Phonenumber::class, + 'collectionClass' => PhonenumberCollection::class, ]); $metadata->mapManyReference([ 'fieldName' => 'groups', - 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Group', + 'targetDocument' => Group::class, 'cascade' => [ 0 => 'remove', 1 => 'persist', @@ -559,7 +559,7 @@ public static function loadMetadata(ClassMetadata $metadata) ]); $metadata->mapManyEmbedded([ 'fieldName' => 'otherPhonenumbers', - 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', + 'targetDocument' => Phonenumber::class, 'discriminatorField' => 'discr', 'discriminatorMap' => [ 'home' => 'HomePhonenumber', diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AnnotationDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AnnotationDriverTest.php index c6df291535..da62477d51 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AnnotationDriverTest.php @@ -9,6 +9,7 @@ use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; use Doctrine\ODM\MongoDB\Mapping\MappingException; +use Documents\CmsUser; class AnnotationDriverTest extends AbstractMappingDriverTest { @@ -82,11 +83,11 @@ public function testLoadMetadataForNonDocumentThrowsException() */ public function testColumnWithMissingTypeDefaultsToString() { - $cm = new ClassMetadata('Doctrine\ODM\MongoDB\Tests\Mapping\ColumnWithoutType'); + $cm = new ClassMetadata(ColumnWithoutType::class); $reader = new AnnotationReader(); $annotationDriver = new AnnotationDriver($reader); - $annotationDriver->loadMetadataForClass('Doctrine\ODM\MongoDB\Tests\Mapping\InvalidColumn', $cm); + $annotationDriver->loadMetadataForClass(InvalidColumn::class, $cm); $this->assertEquals('id', $cm->fieldMappings['id']['type']); } @@ -123,12 +124,10 @@ public function testGetAllClassNamesIsIdempotentEvenWithDifferentDriverInstances */ public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate() { - $rightClassName = 'Documents\CmsUser'; - $annotationDriver = $this->_loadDriverForCMSDocuments(); $classes = $annotationDriver->getAllClassNames(); - $this->assertContains($rightClassName, $classes); + $this->assertContains(CmsUser::class, $classes); } /** diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php index 8f5edbd760..1ab9dca5d6 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php @@ -27,12 +27,12 @@ public function setUp() */ public function testGetMetadataForTransientClassThrowsException() { - $this->factory->getMetadataFor('Doctrine\ODM\MongoDB\Tests\Mapping\TransientBaseClass'); + $this->factory->getMetadataFor(TransientBaseClass::class); } public function testGetMetadataForSubclassWithTransientBaseClass() { - $class = $this->factory->getMetadataFor('Doctrine\ODM\MongoDB\Tests\Mapping\DocumentSubClass'); + $class = $this->factory->getMetadataFor(DocumentSubClass::class); $this->assertEmpty($class->subClasses); $this->assertEmpty($class->parentClasses); @@ -42,7 +42,7 @@ public function testGetMetadataForSubclassWithTransientBaseClass() public function testGetMetadataForSubclassWithMappedSuperclass() { - $class = $this->factory->getMetadataFor('Doctrine\ODM\MongoDB\Tests\Mapping\DocumentSubClass2'); + $class = $this->factory->getMetadataFor(DocumentSubClass2::class); $this->assertEmpty($class->subClasses); $this->assertEmpty($class->parentClasses); @@ -64,7 +64,7 @@ public function testGetMetadataForSubclassWithMappedSuperclass() */ public function testSerializationWithPrivateFieldsFromMappedSuperclass() { - $class = $this->factory->getMetadataFor(__NAMESPACE__ . '\\DocumentSubClass2'); + $class = $this->factory->getMetadataFor(DocumentSubClass2::class); $class2 = unserialize(serialize($class)); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataFactoryTest.php index 28e87487ee..5d16e5ec24 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataFactoryTest.php @@ -4,6 +4,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Mapping; +use Doctrine\Common\EventManager; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory; @@ -17,7 +18,7 @@ class ClassMetadataFactoryTest extends BaseTest public function testGetMetadataForSingleClass() { // Self-made metadata - $cm1 = new ClassMetadata('Doctrine\ODM\MongoDB\Tests\Mapping\TestDocument1'); + $cm1 = new ClassMetadata(TestDocument1::class); $cm1->setCollection('group'); // Add a mapped field $cm1->mapField(['fieldName' => 'name', 'type' => 'string']); @@ -29,7 +30,7 @@ public function testGetMetadataForSingleClass() // SUT $cmf = new ClassMetadataFactoryTestSubject(); - $cmf->setMetadataFor('Doctrine\ODM\MongoDB\Tests\Mapping\TestDocument1', $cm1); + $cmf->setMetadataFor(TestDocument1::class, $cm1); // Prechecks $this->assertEquals([], $cm1->parentClasses); @@ -38,7 +39,7 @@ public function testGetMetadataForSingleClass() $this->assertCount(4, $cm1->fieldMappings); // Go - $cm1 = $cmf->getMetadataFor('Doctrine\ODM\MongoDB\Tests\Mapping\TestDocument1'); + $cm1 = $cmf->getMetadataFor(TestDocument1::class); $this->assertEquals('group', $cm1->collection); $this->assertEquals([], $cm1->parentClasses); @@ -72,7 +73,7 @@ protected function getMockDocumentManager($driver) $config = new Configuration(); $config->setMetadataDriverImpl($driver); - $em = $this->createMock('Doctrine\Common\EventManager'); + $em = $this->createMock(EventManager::class); $dm = new DocumentManagerMock(); $dm->config = $config; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php index 353e2df936..a9b4d99643 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php @@ -16,7 +16,7 @@ public function testEvent() $metadataFactory = $this->dm->getMetadataFactory(); $evm = $this->dm->getEventManager(); $evm->addEventListener(Events::loadClassMetadata, $this); - $classMetadata = $metadataFactory->getMetadataFor('Doctrine\ODM\MongoDB\Tests\Mapping\LoadEventTestDocument'); + $classMetadata = $metadataFactory->getMetadataFor(LoadEventTestDocument::class); $this->assertTrue($classMetadata->hasField('about')); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php index 8d6b247a72..2f671841ef 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php @@ -9,13 +9,17 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Mapping\MappingException; +use Doctrine\ODM\MongoDB\Proxy\Proxy; use Doctrine\ODM\MongoDB\Tests\BaseTest; use Doctrine\ODM\MongoDB\Utility\CollectionHelper; use Documents\Account; +use Documents\Address; use Documents\Album; +use Documents\Bar; use Documents\CmsUser; use Documents\SpecialUser; use Documents\User; +use Documents\UserRepository; use function array_merge; use function get_class; use function serialize; @@ -25,13 +29,13 @@ class ClassMetadataTest extends BaseTest { public function testClassMetadataInstanceSerialization() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); // Test initial state $this->assertCount(0, $cm->getReflectionProperties()); $this->assertInstanceOf(\ReflectionClass::class, $cm->reflClass); - $this->assertEquals('Documents\CmsUser', $cm->name); - $this->assertEquals('Documents\CmsUser', $cm->rootDocumentName); + $this->assertEquals(CmsUser::class, $cm->name); + $this->assertEquals(CmsUser::class, $cm->rootDocumentName); $this->assertEquals([], $cm->subClasses); $this->assertEquals([], $cm->parentClasses); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm->inheritanceType); @@ -58,18 +62,18 @@ public function testClassMetadataInstanceSerialization() $this->assertGreaterThan(0, $cm->getReflectionProperties()); $this->assertEquals('Documents', $cm->namespace); $this->assertInstanceOf(\ReflectionClass::class, $cm->reflClass); - $this->assertEquals('Documents\CmsUser', $cm->name); + $this->assertEquals(CmsUser::class, $cm->name); $this->assertEquals('UserParent', $cm->rootDocumentName); $this->assertEquals(['Documents\One', 'Documents\Two', 'Documents\Three'], $cm->subClasses); $this->assertEquals(['UserParent'], $cm->parentClasses); - $this->assertEquals('Documents\UserRepository', $cm->customRepositoryClassName); + $this->assertEquals(UserRepository::class, $cm->customRepositoryClassName); $this->assertEquals('disc', $cm->discriminatorField); $this->assertInternalType('array', $cm->getFieldMapping('phonenumbers')); $this->assertCount(1, $cm->fieldMappings); $this->assertCount(1, $cm->associationMappings); $this->assertEquals(['keys' => ['_id' => 1], 'options' => []], $cm->getShardKey()); $mapping = $cm->getFieldMapping('phonenumbers'); - $this->assertEquals('Documents\Bar', $mapping['targetDocument']); + $this->assertEquals(Bar::class, $mapping['targetDocument']); $this->assertTrue($cm->getCollectionCapped()); $this->assertEquals(1000, $cm->getCollectionMax()); $this->assertEquals(500, $cm->getCollectionSize()); @@ -88,7 +92,7 @@ public function testOwningSideAndInverseSide() public function testFieldIsNullable() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); // Explicit Nullable $cm->mapField(['fieldName' => 'status', 'nullable' => true, 'type' => 'string', 'length' => 50]); @@ -121,7 +125,7 @@ public function testMapAssocationInGlobalNamespace() public function testMapManyToManyJoinTableDefaults() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->mapManyEmbedded( [ 'fieldName' => 'groups', @@ -162,7 +166,7 @@ public function testSetSubClassesInGlobalNamespace() public function testDuplicateFieldMapping() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $a1 = ['reference' => true, 'type' => 'many', 'fieldName' => 'name', 'targetDocument' => 'stdClass']; $a2 = ['type' => 'string', 'fieldName' => 'name']; @@ -174,7 +178,7 @@ public function testDuplicateFieldMapping() public function testDuplicateColumnNameDiscriminatorColumnThrowsMappingException() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->mapField(['fieldName' => 'name']); $this->expectException(MappingException::class); @@ -183,7 +187,7 @@ public function testDuplicateColumnNameDiscriminatorColumnThrowsMappingException public function testDuplicateFieldNameDiscriminatorColumn2ThrowsMappingException() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->setDiscriminatorField('name'); $this->expectException(MappingException::class); @@ -192,7 +196,7 @@ public function testDuplicateFieldNameDiscriminatorColumn2ThrowsMappingException public function testDuplicateFieldAndAssocationMapping1() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->mapField(['fieldName' => 'name']); $cm->mapOneEmbedded(['fieldName' => 'name', 'targetDocument' => 'CmsUser']); @@ -201,7 +205,7 @@ public function testDuplicateFieldAndAssocationMapping1() public function testDuplicateFieldAndAssocationMapping2() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->mapOneEmbedded(['fieldName' => 'name', 'targetDocument' => 'CmsUser']); $cm->mapField(['fieldName' => 'name', 'columnName' => 'name', 'type' => 'string']); @@ -213,7 +217,7 @@ public function testDuplicateFieldAndAssocationMapping2() */ public function testMapNotExistingFieldThrowsException() { - $cm = new ClassMetadata('Documents\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->mapField(['fieldName' => 'namee', 'columnName' => 'name', 'type' => 'string']); } @@ -307,7 +311,7 @@ public function testDefaultDiscriminatorField() public function testGetFieldValue() { $document = new Album('ten'); - $metadata = $this->dm->getClassMetadata('Documents\Album'); + $metadata = $this->dm->getClassMetadata(Album::class); $this->assertEquals($document->getName(), $metadata->getFieldValue($document, 'name')); } @@ -319,11 +323,11 @@ public function testGetFieldValueInitializesProxy() $this->dm->flush(); $this->dm->clear(); - $proxy = $this->dm->getReference('Documents\Album', $document->getId()); - $metadata = $this->dm->getClassMetadata('Documents\Album'); + $proxy = $this->dm->getReference(Album::class, $document->getId()); + $metadata = $this->dm->getClassMetadata(Album::class); $this->assertEquals($document->getName(), $metadata->getFieldValue($proxy, 'name')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $proxy); + $this->assertInstanceOf(Proxy::class, $proxy); $this->assertTrue($proxy->__isInitialized()); } @@ -334,18 +338,18 @@ public function testGetFieldValueOfIdentifierDoesNotInitializeProxy() $this->dm->flush(); $this->dm->clear(); - $proxy = $this->dm->getReference('Documents\Album', $document->getId()); - $metadata = $this->dm->getClassMetadata('Documents\Album'); + $proxy = $this->dm->getReference(Album::class, $document->getId()); + $metadata = $this->dm->getClassMetadata(Album::class); $this->assertEquals($document->getId(), $metadata->getFieldValue($proxy, 'id')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $proxy); + $this->assertInstanceOf(Proxy::class, $proxy); $this->assertFalse($proxy->__isInitialized()); } public function testSetFieldValue() { $document = new Album('ten'); - $metadata = $this->dm->getClassMetadata('Documents\Album'); + $metadata = $this->dm->getClassMetadata(Album::class); $metadata->setFieldValue($document, 'name', 'nevermind'); @@ -359,17 +363,17 @@ public function testSetFieldValueWithProxy() $this->dm->flush(); $this->dm->clear(); - $proxy = $this->dm->getReference('Documents\Album', $document->getId()); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $proxy); + $proxy = $this->dm->getReference(Album::class, $document->getId()); + $this->assertInstanceOf(Proxy::class, $proxy); - $metadata = $this->dm->getClassMetadata('Documents\Album'); + $metadata = $this->dm->getClassMetadata(Album::class); $metadata->setFieldValue($proxy, 'name', 'nevermind'); $this->dm->flush(); $this->dm->clear(); - $proxy = $this->dm->getReference('Documents\Album', $document->getId()); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $proxy); + $proxy = $this->dm->getReference(Album::class, $document->getId()); + $this->assertInstanceOf(Proxy::class, $proxy); $this->assertEquals('nevermind', $proxy->getName()); } @@ -390,7 +394,7 @@ public function testSetCustomRepositoryClass() public function testEmbeddedAssociationsAlwaysCascade() { - $class = $this->dm->getClassMetadata(__NAMESPACE__ . '\EmbeddedAssociationsCascadeTest'); + $class = $this->dm->getClassMetadata(EmbeddedAssociationsCascadeTest::class); $this->assertTrue($class->fieldMappings['address']['isCascadeRemove']); $this->assertTrue($class->fieldMappings['address']['isCascadePersist']); @@ -411,10 +415,10 @@ public function testEmbeddedAssociationsAlwaysCascade() */ public function testEmbedWithCascadeThrowsMappingException() { - $class = new ClassMetadata(__NAMESPACE__ . '\EmbedWithCascadeTest'); + $class = new ClassMetadata(EmbedWithCascadeTest::class); $class->mapOneEmbedded([ 'fieldName' => 'address', - 'targetDocument' => 'Documents\Address', + 'targetDocument' => Address::class, 'cascade' => 'all', ]); } @@ -425,7 +429,7 @@ public function testEmbedWithCascadeThrowsMappingException() */ public function testInvokeLifecycleCallbacksShouldRequireInstanceOfClass() { - $class = $this->dm->getClassMetadata('\Documents\User'); + $class = $this->dm->getClassMetadata(User::class); $document = new \stdClass(); $this->assertInstanceOf('\stdClass', $document); @@ -435,10 +439,10 @@ public function testInvokeLifecycleCallbacksShouldRequireInstanceOfClass() public function testInvokeLifecycleCallbacksAllowsInstanceOfClass() { - $class = $this->dm->getClassMetadata('\Documents\User'); + $class = $this->dm->getClassMetadata(User::class); $document = new Specialuser(); - $this->assertInstanceOf('\Documents\SpecialUser', $document); + $this->assertInstanceOf(SpecialUser::class, $document); $class->invokeLifecycleCallbacks(Events::prePersist, $document); } @@ -450,10 +454,10 @@ public function testInvokeLifecycleCallbacksShouldAllowProxyOfExactClass() $this->dm->flush(); $this->dm->clear(); - $class = $this->dm->getClassMetadata('\Documents\User'); - $proxy = $this->dm->getReference('\Documents\User', $document->getId()); + $class = $this->dm->getClassMetadata(User::class); + $proxy = $this->dm->getReference(User::class, $document->getId()); - $this->assertInstanceOf('\Documents\User', $proxy); + $this->assertInstanceOf(User::class, $proxy); $class->invokeLifecycleCallbacks(Events::prePersist, $proxy); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php index 23189d6d57..28dc9be579 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php @@ -5,8 +5,17 @@ namespace Doctrine\ODM\MongoDB\Tests\Mapping\Driver; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; +use Documents\Account; +use Documents\Address; +use Documents\Group; +use Documents\Phonenumber; +use Documents\Profile; use PHPUnit\Framework\TestCase; +use TestDocuments\EmbeddedDocument; +use TestDocuments\PartialFilterDocument; use TestDocuments\PrimedCollectionDocument; +use TestDocuments\QueryResultDocument; +use TestDocuments\User; require_once 'fixtures/InvalidPartialFilterDocument.php'; require_once 'fixtures/PartialFilterDocument.php'; @@ -31,8 +40,8 @@ public function tearDown() public function testDriver() { - $classMetadata = new ClassMetadata('TestDocuments\User'); - $this->driver->loadMetadataForClass('TestDocuments\User', $classMetadata); + $classMetadata = new ClassMetadata(User::class); + $this->driver->loadMetadataForClass(User::class, $classMetadata); $this->assertEquals([ 'fieldName' => 'id', @@ -109,7 +118,7 @@ public function testDriver() 'name' => 'address', 'type' => 'one', 'embedded' => true, - 'targetDocument' => 'Documents\Address', + 'targetDocument' => Address::class, 'collectionClass' => null, 'isCascadeDetach' => true, 'isCascadeMerge' => true, @@ -128,7 +137,7 @@ public function testDriver() 'name' => 'phonenumbers', 'type' => 'many', 'embedded' => true, - 'targetDocument' => 'Documents\Phonenumber', + 'targetDocument' => Phonenumber::class, 'collectionClass' => null, 'isCascadeDetach' => true, 'isCascadeMerge' => true, @@ -148,7 +157,7 @@ public function testDriver() 'type' => 'one', 'reference' => true, 'storeAs' => ClassMetadata::REFERENCE_STORE_AS_ID, - 'targetDocument' => 'Documents\Profile', + 'targetDocument' => Profile::class, 'collectionClass' => null, 'cascade' => ['remove', 'persist', 'refresh', 'merge', 'detach'], 'isCascadeDetach' => true, @@ -176,7 +185,7 @@ public function testDriver() 'type' => 'one', 'reference' => true, 'storeAs' => ClassMetadata::REFERENCE_STORE_AS_DB_REF, - 'targetDocument' => 'Documents\Account', + 'targetDocument' => Account::class, 'collectionClass' => null, 'cascade' => ['remove', 'persist', 'refresh', 'merge', 'detach'], 'isCascadeDetach' => true, @@ -204,7 +213,7 @@ public function testDriver() 'type' => 'many', 'reference' => true, 'storeAs' => ClassMetadata::REFERENCE_STORE_AS_DB_REF, - 'targetDocument' => 'Documents\Group', + 'targetDocument' => Group::class, 'collectionClass' => null, 'cascade' => ['remove', 'persist', 'refresh', 'merge', 'detach'], 'isCascadeDetach' => true, @@ -240,8 +249,8 @@ public function testDriver() $classMetadata->alsoLoadMethods ); - $classMetadata = new ClassMetadata('TestDocuments\EmbeddedDocument'); - $this->driver->loadMetadataForClass('TestDocuments\EmbeddedDocument', $classMetadata); + $classMetadata = new ClassMetadata(EmbeddedDocument::class); + $this->driver->loadMetadataForClass(EmbeddedDocument::class, $classMetadata); $this->assertEquals([ 'fieldName' => 'name', @@ -258,8 +267,8 @@ public function testDriver() 'strategy' => ClassMetadata::STORAGE_STRATEGY_SET, ], $classMetadata->fieldMappings['name']); - $classMetadata = new ClassMetadata('TestDocuments\QueryResultDocument'); - $this->driver->loadMetadataForClass('TestDocuments\QueryResultDocument', $classMetadata); + $classMetadata = new ClassMetadata(QueryResultDocument::class); + $this->driver->loadMetadataForClass(QueryResultDocument::class, $classMetadata); $this->assertEquals([ 'fieldName' => 'name', @@ -294,8 +303,8 @@ public function testDriver() public function testPartialFilterExpressions() { - $classMetadata = new ClassMetadata('TestDocuments\PartialFilterDocument'); - $this->driver->loadMetadataForClass('TestDocuments\PartialFilterDocument', $classMetadata); + $classMetadata = new ClassMetadata(PartialFilterDocument::class); + $this->driver->loadMetadataForClass(PartialFilterDocument::class, $classMetadata); $this->assertEquals([ [ diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php index d3945fe205..802c26d727 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php @@ -6,6 +6,10 @@ use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver; +use TestDocuments\CustomIdGenerator; +use TestDocuments\InvalidPartialFilterDocument; +use TestDocuments\UserCustomIdGenerator; +use TestDocuments\UserNonStringOptions; class XmlDriverTest extends AbstractDriverTest { @@ -16,13 +20,13 @@ public function setUp() public function testDriverShouldReturnOptionsForCustomIdGenerator() { - $classMetadata = new ClassMetadata('TestDocuments\UserCustomIdGenerator'); - $this->driver->loadMetadataForClass('TestDocuments\UserCustomIdGenerator', $classMetadata); + $classMetadata = new ClassMetadata(UserCustomIdGenerator::class); + $this->driver->loadMetadataForClass(UserCustomIdGenerator::class, $classMetadata); $this->assertEquals([ 'fieldName' => 'id', 'strategy' => 'custom', 'options' => [ - 'class' => 'TestDocuments\CustomIdGenerator', + 'class' => CustomIdGenerator::class, 'someOption' => 'some-option', ], 'id' => true, @@ -41,8 +45,8 @@ public function testDriverShouldReturnOptionsForCustomIdGenerator() public function testDriverShouldParseNonStringAttributes() { - $classMetadata = new ClassMetadata('TestDocuments\UserNonStringOptions'); - $this->driver->loadMetadataForClass('TestDocuments\UserNonStringOptions', $classMetadata); + $classMetadata = new ClassMetadata(UserNonStringOptions::class); + $this->driver->loadMetadataForClass(UserNonStringOptions::class, $classMetadata); $profileMapping = $classMetadata->fieldMappings['profile']; $this->assertSame(ClassMetadata::REFERENCE_STORE_AS_ID, $profileMapping['storeAs']); @@ -57,8 +61,8 @@ public function testDriverShouldParseNonStringAttributes() public function testInvalidPartialFilterExpressions() { - $classMetadata = new ClassMetadata('TestDocuments\InvalidPartialFilterDocument'); - $this->driver->loadMetadataForClass('TestDocuments\InvalidPartialFilterDocument', $classMetadata); + $classMetadata = new ClassMetadata(InvalidPartialFilterDocument::class); + $this->driver->loadMetadataForClass(InvalidPartialFilterDocument::class, $classMetadata); $this->assertEquals([ [ diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php index 31d997d32e..8d685abfbc 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php @@ -45,6 +45,6 @@ public function testGetAssociationCollectionClass() $m->setAccessible(true); $m->invoke($driver, $class, $element, 'many'); - $this->assertEquals('Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\PhonenumberCollection', $class->getAssociationCollectionClass('phonenumbers')); + $this->assertEquals(PhonenumberCollection::class, $class->getAssociationCollectionClass('phonenumbers')); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/MongoCollectionTest.php b/tests/Doctrine/ODM/MongoDB/Tests/MongoCollectionTest.php index d406668a59..c881fe3c41 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/MongoCollectionTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/MongoCollectionTest.php @@ -4,11 +4,13 @@ namespace Doctrine\ODM\MongoDB\Tests; +use Documents\File; + class MongoCollectionTest extends BaseTest { public function testGridFSEmptyResult() { - $mongoCollection = $this->dm->getDocumentCollection('Documents\File'); + $mongoCollection = $this->dm->getDocumentCollection(File::class); $this->assertNull($mongoCollection->findOne(['_id' => 'definitelynotanid'])); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Performance/HydrationPerformanceTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Performance/HydrationPerformanceTest.php index 212dd3cea1..4dedea0571 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Performance/HydrationPerformanceTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Performance/HydrationPerformanceTest.php @@ -42,7 +42,7 @@ public function testHydrationPerformance() echo 'Memory usage before: ' . (memory_get_usage() / 1024) . ' KB' . PHP_EOL; - $this->dm->getRepository('Documents\CmsUser')->findAll(); + $this->dm->getRepository(CmsUser::class)->findAll(); $this->dm->clear(); gc_collect_cycles(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php index 7f6c0d510d..1acc74a4d7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php @@ -71,7 +71,7 @@ public function testGetTypeClassWorksAfterUnserialization() /** @var PersistentCollection $unserialized */ $unserialized = unserialize($serialized); - $unserialized->setOwner(new User(), $this->dm->getClassMetadata('Documents\\User')->getFieldMapping('phonebooks')); + $unserialized->setOwner(new User(), $this->dm->getClassMetadata(User::class)->getFieldMapping('phonebooks')); $unserialized->setDocumentManager($this->dm); $this->assertInstanceOf(ClassMetadata::class, $unserialized->getTypeClass()); } @@ -279,7 +279,7 @@ public function testIsEmptyUsesCountWhenCollectionIsNotInitialized() */ private function getMockDocumentManager() { - return $this->createMock('Doctrine\ODM\MongoDB\DocumentManager'); + return $this->createMock(DocumentManager::class); } /** @@ -287,7 +287,7 @@ private function getMockDocumentManager() */ private function getMockUnitOfWork() { - return $this->createMock('Doctrine\ODM\MongoDB\UnitOfWork'); + return $this->createMock(UnitOfWork::class); } /** @@ -295,6 +295,6 @@ private function getMockUnitOfWork() */ private function getMockCollection() { - return $this->createMock('Doctrine\Common\Collections\Collection'); + return $this->createMock(Collection::class); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Persisters/DocumentPersisterFilterTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Persisters/DocumentPersisterFilterTest.php index ef92e6d797..bb1e5f549e 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Persisters/DocumentPersisterFilterTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Persisters/DocumentPersisterFilterTest.php @@ -7,17 +7,18 @@ use Doctrine\ODM\MongoDB\Tests\BaseTest; use Documents\BlogPost; use Documents\Comment; +use Documents\User; class DocumentPersisterFilterTest extends BaseTest { public function testAddFilterToPreparedQuery() { - $persister = $this->uow->getDocumentPersister('Documents\User'); + $persister = $this->uow->getDocumentPersister(User::class); $filterCollection = $this->dm->getFilterCollection(); $filterCollection->enable('testFilter'); $testFilter = $filterCollection->getFilter('testFilter'); - $testFilter->setParameter('class', 'Documents\User'); + $testFilter->setParameter('class', User::class); $testFilter->setParameter('field', 'username'); $testFilter->setParameter('value', 'Tim'); @@ -47,11 +48,11 @@ public function testFilterCrieriaShouldAndWithMappingCriteriaOwningSide() $filterCollection->enable('testFilter'); $testFilter = $filterCollection->getFilter('testFilter'); - $testFilter->setParameter('class', 'Documents\Comment'); + $testFilter->setParameter('class', Comment::class); $testFilter->setParameter('field', 'isByAdmin'); $testFilter->setParameter('value', false); - $blogPost = $this->dm->getRepository('Documents\BlogPost')->find($blogPost->id); + $blogPost = $this->dm->getRepository(BlogPost::class)->find($blogPost->id); // Admin comments should be removed by the filter $this->assertCount(1, $blogPost->comments); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php index c0f253bc68..c4c72cff07 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php @@ -47,7 +47,7 @@ public function testQueryBuilderUpdateWithDiscriminatorMap() /** * @var Builder $qb */ - $qb = $this->dm->createQueryBuilder('Documents\Functional\SameCollection1'); + $qb = $this->dm->createQueryBuilder(SameCollection1::class); $qb->updateOne() ->field('ok')->set(true) ->field('test')->set('OK! TEST') @@ -271,7 +271,7 @@ public function testAdvancedQueriesOnReferenceWithDiscriminatorMap() /** * @var Builder $qb */ - $qb = $this->dm->createQueryBuilder('Documents\CmsComment'); + $qb = $this->dm->createQueryBuilder(CmsComment::class); $qb ->field('article.id')->in([$articleId]); $query = $qb->getQuery(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php index 936156b186..3c2017b47c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php @@ -24,7 +24,7 @@ class BuilderTest extends BaseTest */ public function testPrimeRequiresBooleanOrCallable() { - $this->dm->createQueryBuilder('Documents\User') + $this->dm->createQueryBuilder(User::class) ->field('groups')->prime(1); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php index 833e947575..a07ab5f3ea 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php @@ -11,13 +11,15 @@ use Doctrine\ODM\MongoDB\Tests\BaseTest; use Doctrine\ODM\MongoDB\UnitOfWork; use Documents\User; +use GeoJson\Geometry\Point; +use GeoJson\Geometry\Polygon; use MongoDB\BSON\ObjectId; class ExprTest extends BaseTest { public function testSelectIsPrepared() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->select('id'); $query = $qb->getQuery(); @@ -28,7 +30,7 @@ public function testInIsPrepared() { $ids = ['4f28aa84acee41388900000a']; - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('groups.id')->in($ids) ->select('id')->hydrate(false); $query = $qb->getQuery(); @@ -42,7 +44,7 @@ public function testAllIsPrepared() { $ids = ['4f28aa84acee41388900000a']; - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('groups.id')->all($ids) ->select('id')->hydrate(false); $query = $qb->getQuery(); @@ -56,7 +58,7 @@ public function testNotEqualIsPrepared() { $id = '4f28aa84acee41388900000a'; - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('groups.id')->notEqual($id) ->select('id')->hydrate(false); $query = $qb->getQuery(); @@ -70,7 +72,7 @@ public function testNotInIsPrepared() { $ids = ['4f28aa84acee41388900000a']; - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('groups.id')->notIn($ids) ->select('id')->hydrate(false); $query = $qb->getQuery(); @@ -84,7 +86,7 @@ public function testAndIsPrepared() { $ids = ['4f28aa84acee41388900000a']; - $qb = $this->dm->createQueryBuilder('Documents\User'); + $qb = $this->dm->createQueryBuilder(User::class); $qb ->addAnd($qb->expr()->field('groups.id')->in($ids)) ->select('id')->hydrate(false); @@ -99,7 +101,7 @@ public function testOrIsPrepared() { $ids = ['4f28aa84acee41388900000a']; - $qb = $this->dm->createQueryBuilder('Documents\User'); + $qb = $this->dm->createQueryBuilder(User::class); $qb ->addOr($qb->expr()->field('groups.id')->in($ids)) ->select('id')->hydrate(false); @@ -117,7 +119,7 @@ public function testMultipleQueryOperatorsArePrepared() $ne = '4f28aa84acee41388900000c'; $nin = ['4f28aa84acee41388900000d']; - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('groups.id')->all($all) ->field('groups.id')->in($in) ->field('groups.id')->notEqual($ne) @@ -138,7 +140,7 @@ public function testMultipleQueryOperatorsArePrepared() public function testPrepareNestedDocuments() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('address.subAddress.subAddress.subAddress.test')->equals('test'); $query = $qb->getQuery(); $debug = $query->debug('query'); @@ -147,7 +149,7 @@ public function testPrepareNestedDocuments() public function testPreparePositionalOperator() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->updateOne() ->field('phonenumbers.$.phonenumber')->equals('foo') ->field('phonenumbers.$')->set(['phonenumber' => 'bar']); @@ -158,13 +160,13 @@ public function testPreparePositionalOperator() public function testSortIsPrepared() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->sort('id', 'desc'); $query = $qb->getQuery(); $query = $query->getQuery(); $this->assertEquals(['_id' => -1], $query['sort']); - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->sort('address.subAddress.subAddress.subAddress.test', 'asc'); $query = $qb->getQuery(); $query = $query->getQuery(); @@ -173,7 +175,7 @@ public function testSortIsPrepared() public function testNestedWithOperator() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('address.subAddress.subAddress.subAddress.test')->notIn(['test']); $query = $qb->getQuery(); $query = $query->getQuery(); @@ -182,7 +184,7 @@ public function testNestedWithOperator() public function testNewObjectIsPrepared() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->updateOne() ->field('address.subAddress.subAddress.subAddress.test')->popFirst(); $query = $qb->getQuery(); @@ -788,7 +790,7 @@ private function createExpr(?DocumentManager $dm = null, ?ClassMetadata $class = private function getMockPoint($json) { - $point = $this->getMockBuilder('GeoJson\Geometry\Point') + $point = $this->getMockBuilder(Point::class) ->disableOriginalConstructor() ->getMock(); @@ -801,7 +803,7 @@ private function getMockPoint($json) private function getMockPolygon($json) { - $point = $this->getMockBuilder('GeoJson\Geometry\Polygon') + $point = $this->getMockBuilder(Polygon::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Query/FilterCollectionTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Query/FilterCollectionTest.php index 7718193dad..319aed26dc 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Query/FilterCollectionTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Query/FilterCollectionTest.php @@ -4,7 +4,9 @@ namespace Doctrine\ODM\MongoDB\Tests\Query; +use Doctrine\ODM\MongoDB\Query\Filter\BsonFilter; use Doctrine\ODM\MongoDB\Tests\BaseTest; +use Documents\User; class FilterCollectionTest extends BaseTest { @@ -18,7 +20,7 @@ public function testEnable() $enabledFilters = $filterCollection->getEnabledFilters(); $this->assertCount(1, $enabledFilters); - $this->assertContainsOnly('Doctrine\ODM\MongoDB\Query\Filter\BsonFilter', $enabledFilters); + $this->assertContainsOnly(BsonFilter::class, $enabledFilters); $filterCollection->disable('testFilter'); $this->assertCount(0, $filterCollection->getEnabledFilters()); @@ -59,19 +61,19 @@ public function testGetFilter() { $filterCollection = $this->dm->getFilterCollection(); $filterCollection->enable('testFilter'); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter', $filterCollection->getFilter('testFilter')); + $this->assertInstanceOf(Filter\Filter::class, $filterCollection->getFilter('testFilter')); } public function testGetFilterCriteria() { - $class = $this->dm->getClassMetadata('Documents\User'); + $class = $this->dm->getClassMetadata(User::class); $filterCollection = $this->dm->getFilterCollection(); $this->assertEmpty($filterCollection->getFilterCriteria($class)); $filterCollection->enable('testFilter'); $testFilter = $filterCollection->getFilter('testFilter'); - $testFilter->setParameter('class', 'Documents\User'); + $testFilter->setParameter('class', User::class); $testFilter->setParameter('field', 'username'); $testFilter->setParameter('value', 'Tim'); @@ -80,18 +82,18 @@ public function testGetFilterCriteria() public function testGetFilterCriteriaMergesCriteria() { - $class = $this->dm->getClassMetadata('Documents\User'); + $class = $this->dm->getClassMetadata(User::class); $filterCollection = $this->dm->getFilterCollection(); $filterCollection->enable('testFilter'); $testFilter = $filterCollection->getFilter('testFilter'); - $testFilter->setParameter('class', 'Documents\User'); + $testFilter->setParameter('class', User::class); $testFilter->setParameter('field', 'username'); $testFilter->setParameter('value', 'Tim'); $filterCollection->enable('testFilter2'); $testFilter = $filterCollection->getFilter('testFilter2'); - $testFilter->setParameter('class', 'Documents\User'); + $testFilter->setParameter('class', User::class); $testFilter->setParameter('field', 'username'); $testFilter->setParameter('value', 'John'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Query/QueryExpressionVisitorTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Query/QueryExpressionVisitorTest.php index 2765db3e31..ed231d3477 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Query/QueryExpressionVisitorTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Query/QueryExpressionVisitorTest.php @@ -8,8 +8,10 @@ use Doctrine\Common\Collections\Expr\CompositeExpression; use Doctrine\Common\Collections\Expr\Value; use Doctrine\Common\Collections\ExpressionBuilder; +use Doctrine\ODM\MongoDB\Query\Expr; use Doctrine\ODM\MongoDB\Query\QueryExpressionVisitor; use Doctrine\ODM\MongoDB\Tests\BaseTest; +use Documents\Bars\Bar; use MongoDB\BSON\Regex; class QueryExpressionVisitorTest extends BaseTest @@ -20,7 +22,7 @@ class QueryExpressionVisitorTest extends BaseTest public function setUp() { parent::setUp(); - $this->queryBuilder = $this->dm->createQueryBuilder('Documents\Bars\Bar'); + $this->queryBuilder = $this->dm->createQueryBuilder(Bar::class); $this->visitor = new QueryExpressionVisitor($this->queryBuilder); } @@ -31,7 +33,7 @@ public function testWalkComparison(Comparison $comparison, array $expectedQuery) { $expr = $this->visitor->dispatch($comparison); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Query\Expr', $expr); + $this->assertInstanceOf(Expr::class, $expr); $this->assertEquals($expectedQuery, $expr->getQuery()); } @@ -82,7 +84,7 @@ public function testWalkCompositeExpression() $expr = $this->visitor->dispatch($compositeExpr); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Query\Expr', $expr); + $this->assertInstanceOf(Expr::class, $expr); $this->assertEquals($expectedQuery, $expr->getQuery()); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php index d602b436a1..49731452da 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php @@ -8,6 +8,8 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Query\Query; +use Documents\Phonenumber; +use Documents\Project; use Documents\SubProject; use Documents\User; use MongoDB\BSON\ObjectId; @@ -20,7 +22,7 @@ class QueryTest extends BaseTest { public function testSelectAndSelectSliceOnSameField() { - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\Person') + $qb = $this->dm->createQueryBuilder(Person::class) ->exclude('comments') ->select('comments') ->selectSlice('comments', 0, 10); @@ -41,7 +43,7 @@ public function testThatOrAcceptsAnotherQuery() $this->dm->persist($chris); $this->dm->flush(); - $class = __NAMESPACE__ . '\Person'; + $class = Person::class; $expression1 = ['firstName' => 'Kris']; $expression2 = ['firstName' => 'Chris']; @@ -75,7 +77,7 @@ public function testReferences() $kris->bestFriend = $jon; $this->dm->flush(); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\Person'); + $qb = $this->dm->createQueryBuilder(Person::class); $qb->field('bestFriend')->references($jon); $queryArray = $qb->getQueryArray(); @@ -103,7 +105,7 @@ public function testReferencesStoreAsId() $kris->bestFriendSimple = $jon; $this->dm->flush(); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\Person'); + $qb = $this->dm->createQueryBuilder(Person::class); $qb->field('bestFriendSimple')->references($jon); $queryArray = $qb->getQueryArray(); @@ -129,7 +131,7 @@ public function testReferencesStoreAsDbRef() $kris->bestFriendPartial = $jon; $this->dm->flush(); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\Person'); + $qb = $this->dm->createQueryBuilder(Person::class); $qb->field('bestFriendPartial')->references($jon); $queryArray = $qb->getQueryArray(); @@ -156,7 +158,7 @@ public function testIncludesReferenceToWithStoreAsDbRefWithDb() $jon->friends[] = $kris; $this->dm->flush(); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\Person'); + $qb = $this->dm->createQueryBuilder(Person::class); $qb->field('friends')->includesReferenceTo($kris); $queryArray = $qb->getQueryArray(); @@ -191,7 +193,7 @@ public function testIncludesReferenceToWithStoreAsId() $jon->friendsSimple[] = $jachim; $this->dm->flush(); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\Person'); + $qb = $this->dm->createQueryBuilder(Person::class); $qb->field('friendsSimple')->includesReferenceTo($kris); $queryArray = $qb->getQueryArray(); @@ -217,7 +219,7 @@ public function testIncludesReferenceToWithStoreAsDbRef() $jon->friendsPartial[] = $kris; $this->dm->flush(); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\Person'); + $qb = $this->dm->createQueryBuilder(Person::class); $qb->field('friendsPartial')->includesReferenceTo($kris); $queryArray = $qb->getQueryArray(); @@ -246,7 +248,7 @@ public function testQueryIdIn() $identifier = new ObjectId($user->getId()); $ids = [$identifier]; - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->field('_id')->in($ids); $query = $qb->getQuery(); $results = $query->toArray(); @@ -255,7 +257,7 @@ public function testQueryIdIn() public function testEmbeddedSet() { - $qb = $this->dm->createQueryBuilder('Documents\User') + $qb = $this->dm->createQueryBuilder(User::class) ->insert() ->field('testInt')->set('0') ->field('intfields.intone')->set('1') @@ -267,8 +269,8 @@ public function testElemMatch() { $refId = '000000000000000000000001'; - $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($refId)); @@ -280,7 +282,7 @@ public function testElemMatch() public function testQueryWithMultipleEmbeddedDocuments() { - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\EmbedTest') + $qb = $this->dm->createQueryBuilder(EmbedTest::class) ->find() ->field('embeddedOne.embeddedOne.embeddedMany.embeddedOne.name')->equals('Foo'); $query = $qb->getQuery(); @@ -291,7 +293,7 @@ public function testQueryWithMultipleEmbeddedDocumentsAndReference() { $identifier = new ObjectId(); - $qb = $this->dm->createQueryBuilder(__NAMESPACE__ . '\EmbedTest') + $qb = $this->dm->createQueryBuilder(EmbedTest::class) ->find() ->field('embeddedOne.embeddedOne.embeddedMany.embeddedOne.pet.owner.id')->equals((string) $identifier); $query = $qb->getQuery(); @@ -309,12 +311,12 @@ public function testSelectVsSingleCollectionInheritance() $this->dm->clear(); $test = $this->dm->createQueryBuilder() - ->find('Documents\Project') + ->find(Project::class) ->select(['name']) ->field('id')->equals($p->getId()) ->getQuery()->getSingleResult(); $this->assertNotNull($test); - $this->assertInstanceOf('Documents\SubProject', $test); + $this->assertInstanceOf(SubProject::class, $test); $this->assertEquals('SubProject', $test->getName()); } @@ -326,12 +328,12 @@ public function testEmptySelectVsSingleCollectionInheritance() $this->dm->clear(); $test = $this->dm->createQueryBuilder() - ->find('Documents\Project') + ->find(Project::class) ->select([]) ->field('id')->equals($p->getId()) ->getQuery()->getSingleResult(); $this->assertNotNull($test); - $this->assertInstanceOf('Documents\SubProject', $test); + $this->assertInstanceOf(SubProject::class, $test); $this->assertEquals('SubProject', $test->getName()); } @@ -343,7 +345,7 @@ public function testDiscriminatorFieldNotAddedWithoutHydration() $this->dm->clear(); $test = $this->dm->createQueryBuilder() - ->find('Documents\Project')->hydrate(false) + ->find(Project::class)->hydrate(false) ->select(['name']) ->field('id')->equals($p->getId()) ->getQuery()->getSingleResult(); @@ -359,12 +361,12 @@ public function testExcludeVsSingleCollectionInheritance() $this->dm->clear(); $test = $this->dm->createQueryBuilder() - ->find('Documents\SubProject') + ->find(SubProject::class) ->exclude(['name', 'issues']) ->field('id')->equals($p->getId()) ->getQuery()->getSingleResult(); $this->assertNotNull($test); - $this->assertInstanceOf('Documents\SubProject', $test); + $this->assertInstanceOf(SubProject::class, $test); $this->assertNull($test->getName()); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php index ac374219a5..14dcc789b3 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php @@ -4,11 +4,14 @@ namespace Doctrine\ODM\MongoDB\Tests; +use Doctrine\Common\EventManager; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory; use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; +use Doctrine\ODM\MongoDB\Persisters\DocumentPersister; use Doctrine\ODM\MongoDB\SchemaManager; use Doctrine\ODM\MongoDB\Tests\Mocks\DocumentManagerMock; +use Doctrine\ODM\MongoDB\UnitOfWork; use Documents\CmsAddress; use Documents\CmsArticle; use Documents\CmsComment; @@ -632,7 +635,7 @@ private function getMockDocumentManager() $config = new Configuration(); $config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/../../../../Documents')); - $em = $this->createMock('Doctrine\Common\EventManager'); + $em = $this->createMock(EventManager::class); $dm = new DocumentManagerMock(); $dm->eventManager = $em; @@ -643,13 +646,13 @@ private function getMockDocumentManager() private function getMockUnitOfWork() { - $documentPersister = $this->createMock('Doctrine\ODM\MongoDB\Persisters\DocumentPersister'); + $documentPersister = $this->createMock(DocumentPersister::class); $documentPersister->expects($this->any()) ->method('prepareFieldName') ->will($this->returnArgument(0)); - $uow = $this->createMock('Doctrine\ODM\MongoDB\UnitOfWork'); + $uow = $this->createMock(UnitOfWork::class); $uow->expects($this->any()) ->method('getDocumentPersister') diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Tools/ResolveTargetDocumentListenerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Tools/ResolveTargetDocumentListenerTest.php index 1b96e2e23b..039c10f3e7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Tools/ResolveTargetDocumentListenerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Tools/ResolveTargetDocumentListenerTest.php @@ -30,26 +30,26 @@ public function testResolveTargetDocumentListenerCanResolveTargetDocument() $evm = $this->dm->getEventManager(); $this->listener->addResolveTargetDocument( - 'Doctrine\ODM\MongoDB\Tests\Tools\ResolveTargetInterface', - 'Doctrine\ODM\MongoDB\Tests\Tools\ResolveTargetDocument', + ResolveTargetInterface::class, + ResolveTargetDocument::class, [] ); $this->listener->addResolveTargetDocument( - 'Doctrine\ODM\MongoDB\Tests\Tools\TargetInterface', - 'Doctrine\ODM\MongoDB\Tests\Tools\TargetDocument', + TargetInterface::class, + TargetDocument::class, [] ); $evm->addEventListener(Events::loadClassMetadata, $this->listener); - $cm = $this->dm->getClassMetadata('Doctrine\ODM\MongoDB\Tests\Tools\ResolveTargetDocument'); + $cm = $this->dm->getClassMetadata(ResolveTargetDocument::class); $meta = $cm->associationMappings; - $this->assertSame('Doctrine\ODM\MongoDB\Tests\Tools\ResolveTargetDocument', $meta['refOne']['targetDocument']); - $this->assertSame('Doctrine\ODM\MongoDB\Tests\Tools\TargetDocument', $meta['refMany']['targetDocument']); - $this->assertSame('Doctrine\ODM\MongoDB\Tests\Tools\ResolveTargetDocument', $meta['embedOne']['targetDocument']); - $this->assertSame('Doctrine\ODM\MongoDB\Tests\Tools\TargetDocument', $meta['embedMany']['targetDocument']); + $this->assertSame(ResolveTargetDocument::class, $meta['refOne']['targetDocument']); + $this->assertSame(TargetDocument::class, $meta['refMany']['targetDocument']); + $this->assertSame(ResolveTargetDocument::class, $meta['embedOne']['targetDocument']); + $this->assertSame(TargetDocument::class, $meta['embedMany']['targetDocument']); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php index 53e738a536..06be753110 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php @@ -13,6 +13,7 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Persisters\PersistenceBuilder; +use Doctrine\ODM\MongoDB\Proxy\Proxy; use Doctrine\ODM\MongoDB\Tests\Mocks\DocumentPersisterMock; use Doctrine\ODM\MongoDB\Tests\Mocks\ExceptionThrowingListenerMock; use Doctrine\ODM\MongoDB\Tests\Mocks\PreUpdateListenerMock; @@ -32,7 +33,7 @@ class UnitOfWorkTest extends BaseTest { public function testIsDocumentScheduled() { - $class = $this->dm->getClassMetadata('Documents\ForumUser'); + $class = $this->dm->getClassMetadata(ForumUser::class); $user = new ForumUser(); $this->assertFalse($this->uow->isDocumentScheduled($user)); $this->uow->scheduleForInsert($class, $user); @@ -41,7 +42,7 @@ public function testIsDocumentScheduled() public function testScheduleForInsert() { - $class = $this->dm->getClassMetadata('Documents\ForumUser'); + $class = $this->dm->getClassMetadata(ForumUser::class); $user = new ForumUser(); $this->assertFalse($this->uow->isScheduledForInsert($user)); $this->uow->scheduleForInsert($class, $user); @@ -50,7 +51,7 @@ public function testScheduleForInsert() public function testScheduleForUpsert() { - $class = $this->dm->getClassMetadata('Documents\ForumUser'); + $class = $this->dm->getClassMetadata(ForumUser::class); $user = new ForumUser(); $user->id = new ObjectId(); $this->assertFalse($this->uow->isScheduledForInsert($user)); @@ -62,7 +63,7 @@ public function testScheduleForUpsert() public function testGetScheduledDocumentUpserts() { - $class = $this->dm->getClassMetadata('Documents\ForumUser'); + $class = $this->dm->getClassMetadata(ForumUser::class); $user = new ForumUser(); $user->id = new ObjectId(); $this->assertEmpty($this->uow->getScheduledDocumentUpserts()); @@ -72,7 +73,7 @@ public function testGetScheduledDocumentUpserts() public function testScheduleForEmbeddedUpsert() { - $class = $this->dm->getClassMetadata('Documents\ForumUser'); + $class = $this->dm->getClassMetadata(ForumUser::class); $test = new EmbeddedUpsertDocument(); $test->id = (string) new ObjectId(); $this->assertFalse($this->uow->isScheduledForInsert($test)); @@ -96,7 +97,7 @@ public function testScheduleForUpsertWithNonObjectIdValues() public function testScheduleForInsertShouldNotUpsertDocumentsWithInconsistentIdValues() { - $class = $this->dm->getClassMetadata('Documents\ForumUser'); + $class = $this->dm->getClassMetadata(ForumUser::class); $user = new ForumUser(); $user->id = 1; $this->assertFalse($this->uow->isScheduledForInsert($user)); @@ -119,9 +120,9 @@ public function testSavingSingleDocumentWithIdentityFieldForcesInsert() { // Setup fake persister and id generator for identity generation $pb = $this->getMockPersistenceBuilder(); - $class = $this->dm->getClassMetadata('Documents\ForumUser'); + $class = $this->dm->getClassMetadata(ForumUser::class); $userPersister = $this->getMockDocumentPersister($pb, $class); - $this->uow->setDocumentPersister('Documents\ForumUser', $userPersister); + $this->uow->setDocumentPersister(ForumUser::class, $userPersister); // Test $user = new ForumUser(); @@ -160,15 +161,15 @@ public function testCascadedIdentityColumnInsert() // Setup fake persister and id generator for identity generation //ForumUser $pb = $this->getMockPersistenceBuilder(); - $class = $this->dm->getClassMetadata('Documents\ForumUser'); + $class = $this->dm->getClassMetadata(ForumUser::class); $userPersister = $this->getMockDocumentPersister($pb, $class); - $this->uow->setDocumentPersister('Documents\ForumUser', $userPersister); + $this->uow->setDocumentPersister(ForumUser::class, $userPersister); // ForumAvatar $pb = $this->getMockPersistenceBuilder(); - $class = $this->dm->getClassMetadata('Documents\ForumAvatar'); + $class = $this->dm->getClassMetadata(ForumAvatar::class); $avatarPersister = $this->getMockDocumentPersister($pb, $class); - $this->uow->setDocumentPersister('Documents\ForumAvatar', $avatarPersister); + $this->uow->setDocumentPersister(ForumAvatar::class, $avatarPersister); // Test $user = new ForumUser(); @@ -195,11 +196,11 @@ public function testChangeTrackingNotify() { $pb = $this->getMockPersistenceBuilder(); - $class = $this->dm->getClassMetadata('Doctrine\ODM\MongoDB\Tests\NotifyChangedDocument'); + $class = $this->dm->getClassMetadata(NotifyChangedDocument::class); $persister = $this->getMockDocumentPersister($pb, $class); $this->uow->setDocumentPersister($class->name, $persister); - $class = $this->dm->getClassMetadata('Doctrine\ODM\MongoDB\Tests\NotifyChangedRelatedItem'); + $class = $this->dm->getClassMetadata(NotifyChangedRelatedItem::class); $itemPersister = $this->getMockDocumentPersister($pb, $class); $this->uow->setDocumentPersister($class->name, $itemPersister); @@ -253,9 +254,9 @@ public function testChangeTrackingNotify() public function testGetDocumentStateWithAssignedIdentity() { $pb = $this->getMockPersistenceBuilder(); - $class = $this->dm->getClassMetadata('Documents\CmsPhonenumber'); + $class = $this->dm->getClassMetadata(CmsPhonenumber::class); $persister = $this->getMockDocumentPersister($pb, $class); - $this->uow->setDocumentPersister('Documents\CmsPhonenumber', $persister); + $this->uow->setDocumentPersister(CmsPhonenumber::class, $persister); $ph = new CmsPhonenumber(); $ph->phonenumber = '12345'; @@ -281,7 +282,7 @@ public function testGetDocumentStateWithAssignedIdentity() public function testThrowsOnPersistOfMappedSuperclass() { $documentManager = $this->getDocumentManager(); - $documentManager->setClassMetadata('Documents\Address', $this->getClassMetadata('Documents\Address', 'MappedSuperclass')); + $documentManager->setClassMetadata(Address::class, $this->getClassMetadata(Address::class, 'MappedSuperclass')); $unitOfWork = $this->getUnitOfWork($documentManager); $unitOfWork->persist(new Address()); } @@ -339,9 +340,9 @@ public function testNotSaved() public function testScheduleForUpdateWithArrays($origData, $updateData, $shouldInUpdate) { $pb = $this->getMockPersistenceBuilder(); - $class = $this->dm->getClassMetadata('Doctrine\ODM\MongoDB\Tests\ArrayTest'); + $class = $this->dm->getClassMetadata(ArrayTest::class); $persister = $this->getMockDocumentPersister($pb, $class); - $this->uow->setDocumentPersister('Doctrine\ODM\MongoDB\Tests\ArrayTest', $persister); + $this->uow->setDocumentPersister(ArrayTest::class, $persister); $arrayTest = new ArrayTest($origData); $this->uow->persist($arrayTest); @@ -553,12 +554,12 @@ public function testGetClassNameForAssociation() { $mapping = [ 'discriminatorField' => 'type', - 'discriminatorMap' => ['forum_user' => 'Documents\ForumUser'], - 'targetDocument' => 'Documents\User', + 'discriminatorMap' => ['forum_user' => ForumUser::class], + 'targetDocument' => User::class, ]; $data = ['type' => 'forum_user']; - $this->assertEquals('Documents\ForumUser', $this->uow->getClassNameForAssociation($mapping, $data)); + $this->assertEquals(ForumUser::class, $this->uow->getClassNameForAssociation($mapping, $data)); } public function testGetClassNameForAssociationWithClassMetadataDiscriminatorMap() @@ -566,25 +567,25 @@ public function testGetClassNameForAssociationWithClassMetadataDiscriminatorMap( $dm = $this->getMockDocumentManager(); $uow = new UnitOfWork($dm, $this->getMockEventManager(), $this->getMockHydratorFactory()); - $mapping = ['targetDocument' => 'Documents\User']; + $mapping = ['targetDocument' => User::class]; $data = ['type' => 'forum_user']; - $userClassMetadata = new ClassMetadata('Documents\ForumUser'); + $userClassMetadata = new ClassMetadata(ForumUser::class); $userClassMetadata->discriminatorField = 'type'; - $userClassMetadata->discriminatorMap = ['forum_user' => 'Documents\ForumUser']; + $userClassMetadata->discriminatorMap = ['forum_user' => ForumUser::class]; $dm->expects($this->once()) ->method('getClassMetadata') - ->with('Documents\User') + ->with(User::class) ->will($this->returnValue($userClassMetadata)); - $this->assertEquals('Documents\ForumUser', $uow->getClassNameForAssociation($mapping, $data)); + $this->assertEquals(ForumUser::class, $uow->getClassNameForAssociation($mapping, $data)); } public function testGetClassNameForAssociationReturnsTargetDocumentWithNullData() { - $mapping = ['targetDocument' => 'Documents\User']; - $this->assertEquals('Documents\User', $this->uow->getClassNameForAssociation($mapping, null)); + $mapping = ['targetDocument' => User::class]; + $this->assertEquals(User::class, $this->uow->getClassNameForAssociation($mapping, null)); } public function testRecomputeChangesetForUninitializedProxyDoesNotCreateChangeset() @@ -599,12 +600,12 @@ public function testRecomputeChangesetForUninitializedProxyDoesNotCreateChangese $id = $user->getId(); $this->dm->clear(); - $user = $this->dm->find('\Documents\ForumUser', $id); - $this->assertInstanceOf('\Documents\ForumUser', $user); + $user = $this->dm->find(ForumUser::class, $id); + $this->assertInstanceOf(ForumUser::class, $user); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user->getAvatar()); + $this->assertInstanceOf(Proxy::class, $user->getAvatar()); - $classMetadata = $this->dm->getClassMetadata('Documents\ForumAvatar'); + $classMetadata = $this->dm->getClassMetadata(ForumAvatar::class); $this->uow->recomputeSingleDocumentChangeSet($classMetadata, $user->getAvatar()); @@ -646,7 +647,7 @@ protected function getUnitOfWork(DocumentManager $dm) */ private function getMockHydratorFactory() { - return $this->createMock('Doctrine\ODM\MongoDB\Hydrator\HydratorFactory'); + return $this->createMock(HydratorFactory::class); } /** @@ -656,17 +657,17 @@ private function getMockHydratorFactory() */ private function getMockEventManager() { - return $this->createMock('Doctrine\Common\EventManager'); + return $this->createMock(EventManager::class); } private function getMockPersistenceBuilder() { - return $this->createMock('Doctrine\ODM\MongoDB\Persisters\PersistenceBuilder'); + return $this->createMock(PersistenceBuilder::class); } private function getMockDocumentManager() { - return $this->createMock('Doctrine\ODM\MongoDB\DocumentManager'); + return $this->createMock(DocumentManager::class); } private function getMockDocumentPersister(PersistenceBuilder $pb, ClassMetadata $class)