Inheritance: implements Prewk\XmlStringStreamer\ParserInterface
 public function test_UniqueNode_parser_with_pubmed_xml_and_container_extraction()
 {
     $file = __DIR__ . "/../../xml/pubmed-example.xml";
     $stream = new File($file, 512);
     $parser = new UniqueNode(array("uniqueNode" => "PubmedArticle", "extractContainer" => true));
     $streamer = new XmlStringStreamer($parser, $stream);
     $expectedPMIDs = array("24531174", "24529294", "24449586");
     $foundPMIDs = array();
     while ($node = $streamer->getNode()) {
         $xmlNode = simplexml_load_string($node);
         $foundPMIDs[] = (string) $xmlNode->MedlineCitation->PMID;
     }
     $this->assertEquals($expectedPMIDs, $foundPMIDs, "The PMID nodes should be as expected");
     $containerXml = simplexml_load_string($parser->getExtractedContainer());
     $this->assertEquals("PubmedArticleSet", $containerXml->getName(), "Root node should be as expected");
     $this->assertEquals("bar", $containerXml->attributes()->foo, "Attributes should be extracted correctly");
     $this->assertEquals("qux", $containerXml->attributes()->baz, "Attributes should be extracted correctly");
 }
    public function test_multiple_roots()
    {
        $node1 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
            </child>
eot;
        $node2 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>2</index>
            </child>
eot;
        $node3 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>3</index>
            </child>
eot;
        $node4 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>3</index>
            </child>
eot;
        $xml = <<<eot
            <?xml version="1.0"?>
            <root-a>
                {$node1}
                {$node2}
            </root-a>
            <root-b>
                {$node3}
                {$node4}
            </root-b>
eot;
        $stream = $this->getStreamMock($xml, 50);
        $parser = new UniqueNode(array("uniqueNode" => "child"));
        $this->assertEquals(trim($node1), trim($parser->getNodeFrom($stream)), "Node 1 should be obtained on the first getNodeFrom from root-a");
        $this->assertEquals(trim($node2), trim($parser->getNodeFrom($stream)), "Node 2 should be obtained on the second getNodeFrom from root-a");
        $this->assertEquals(trim($node3), trim($parser->getNodeFrom($stream)), "Node 3 should be obtained on the third getNodeFrom from root-b");
        $this->assertEquals(trim($node4), trim($parser->getNodeFrom($stream)), "Node 4 should be obtained on the third getNodeFrom from root-b");
        $this->assertFalse(false, "When no nodes are left, false should be returned");
    }
    public function test_sibling_nodes()
    {
        $node1 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
            </child>
eot;
        $node3 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
                {$node1}
                {$node1}
            </child>
eot;
        $node2 = <<<eot
            <child>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
                {$node3}
                {$node1}
            </child>
eot;
        $xml = <<<eot
            <?xml version="1.0"?>
            <root>
                {$node2}
            </root>
eot;
        $stream = $this->getStreamMock($xml, 50);
        $parser = new UniqueNode(array("uniqueNode" => "child", "ignoreNestedNodes" => true));
        $node = $parser->getNodeFrom($stream);
        $this->assertEquals(trim($node2), trim($node), "Nested siblings should be ignored");
    }