Skip to content

Commit

Permalink
fixup! Merge pull request doctrine#1767 from alcaeus/fix-upsert-nulla…
Browse files Browse the repository at this point in the history
…ble-fields-2.0
  • Loading branch information
malarzm committed Apr 4, 2018
1 parent b975101 commit a5f846f
Show file tree
Hide file tree
Showing 24 changed files with 253 additions and 246 deletions.
12 changes: 6 additions & 6 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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());
Expand All @@ -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'));
}
}
6 changes: 3 additions & 3 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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'));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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()
Expand All @@ -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();
Expand Down
30 changes: 15 additions & 15 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testSetEmbeddedToNull()
$this->dm->clear();
$userId = $user->getId();

$user = $this->dm->getRepository('Documents\User')->find($userId);
$user = $this->dm->getRepository(User::class)->find($userId);
$this->assertEquals($userId, $user->getId());
$this->assertNull($user->getAddress());
}
Expand All @@ -49,8 +49,8 @@ public function testFlushEmbedded()
$this->dm->flush();
$this->dm->clear();

$test = $this->dm->getRepository('Documents\Functional\EmbeddedTestLevel0')->findOneBy(['name' => 'test']);
$this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test);
$test = $this->dm->getRepository(EmbeddedTestLevel0::class)->findOneBy(['name' => 'test']);
$this->assertInstanceOf(EmbeddedTestLevel0::class, $test);

// Adding this flush here makes level1 not to be inserted.
$this->dm->flush();
Expand All @@ -62,9 +62,9 @@ public function testFlushEmbedded()
$this->dm->flush();
$this->dm->clear();

$test = $this->dm->find('Documents\Functional\EmbeddedTestLevel0', $test->id);
$this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test);
$this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel1', $test->level1[0]);
$test = $this->dm->find(EmbeddedTestLevel0::class, $test->id);
$this->assertInstanceOf(EmbeddedTestLevel0::class, $test);
$this->assertInstanceOf(EmbeddedTestLevel1::class, $test->level1[0]);

$test->level1[0]->name = 'changed';
$level1 = new EmbeddedTestLevel1();
Expand All @@ -73,7 +73,7 @@ public function testFlushEmbedded()
$this->dm->flush();
$this->dm->clear();

$test = $this->dm->find('Documents\Functional\EmbeddedTestLevel0', $test->id);
$test = $this->dm->find(EmbeddedTestLevel0::class, $test->id);
$this->assertCount(2, $test->level1);
$this->assertEquals('changed', $test->level1[0]->name);
$this->assertEquals('testing', $test->level1[1]->name);
Expand Down Expand Up @@ -106,7 +106,7 @@ public function testOneEmbedded()
$this->dm->flush();
$this->dm->clear();

$user = $this->dm->createQueryBuilder('Documents\User')
$user = $this->dm->createQueryBuilder(User::class)
->field('id')->equals($user->getId())
->getQuery()
->getSingleResult();
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testRemoveOneEmbedded()
$this->dm->flush();
$this->dm->clear();

$user = $this->dm->createQueryBuilder('Documents\User')
$user = $this->dm->createQueryBuilder(User::class)
->field('id')->equals($user->getId())
->getQuery()
->getSingleResult();
Expand All @@ -160,7 +160,7 @@ public function testManyEmbedded()
$this->dm->flush();
$this->dm->clear();

$user2 = $this->dm->createQueryBuilder('Documents\User')
$user2 = $this->dm->createQueryBuilder(User::class)
->field('id')->equals($user->getId())
->getQuery()
->getSingleResult();
Expand Down Expand Up @@ -382,15 +382,15 @@ 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');

$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());
}

Expand All @@ -414,7 +414,7 @@ public function testRemoveEmbeddedDocument()

$this->dm->flush();

$check = $this->dm->getDocumentCollection('Documents\User')->findOne();
$check = $this->dm->getDocumentCollection(User::class)->findOne();
$this->assertEmpty($check['phonenumbers']);
$this->assertArrayNotHasKey('address', $check);
}
Expand Down Expand Up @@ -446,7 +446,7 @@ public function testRemoveAddDeepEmbedded()
$this->dm->flush();
$this->dm->clear();

$vhost = $this->dm->find('Documents\Functional\VirtualHost', $vhost->getId());
$vhost = $this->dm->find(VirtualHost::class, $vhost->getId());

foreach ($vhost->getVHostDirective()->getDirectives() as $directive) {
$this->assertNotEmpty($directive->getName());
Expand All @@ -464,7 +464,7 @@ public function testEmbeddedDocumentNotSavedFields()
$this->dm->flush();
$this->dm->clear();

$document = $this->dm->find('Documents\Functional\NotSaved', $document->id);
$document = $this->dm->find(NotSaved::class, $document->id);

$this->assertEquals('foo', $document->embedded->name);
$this->assertNull($document->embedded->notSaved);
Expand Down
28 changes: 14 additions & 14 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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');
}
Expand All @@ -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');
}
Expand All @@ -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']);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 = [];

Expand Down Expand Up @@ -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();

Expand All @@ -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');

Expand Down
Loading

0 comments on commit a5f846f

Please sign in to comment.