Make CSV reader return Row objects
This commit is contained in:
1 parent
139f7fdfb3
commit
a665b974fa
37 files changed
+664
-214
No files matched your search
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Common\Helper;
|
||||
|
||||
/**
|
||||
* Class CellTypeHelperTest
|
||||
*/
|
||||
class CellTypeHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function testIsEmpty()
|
||||
{
|
||||
$this->assertTrue(CellTypeHelper::isEmpty(null));
|
||||
$this->assertTrue(CellTypeHelper::isEmpty(''));
|
||||
|
||||
$this->assertFalse(CellTypeHelper::isEmpty('string'));
|
||||
$this->assertFalse(CellTypeHelper::isEmpty(0));
|
||||
$this->assertFalse(CellTypeHelper::isEmpty(1));
|
||||
$this->assertFalse(CellTypeHelper::isEmpty(true));
|
||||
$this->assertFalse(CellTypeHelper::isEmpty(false));
|
||||
$this->assertFalse(CellTypeHelper::isEmpty(['string']));
|
||||
$this->assertFalse(CellTypeHelper::isEmpty(new \stdClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function testIsNonEmptyString()
|
||||
{
|
||||
$this->assertTrue(CellTypeHelper::isNonEmptyString('string'));
|
||||
|
||||
$this->assertFalse(CellTypeHelper::isNonEmptyString(''));
|
||||
$this->assertFalse(CellTypeHelper::isNonEmptyString(0));
|
||||
$this->assertFalse(CellTypeHelper::isNonEmptyString(1));
|
||||
$this->assertFalse(CellTypeHelper::isNonEmptyString(true));
|
||||
$this->assertFalse(CellTypeHelper::isNonEmptyString(false));
|
||||
$this->assertFalse(CellTypeHelper::isNonEmptyString(['string']));
|
||||
$this->assertFalse(CellTypeHelper::isNonEmptyString(new \stdClass()));
|
||||
$this->assertFalse(CellTypeHelper::isNonEmptyString(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function testIsNumeric()
|
||||
{
|
||||
$this->assertTrue(CellTypeHelper::isNumeric(0));
|
||||
$this->assertTrue(CellTypeHelper::isNumeric(10));
|
||||
$this->assertTrue(CellTypeHelper::isNumeric(10.1));
|
||||
$this->assertTrue(CellTypeHelper::isNumeric(10.10000000000000000000001));
|
||||
$this->assertTrue(CellTypeHelper::isNumeric(0x539));
|
||||
$this->assertTrue(CellTypeHelper::isNumeric(02471));
|
||||
$this->assertTrue(CellTypeHelper::isNumeric(0b10100111001));
|
||||
$this->assertTrue(CellTypeHelper::isNumeric(1337e0));
|
||||
|
||||
$this->assertFalse(CellTypeHelper::isNumeric('0'));
|
||||
$this->assertFalse(CellTypeHelper::isNumeric('42'));
|
||||
$this->assertFalse(CellTypeHelper::isNumeric(true));
|
||||
$this->assertFalse(CellTypeHelper::isNumeric([2]));
|
||||
$this->assertFalse(CellTypeHelper::isNumeric(new \stdClass()));
|
||||
$this->assertFalse(CellTypeHelper::isNumeric(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function testIsBoolean()
|
||||
{
|
||||
$this->assertTrue(CellTypeHelper::isBoolean(true));
|
||||
$this->assertTrue(CellTypeHelper::isBoolean(false));
|
||||
|
||||
$this->assertFalse(CellTypeHelper::isBoolean(0));
|
||||
$this->assertFalse(CellTypeHelper::isBoolean(1));
|
||||
$this->assertFalse(CellTypeHelper::isBoolean('0'));
|
||||
$this->assertFalse(CellTypeHelper::isBoolean('1'));
|
||||
$this->assertFalse(CellTypeHelper::isBoolean('true'));
|
||||
$this->assertFalse(CellTypeHelper::isBoolean('false'));
|
||||
$this->assertFalse(CellTypeHelper::isBoolean([true]));
|
||||
$this->assertFalse(CellTypeHelper::isBoolean(new \stdClass()));
|
||||
$this->assertFalse(CellTypeHelper::isBoolean(null));
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ use Box\Spout\Common\Creator\HelperFactory;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Helper\EncodingHelper;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Reader\CSV\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
|
||||
use Box\Spout\Reader\CSV\Manager\OptionsManager;
|
||||
use Box\Spout\Reader\Exception\ReaderNotOpenedException;
|
||||
use Box\Spout\Reader\ReaderInterface;
|
||||
@@ -320,7 +320,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheet) {
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
$allRows[] = $row;
|
||||
$allRows[] = $row->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,19 +351,19 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheet) {
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
$allRows[] = $row;
|
||||
$allRows[] = $row->toArray();
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
$allRows[] = $row;
|
||||
$allRows[] = $row->toArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheet) {
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
$allRows[] = $row;
|
||||
$allRows[] = $row->toArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -444,7 +444,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheet) {
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
$allRows[] = $row;
|
||||
$allRows[] = $row->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$optionsManager = $optionsManager ?: new OptionsManager();
|
||||
$globalFunctionsHelper = $globalFunctionsHelper ?: new GlobalFunctionsHelper();
|
||||
$entityFactory = new EntityFactory(new HelperFactory());
|
||||
$entityFactory = new InternalEntityFactory(new HelperFactory());
|
||||
|
||||
return new Reader($optionsManager, $globalFunctionsHelper, $entityFactory);
|
||||
}
|
||||
@@ -516,7 +516,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheetIndex => $sheet) {
|
||||
foreach ($sheet->getRowIterator() as $rowIndex => $row) {
|
||||
$allRows[] = $row;
|
||||
$allRows[] = $row->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Box\Spout\Reader\CSV;
|
||||
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Reader\ReaderFactory;
|
||||
use Box\Spout\Reader\Common\Creator\EntityFactory;
|
||||
use Box\Spout\TestUsingResource;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
private function openFileAndReturnSheet($fileName)
|
||||
{
|
||||
$resourcePath = $this->getResourcePath($fileName);
|
||||
$reader = ReaderFactory::create(Type::CSV);
|
||||
$reader = EntityFactory::createReader(Type::CSV);
|
||||
$reader->open($resourcePath);
|
||||
|
||||
$sheet = $reader->getSheetIterator()->current();
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\Common\Entity;
|
||||
|
||||
class CellTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testValidInstance()
|
||||
{
|
||||
$this->assertInstanceOf(Cell::class, new Cell('cell'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeNumeric()
|
||||
{
|
||||
$this->assertTrue((new Cell(0))->isNumeric());
|
||||
$this->assertTrue((new Cell(1))->isNumeric());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeString()
|
||||
{
|
||||
$this->assertTrue((new Cell('String!'))->isString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeEmptyString()
|
||||
{
|
||||
$this->assertTrue((new Cell(''))->isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeEmptyNull()
|
||||
{
|
||||
$this->assertTrue((new Cell(null))->isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeBool()
|
||||
{
|
||||
$this->assertTrue((new Cell(true))->isBoolean());
|
||||
$this->assertTrue((new Cell(false))->isBoolean());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeError()
|
||||
{
|
||||
$this->assertTrue((new Cell([]))->isError());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\Common\Entity;
|
||||
|
||||
class RowTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject|Cell
|
||||
*/
|
||||
private function getCellMock()
|
||||
{
|
||||
return $this->createMock(Cell::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testValidInstance()
|
||||
{
|
||||
$this->assertInstanceOf(Row::class, new Row([], null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetCells()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetCellsResets()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
|
||||
$row->setCells([$this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(1, count($row->getCells()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCells()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
|
||||
$this->assertEquals(0, count($row->getCells()));
|
||||
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddCell()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
|
||||
$row->addCell($this->getCellMock());
|
||||
|
||||
$this->assertEquals(3, count($row->getCells()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testFluentInterface()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
$row
|
||||
->addCell($this->getCellMock())
|
||||
->setCells([]);
|
||||
|
||||
$this->assertTrue(is_object($row));
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ namespace Box\Spout\Reader\ODS;
|
||||
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Reader\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\Exception\IteratorNotRewindableException;
|
||||
use Box\Spout\Reader\ReaderFactory;
|
||||
use Box\Spout\TestUsingResource;
|
||||
|
||||
/**
|
||||
@@ -353,7 +353,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->expectException(IteratorNotRewindableException::class);
|
||||
|
||||
$resourcePath = $this->getResourcePath('one_sheet_with_strings.ods');
|
||||
$reader = ReaderFactory::create(Type::ODS);
|
||||
$reader = EntityFactory::createReader(Type::ODS);
|
||||
$reader->open($resourcePath);
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheet) {
|
||||
@@ -377,7 +377,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$allRows = [];
|
||||
$resourcePath = $this->getResourcePath('two_sheets_with_strings.ods');
|
||||
|
||||
$reader = ReaderFactory::create(Type::ODS);
|
||||
$reader = EntityFactory::createReader(Type::ODS);
|
||||
$reader->open($resourcePath);
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheet) {
|
||||
@@ -421,7 +421,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->expectException(IOException::class);
|
||||
|
||||
/** @var \Box\Spout\Reader\ODS\Reader $reader */
|
||||
$reader = ReaderFactory::create(Type::ODS);
|
||||
$reader = EntityFactory::createReader(Type::ODS);
|
||||
$reader->open('unsupported://foobar');
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->expectException(IOException::class);
|
||||
|
||||
/** @var \Box\Spout\Reader\ODS\Reader $reader */
|
||||
$reader = ReaderFactory::create(Type::ODS);
|
||||
$reader = EntityFactory::createReader(Type::ODS);
|
||||
$reader->open('php://memory');
|
||||
}
|
||||
|
||||
@@ -529,7 +529,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$resourcePath = $this->getResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Reader\ODS\Reader $reader */
|
||||
$reader = ReaderFactory::create(Type::ODS);
|
||||
$reader = EntityFactory::createReader(Type::ODS);
|
||||
$reader->setShouldFormatDates($shouldFormatDates);
|
||||
$reader->setShouldPreserveEmptyRows($shouldPreserveEmptyRows);
|
||||
$reader->open($resourcePath);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Box\Spout\Reader\ODS;
|
||||
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Reader\ReaderFactory;
|
||||
use Box\Spout\Reader\Common\Creator\EntityFactory;
|
||||
use Box\Spout\TestUsingResource;
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
private function openFileAndReturnSheets($fileName)
|
||||
{
|
||||
$resourcePath = $this->getResourcePath($fileName);
|
||||
$reader = ReaderFactory::create(Type::ODS);
|
||||
$reader = EntityFactory::createReader(Type::ODS);
|
||||
$reader->open($resourcePath);
|
||||
|
||||
$sheets = [];
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace Box\Spout\Reader\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Reader\Exception\SharedStringNotFoundException;
|
||||
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
|
||||
use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\FileBasedStrategy;
|
||||
@@ -50,7 +50,7 @@ class SharedStringsManagerTest extends \PHPUnit_Framework_TestCase
|
||||
$cachingStrategyFactory = new CachingStrategyFactory();
|
||||
$helperFactory = new HelperFactory();
|
||||
$managerFactory = new ManagerFactory($helperFactory, $cachingStrategyFactory);
|
||||
$entityFactory = new EntityFactory($managerFactory, $helperFactory);
|
||||
$entityFactory = new InternalEntityFactory($managerFactory, $helperFactory);
|
||||
$workbookRelationshipsManager = new WorkbookRelationshipsManager($resourcePath, $entityFactory);
|
||||
|
||||
$this->sharedStringsManager = new SharedStringsManager(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
|
||||
|
||||
/**
|
||||
* Class StyleManagerTest
|
||||
@@ -16,7 +16,7 @@ class StyleManagerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
private function getStyleManagerMock($styleAttributes = [], $customNumberFormats = [])
|
||||
{
|
||||
$entityFactory = $this->createMock(EntityFactory::class);
|
||||
$entityFactory = $this->createMock(InternalEntityFactory::class);
|
||||
$workbookRelationshipsManager = $this->createMock(WorkbookRelationshipsManager::class);
|
||||
|
||||
/** @var StyleManager $styleManager */
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Box\Spout\Reader\XLSX;
|
||||
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Reader\ReaderFactory;
|
||||
use Box\Spout\Reader\Common\Creator\EntityFactory;
|
||||
use Box\Spout\TestUsingResource;
|
||||
|
||||
/**
|
||||
@@ -570,7 +570,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$allRows = [];
|
||||
$resourcePath = $this->getResourcePath('two_sheets_with_inline_strings.xlsx');
|
||||
|
||||
$reader = ReaderFactory::create(Type::XLSX);
|
||||
$reader = EntityFactory::createReader(Type::XLSX);
|
||||
$reader->open($resourcePath);
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheet) {
|
||||
@@ -624,7 +624,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->expectException(IOException::class);
|
||||
|
||||
/** @var \Box\Spout\Reader\XLSX\Reader $reader */
|
||||
$reader = ReaderFactory::create(Type::XLSX);
|
||||
$reader = EntityFactory::createReader(Type::XLSX);
|
||||
$reader->open('unsupported://foobar');
|
||||
}
|
||||
|
||||
@@ -636,7 +636,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->expectException(IOException::class);
|
||||
|
||||
/** @var \Box\Spout\Reader\XLSX\Reader $reader */
|
||||
$reader = ReaderFactory::create(Type::XLSX);
|
||||
$reader = EntityFactory::createReader(Type::XLSX);
|
||||
$reader->open('php://memory');
|
||||
}
|
||||
|
||||
@@ -701,7 +701,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$resourcePath = $this->getResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Reader\XLSX\Reader $reader */
|
||||
$reader = ReaderFactory::create(Type::XLSX);
|
||||
$reader = EntityFactory::createReader(Type::XLSX);
|
||||
$reader->setShouldFormatDates($shouldFormatDates);
|
||||
$reader->setShouldPreserveEmptyRows($shouldPreserveEmptyRows);
|
||||
$reader->open($resourcePath);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Box\Spout\Reader\XLSX;
|
||||
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Reader\ReaderFactory;
|
||||
use Box\Spout\Reader\Common\Creator\EntityFactory;
|
||||
use Box\Spout\TestUsingResource;
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
private function openFileAndReturnSheets($fileName)
|
||||
{
|
||||
$resourcePath = $this->getResourcePath($fileName);
|
||||
$reader = ReaderFactory::create(Type::XLSX);
|
||||
$reader = EntityFactory::createReader(Type::XLSX);
|
||||
$reader->open($resourcePath);
|
||||
|
||||
$sheets = [];
|
||||
|
||||
@@ -32,79 +32,4 @@ class CellHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals($expectedCellIndex, CellHelper::getCellIndexFromColumnIndex($columnIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function testIsEmpty()
|
||||
{
|
||||
$this->assertTrue(CellHelper::isEmpty(null));
|
||||
$this->assertTrue(CellHelper::isEmpty(''));
|
||||
|
||||
$this->assertFalse(CellHelper::isEmpty('string'));
|
||||
$this->assertFalse(CellHelper::isEmpty(0));
|
||||
$this->assertFalse(CellHelper::isEmpty(1));
|
||||
$this->assertFalse(CellHelper::isEmpty(true));
|
||||
$this->assertFalse(CellHelper::isEmpty(false));
|
||||
$this->assertFalse(CellHelper::isEmpty(['string']));
|
||||
$this->assertFalse(CellHelper::isEmpty(new \stdClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function testIsNonEmptyString()
|
||||
{
|
||||
$this->assertTrue(CellHelper::isNonEmptyString('string'));
|
||||
|
||||
$this->assertFalse(CellHelper::isNonEmptyString(''));
|
||||
$this->assertFalse(CellHelper::isNonEmptyString(0));
|
||||
$this->assertFalse(CellHelper::isNonEmptyString(1));
|
||||
$this->assertFalse(CellHelper::isNonEmptyString(true));
|
||||
$this->assertFalse(CellHelper::isNonEmptyString(false));
|
||||
$this->assertFalse(CellHelper::isNonEmptyString(['string']));
|
||||
$this->assertFalse(CellHelper::isNonEmptyString(new \stdClass()));
|
||||
$this->assertFalse(CellHelper::isNonEmptyString(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function testIsNumeric()
|
||||
{
|
||||
$this->assertTrue(CellHelper::isNumeric(0));
|
||||
$this->assertTrue(CellHelper::isNumeric(10));
|
||||
$this->assertTrue(CellHelper::isNumeric(10.1));
|
||||
$this->assertTrue(CellHelper::isNumeric(10.10000000000000000000001));
|
||||
$this->assertTrue(CellHelper::isNumeric(0x539));
|
||||
$this->assertTrue(CellHelper::isNumeric(02471));
|
||||
$this->assertTrue(CellHelper::isNumeric(0b10100111001));
|
||||
$this->assertTrue(CellHelper::isNumeric(1337e0));
|
||||
|
||||
$this->assertFalse(CellHelper::isNumeric('0'));
|
||||
$this->assertFalse(CellHelper::isNumeric('42'));
|
||||
$this->assertFalse(CellHelper::isNumeric(true));
|
||||
$this->assertFalse(CellHelper::isNumeric([2]));
|
||||
$this->assertFalse(CellHelper::isNumeric(new \stdClass()));
|
||||
$this->assertFalse(CellHelper::isNumeric(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function testIsBoolean()
|
||||
{
|
||||
$this->assertTrue(CellHelper::isBoolean(true));
|
||||
$this->assertTrue(CellHelper::isBoolean(false));
|
||||
|
||||
$this->assertFalse(CellHelper::isBoolean(0));
|
||||
$this->assertFalse(CellHelper::isBoolean(1));
|
||||
$this->assertFalse(CellHelper::isBoolean('0'));
|
||||
$this->assertFalse(CellHelper::isBoolean('1'));
|
||||
$this->assertFalse(CellHelper::isBoolean('true'));
|
||||
$this->assertFalse(CellHelper::isBoolean('false'));
|
||||
$this->assertFalse(CellHelper::isBoolean([true]));
|
||||
$this->assertFalse(CellHelper::isBoolean(new \stdClass()));
|
||||
$this->assertFalse(CellHelper::isBoolean(null));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user