Added check whether writer is opened before trying to close book. Fixes #392.
This commit is contained in:
parent
36d3596f83
commit
6572e713bf
@ -125,7 +125,7 @@ class Writer extends AbstractMultiSheetsWriter
|
||||
*/
|
||||
protected function closeWriter()
|
||||
{
|
||||
if ($this->book) {
|
||||
if ($this->book && $this->isWriterOpened) {
|
||||
$this->book->close($this->filePointer);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user