Created
June 5, 2014 15:28
-
-
Save jmikola/dd6f3044475c9f08e309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Doctrine\ODM\MongoDB\Tests; | |
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | |
class GH895Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest | |
{ | |
public function testQueryWithSelectShouldRefreshDocument() | |
{ | |
$document = new GH895Document(); | |
$document->a = "a"; | |
$document->b = "b"; | |
$document->c = "c"; | |
$document->d = "d"; | |
$this->dm->persist($document); | |
$this->dm->flush(); | |
$this->dm->clear(); | |
$result = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH895Document') | |
->select('a', 'b', 'c') | |
->field('a')->equals('a') | |
->getQuery() | |
->getSingleResult(); | |
$this->assertEquals($document->a, $result->a); | |
$this->assertEquals($document->b, $result->b); | |
$this->assertEquals($document->c, $result->c); | |
$this->assertNull($result->d); | |
$result = $this->dm->createQueryBuilder(__NAMESPACE__ . '\GH895Document') | |
->select('b', 'c', 'd') | |
->field('d')->equals('d') | |
->getQuery() | |
->getSingleResult(); | |
/* Although "a" was not included in the query, it was previously set on | |
* the managed document. The refresh UnitOfWork hint used by Query and | |
* Cursor is not the same as UnitOfWork::refresh(), which reloads a | |
* document from the database. The refresh hint merely instructs | |
* UnitOfWork to hydrate any data present in the query result and other | |
* fields will remain as-is. | |
*/ | |
$this->assertEquals($document->a, $result->a); | |
$this->assertEquals($document->b, $result->b); | |
$this->assertEquals($document->c, $result->c); | |
$this->assertEquals($document->d, $result->d); | |
} | |
} | |
/** | |
* @ODM\Document | |
*/ | |
class GH895Document | |
{ | |
/** @ODM\Id(strategy="auto") */ | |
private $id; | |
/** @ODM\String */ | |
public $a; | |
/** @ODM\String */ | |
public $b; | |
/** @ODM\String */ | |
public $c; | |
/** @ODM\String */ | |
public $d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment