getNode()) !== false) {
$nodes[] = $node;
}
return $nodes;
}
public function testStringWalkerYieldsEachRootChildNode(): void {
$xml = ''
. 'Alpha'
. 'Beta'
. '';
$nodes = $this->collect(XmlStringStreamer::createStringWalkerParser($this->streamFrom($xml)));
$this->assertCount(2, $nodes, 'one node per depth-2 child');
$this->assertStringContainsString('id="1"', $nodes[0]);
$this->assertStringContainsString('Alpha', $nodes[0]);
$this->assertStringContainsString('id="2"', $nodes[1]);
$this->assertStringContainsString('Beta', $nodes[1]);
}
public function testUniqueNodeParserExtractsNamedElements(): void {
$xml = 'One'
. 'Two';
$streamer = XmlStringStreamer::createUniqueNodeParser(
$this->streamFrom($xml),
['uniqueNode' => 'channel']
);
$nodes = $this->collect($streamer);
$this->assertCount(2, $nodes);
$this->assertStringContainsString('id="c1"', $nodes[0]);
$this->assertStringContainsString('One', $nodes[0]);
$this->assertStringContainsString('id="c2"', $nodes[1]);
}
public function testEmptyDocumentYieldsNoNodes(): void {
$nodes = $this->collect(XmlStringStreamer::createStringWalkerParser($this->streamFrom('')));
$this->assertSame([], $nodes);
}
public function testUniqueNodeRequiresTheUniqueNodeOption(): void {
$this->expectException(\Exception::class);
new UniqueNode([]);
}
public function testFileThrowsWhenPathDoesNotExist(): void {
$this->expectException(\Exception::class);
new File('/no/such/file/xc_vm_test_missing.xml');
}
public function testFileAcceptsAStreamResource(): void {
$file = new File($this->streamFrom(''));
$this->assertIsString($file->getChunk(), 'reads a chunk from the handle');
}
}