public function testFreez() { $em = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->atLeastOnce())->method('getReference')->will($this->returnCallback(function ($class_name, $id) { $ref = new \stdClass(); $ref->class = $class_name; $ref->id = $id; return $ref; })); /* @var $doctrine \PHPUnit_Framework_MockObject_MockObject|Registry */ $doctrine = $this->getMockBuilder('\\Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->getMock(); $doctrine->expects($this->once())->method('getManager')->will($this->returnValue($em)); // set related entities $country = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Country', 'setCountry'); $storage = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Storage', 'setStorage'); $type = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Type', 'setType'); $genre1 = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Genre', 'addGenre'); $genre2 = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Genre', 'addGenre'); $this->item->freez($doctrine); // test freez result $this->assertEquals($country, $this->item->getCountry()); $this->assertEquals($storage, $this->item->getStorage()); $this->assertEquals($type, $this->item->getType()); $this->assertEquals($genre1, $this->item->getGenres()[0]); $this->assertEquals($genre2, $this->item->getGenres()[1]); }