1 parent
30366e6a5d
commit
3bb4fd3d48
14 files changed
+252
-112
No files matched your search
+36
-11
@@ -1,20 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common;
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
|
||||
/**
|
||||
* Class SheetTest
|
||||
*
|
||||
* @package Box\Spout\Writer\Common
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var SheetManager */
|
||||
private $sheetManager;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->sheetManager = new SheetManager(new StringHelper());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $sheetIndex
|
||||
* @param int $associatedWorkbookId
|
||||
* @return Sheet
|
||||
*/
|
||||
private function createSheet($sheetIndex, $associatedWorkbookId)
|
||||
{
|
||||
return new Sheet($sheetIndex, $associatedWorkbookId, $this->sheetManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSheetName()
|
||||
{
|
||||
$sheets = [new Sheet(0, 'workbookId1'), new Sheet(1, 'workbookId1')];
|
||||
$sheets = [$this->createSheet(0, 'workbookId1'), $this->createSheet(1, 'workbookId1')];
|
||||
|
||||
$this->assertEquals('Sheet1', $sheets[0]->getName(), 'Invalid name for the first sheet');
|
||||
$this->assertEquals('Sheet2', $sheets[1]->getName(), 'Invalid name for the second sheet');
|
||||
@@ -26,7 +50,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSetSheetNameShouldCreateSheetWithCustomName()
|
||||
{
|
||||
$customSheetName = 'CustomName';
|
||||
$sheet = new Sheet(0, 'workbookId1');
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
|
||||
$this->assertEquals($customSheetName, $sheet->getName(), "The sheet name should have been changed to '$customSheetName'");
|
||||
@@ -63,7 +87,8 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSetSheetNameShouldThrowOnInvalidName($customSheetName)
|
||||
{
|
||||
(new Sheet(0, 'workbookId1'))->setName($customSheetName);
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +97,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSetSheetNameShouldNotThrowWhenSettingSameNameAsCurrentOne()
|
||||
{
|
||||
$customSheetName = 'Sheet name';
|
||||
$sheet = new Sheet(0, 'workbookId1');
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
@@ -85,10 +110,10 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$customSheetName = 'Sheet name';
|
||||
|
||||
$sheet = new Sheet(0, 'workbookId1');
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
|
||||
$sheet = new Sheet(1, 'workbookId1');
|
||||
$sheet = $this->createSheet(1, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
|
||||
@@ -99,13 +124,13 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$customSheetName = 'Sheet name';
|
||||
|
||||
$sheet = new Sheet(0, 'workbookId1');
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
|
||||
$sheet = new Sheet(0, 'workbookId2');
|
||||
$sheet = $this->createSheet(0, 'workbookId2');
|
||||
$sheet->setName($customSheetName);
|
||||
|
||||
$sheet = new Sheet(1, 'workbookId3');
|
||||
$sheet = $this->createSheet(1, 'workbookId3');
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user