public function test_StringWalker_parser_with_pubmed_xml_and_container_extraction()
 {
     $file = __DIR__ . "/../../xml/pubmed-example.xml";
     $stream = new File($file, 16384);
     $parser = new StringWalker(array("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-a>
                <foo baz="attribute" />
                <bar/>
                <index>1</index>
            </child-a>
eot;
        $node2 = <<<eot
            <child-a>
                <foo baz="attribute" />
                <bar/>
                <index>2</index>
            </child-a>
eot;
        $node3 = <<<eot
            <child-b>
                <foo baz="attribute" />
                <bar/>
                <index>3</index>
            </child-b>
eot;
        $node4 = <<<eot
            <child-b>
                <foo baz="attribute" />
                <bar/>
                <index>3</index>
            </child-b>
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 StringWalker();
        $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");
    }