Permalink
Browse files

Test ClassMetadataInfo slaveOkay wrt DocumentManager getter (#759)

  • Loading branch information...
jmikola committed Jan 21, 2014
1 parent 5ae8df6 commit 09730b7a4c88748daf3e687cb72fbe12ddfc08d3
@@ -2,6 +2,9 @@
namespace Doctrine\ODM\MongoDB\Tests;
+use Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo;
+use Doctrine\ODM\MongoDB\Tests\Mocks\DocumentManagerMock;
+
/**
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
*/
@@ -120,4 +123,69 @@ public function testAffectedByErrorIfClosedException($methodName)
$this->dm->$methodName(new \stdClass());
}
}
+
+ public function testGetDocumentCollectionAppliesClassMetadataSlaveOkay()
+ {
+ $cm1 = new ClassMetadataInfo('a');
+ $cm1->collection = 'a';
+
+ $cm2 = new ClassMetadataInfo('b');
+ $cm2->collection = 'b';
+ $cm2->slaveOkay = true;
+
+ $cm3 = new ClassMetadataInfo('c');
+ $cm3->collection = 'c';
+ $cm3->slaveOkay = false;
+
+ $map = array(
+ array('a', $cm1),
+ array('b', $cm2),
+ array('c', $cm3),
+ );
+
+ $metadataFactory = $this->getMockClassMetadataFactory();
+ $metadataFactory->expects($this->any())
+ ->method('getMetadataFor')
+ ->will($this->returnValueMap($map));
+
+ $coll1 = $this->getMockCollection();
+ $coll1->expects($this->never())
+ ->method('setSlaveOkay');
+
+ $coll2 = $this->getMockCollection();
+ $coll2->expects($this->once())
+ ->method('setSlaveOkay')
+ ->with(true);
+
+ $coll3 = $this->getMockCollection();
+ $coll3->expects($this->once())
+ ->method('setSlaveOkay')
+ ->with(false);
+
+ $dm = new DocumentManagerMock();
+ $dm->metadataFactory = $metadataFactory;
+ $dm->documentCollections = array(
+ 'a' => $coll1,
+ 'b' => $coll2,
+ 'c' => $coll3,
+ );
+
+ $dm->getDocumentCollection('a');
+ $dm->getDocumentCollection('b');
+ $dm->getDocumentCollection('c');
+ }
+
+ private function getMockClassMetadataFactory()
+ {
+ return $this->getMockBuilder('Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ private function getMockCollection()
+ {
+ return $this->getMockBuilder('Doctrine\MongoDB\Collection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
}
@@ -12,6 +12,13 @@
class ClassMetadataInfoTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
+ public function testSlaveOkayDefault()
+ {
+ $cm = new ClassMetadataInfo('stdClass');
+
+ $this->assertNull($cm->slaveOkay);
+ }
+
public function testDefaultDiscriminatorField()
{
$cm = new ClassMetadataInfo('stdClass');

0 comments on commit 09730b7

Please sign in to comment.