diff --git a/src/Keboola/CsvTable/Table.php b/src/Keboola/CsvTable/Table.php index fa44d53..1457ec1 100755 --- a/src/Keboola/CsvTable/Table.php +++ b/src/Keboola/CsvTable/Table.php @@ -28,14 +28,14 @@ class Table extends CsvWriter { /** @var array */ protected $header = []; - public function __construct(string $name, array $header = [], Temp $temp = null, $delimiter = CsvOptions::DEFAULT_DELIMITER, $enclosure = CsvOptions::DEFAULT_ENCLOSURE, $lineBreak = "\n") + public function __construct(string $name, array $header = [], bool $writeHeader = true, Temp $temp = null, $delimiter = CsvOptions::DEFAULT_DELIMITER, $enclosure = CsvOptions::DEFAULT_ENCLOSURE, $lineBreak = "\n") { $this->temp = $temp ? $temp : new Temp('csv-table'); $this->header = $header; $tmpFile = $this->temp ->createTmpFile($name); parent::__construct($tmpFile->getPathname(), $delimiter, $enclosure, $lineBreak); - if (!empty($this->header)) { + if (!empty($this->header) && $writeHeader) { $this->writeRow($this->header); } diff --git a/tests/Keboola/CsvTable/TableTest.php b/tests/Keboola/CsvTable/TableTest.php index aa2282c..4b000e4 100755 --- a/tests/Keboola/CsvTable/TableTest.php +++ b/tests/Keboola/CsvTable/TableTest.php @@ -24,6 +24,20 @@ public function testCreate() ); } + public function testDontWriteHeader() + { + $table = new Table('filename_suffix', ['first_col', 'second_col'], false); + $this->assertFileExists($table->getPathName()); + $this->assertEquals('', file_get_contents($table->getPathName())); + $this->assertEquals( + array ( + 0 => 'first_col', + 1 => 'second_col', + ), + $table->getHeader() + ); + } + public function testPrimaryKey() { $table = new Table('pk', ['id', 'user', 'data']);