Skip to content

Commit

Permalink
add GH1346 Test
Browse files Browse the repository at this point in the history
  • Loading branch information
zajca authored and malarzm committed Jan 31, 2016
1 parent 21c8a94 commit 7a6bdee
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1346Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

class GH1346Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
/**
* @group GH1346Test
*/
public function testPublicProperty()
{

$refrenced1 = new GH1346ReferencedDocument();
$refrenced2 = new GH1346ReferencedDocument();
$gH1346Document = new GH1346Document();
$gH1346Document->addReference($refrenced1);

$this->dm->persist($refrenced2);
$this->dm->persist($refrenced1);
$this->dm->persist($gH1346Document);
$this->dm->flush();
$this->dm->clear();

$gH1346Document = $this->dm->getRepository(__NAMESPACE__ . '\GH1346Document')->find($gH1346Document->getId());
$refrenced2 = $this->dm->getRepository(__NAMESPACE__ . '\GH1346ReferencedDocument')->find($refrenced2->getId());

$gH1346Document->addReference($refrenced2);

$this->dm->persist($gH1346Document);
$this->dm->flush();

$this->assertEquals(2, $gH1346Document->getReferences()->count());

$this->dm->flush();
}
}


/**
* @ODM\Document
*/
class GH1346Document
{
/** @ODM\Id */
protected $id;

/** @ODM\ReferenceMany(targetDocument="GH1346ReferencedDocument") */
protected $references;

public function __construct()
{
$this->references = new ArrayCollection();
}

public function getId()
{
return $this->id;
}

public function addReference($otherReference)
{
$this->references->add($otherReference);
}

public function getReferences()
{
return $this->references;
}
}

/**
* @ODM\Document
*/
class GH1346ReferencedDocument
{
/** @ODM\String() */
public $test;

/** @ODM\Id */
protected $id;

public function setTest($test)
{
$this->test = $test;
}

public function getId()
{
return $this->id;
}
}

0 comments on commit 7a6bdee

Please sign in to comment.