public function testToJson() { $collection = new CiteCollection(); for ($i = 1; $i < 4; $i++) { $cite = $this->getMock('Cite', array('toJson')); $cite->expects($this->once())->method('toJson')->will($this->returnValue('JSON' . $i)); $collection->add($cite); } $this->assertEquals("[JSON1, JSON2, JSON3]", $collection->toJson()); }
/** * @param string $fileName * @return CiteCollection */ public static function loadFromXml(SimpleXMLElement $xml) { $collection = new CiteCollection(); foreach ($xml->cite as $cite) { $collection->add(new Cite(array('author' => $cite->author, 'title' => $cite->title, 'text' => $cite->text))); } return $collection; }