Use the "external" sheet when checking the name. Also, fix the phpUnit tests.

This commit is contained in:
Bob Wienholt 2017-02-06 14:36:46 -05:00
parent c7e5305014
commit cc8971875b
2 changed files with 45 additions and 4 deletions

View File

@ -164,7 +164,8 @@ class Sheet
*/
protected function isNameUnique($name)
{
foreach ($this->workbook->getWorksheets() as $sheetIndex => $sheet) {
foreach ($this->workbook->getWorksheets() as $sheetIndex => $worksheet) {
$sheet = $worksheet->getExternalSheet();
if ($sheetIndex !== $this->index && $sheet->getName() === $name) {
return false;
}

View File

@ -2,12 +2,16 @@
namespace Box\Spout\Writer\Common;
use Box\Spout\Writer\Common\Internal\AbstractWorkbook;
use Box\Spout\Writer\Common\Internal\WorksheetInterface;
use PHPUnit_Framework_TestCase;
/**
* Class SheetTest
*
* @package Box\Spout\Writer\Common
*/
class SheetTest extends \PHPUnit_Framework_TestCase
class SheetTest extends PHPUnit_Framework_TestCase
{
/**
* @return void
@ -101,8 +105,13 @@ class SheetTest extends \PHPUnit_Framework_TestCase
}
}
class SheetTestWorkbook extends \Box\Spout\Writer\Common\Internal\AbstractWorkbook
class SheetTestWorkbook extends AbstractWorkbook
{
public function __construct()
{
parent::__construct(false, null);
}
protected function getMaxRowsPerWorksheet()
{
return 0;
@ -117,7 +126,7 @@ class SheetTestWorkbook extends \Box\Spout\Writer\Common\Internal\AbstractWorkbo
{
$newSheetIndex = count($this->worksheets);
$sheet = new Sheet($newSheetIndex, $this);
$this->worksheets[] = $sheet;
$this->worksheets[] = new SheetTestWorksheet($sheet);
return $sheet;
}
@ -125,3 +134,34 @@ class SheetTestWorkbook extends \Box\Spout\Writer\Common\Internal\AbstractWorkbo
{
}
}
class SheetTestWorksheet implements WorksheetInterface
{
private $sheet;
public function __construct(Sheet $sheet)
{
$this->sheet = $sheet;
}
public function addRow($dataRow, $style)
{
}
public function close()
{
}
public function getExternalSheet()
{
return $this->sheet;
}
public function getLastWrittenRowIndex()
{
}
}