Added check whether writer is opened before trying to close book. Fixes #392.

This commit is contained in:
Alexey Rehov 2017-03-24 13:37:28 +02:00
parent 36d3596f83
commit 6572e713bf
2 changed files with 14 additions and 1 deletions

View File

@ -125,7 +125,7 @@ class Writer extends AbstractMultiSheetsWriter
*/
protected function closeWriter()
{
if ($this->book) {
if ($this->book && $this->isWriterOpened) {
$this->book->close($this->filePointer);
}
}

View File

@ -490,6 +490,19 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $finfo->file($resourcePath));
}
/**
* @return void
*/
public function testCloseIsNotAppliedWhenWriterIsNotOpened()
{
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer->openToFile('test_close.xlsx');
$writer->addRow(['foo']);
$writer->close();
$writer->close();
}
/**
* @param array $allRows
* @param string $fileName