コード例 #1
0
    public function testAppendStream()
    {
        file_put_contents("cache/unit-test-xml-stream.xml", '<?xml version="1.0" encoding="ISO-8859-1"?>
<meals>
	<meal>
		<name>Breakfast</name>
		<calories>100</calories>
	</meal>
	<meal>
		<name>Dinner</name>
		<calories>200</calories>
	</meal>
	<meal>
		<name>Lunch</name>
		<calories>300</calories>
	</meal>
</meals>
');
        @unlink("cache/unit-test-csv-output-from-xml.csv");
        $stream = new XmlStream("meal", "cache/unit-test-xml-stream.xml");
        $csvStream = new CsvStream("cache/unit-test-csv-output-from-xml.csv");
        $csvStream->appendStream($stream);
        $this->assertFileExists("cache/unit-test-csv-output-from-xml.csv");
        $content = file_get_contents("cache/unit-test-csv-output-from-xml.csv");
        $content = str_replace("\r\n", "\n", $content);
        $this->assertEquals("name,calories\nBreakfast,100\nDinner,200\nLunch,300", $content);
    }
コード例 #2
0
ファイル: CsvStreamTest.php プロジェクト: rhubarbphp/rhubarb
 public function testStreamWritingNewFile()
 {
     @unlink("cache/unit-test-csv-stream-new.csv");
     $stream = new CsvStream("cache/unit-test-csv-stream-new.csv");
     $stream->appendItem(["a" => "alan", "b" => "ryan", "c" => "john"]);
     $stream->close();
     $content = file_get_contents("cache/unit-test-csv-stream-new.csv");
     $content = str_replace("\r\n", "\n", $content);
     $this->assertEquals("a,b,c\nalan,ryan,john", $content);
 }