Add and improve test coverage
This commit is contained in:
parent
2074781852
commit
3f3461b002
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
/tests/resources/generated
|
/tests/resources/generated
|
||||||
|
/tests/coverage
|
||||||
/vendor
|
/vendor
|
||||||
composer.lock
|
composer.lock
|
||||||
/.idea
|
/.idea
|
||||||
|
10
phpunit.xml
10
phpunit.xml
@ -14,4 +14,14 @@
|
|||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
||||||
|
<logging>
|
||||||
|
<log type="coverage-html" target="tests/coverage/"/>
|
||||||
|
</logging>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">src/</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -13,6 +13,8 @@ class CSV implements EscaperInterface
|
|||||||
/**
|
/**
|
||||||
* Escapes the given string to make it compatible with CSV
|
* Escapes the given string to make it compatible with CSV
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param string $string The string to escape
|
* @param string $string The string to escape
|
||||||
* @return string The escaped string
|
* @return string The escaped string
|
||||||
*/
|
*/
|
||||||
@ -24,6 +26,8 @@ class CSV implements EscaperInterface
|
|||||||
/**
|
/**
|
||||||
* Unescapes the given string to make it compatible with CSV
|
* Unescapes the given string to make it compatible with CSV
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param string $string The string to unescape
|
* @param string $string The string to unescape
|
||||||
* @return string The unescaped string
|
* @return string The unescaped string
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,8 @@ namespace Box\Spout\Common\Helper;
|
|||||||
* Class GlobalFunctionsHelper
|
* Class GlobalFunctionsHelper
|
||||||
* This class wraps global functions to facilitate testing
|
* This class wraps global functions to facilitate testing
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @package Box\Spout\Common\Helper
|
* @package Box\Spout\Common\Helper
|
||||||
*/
|
*/
|
||||||
class GlobalFunctionsHelper
|
class GlobalFunctionsHelper
|
||||||
|
@ -25,7 +25,7 @@ class CellHelper
|
|||||||
{
|
{
|
||||||
$existingIndexes = array_keys($dataArray);
|
$existingIndexes = array_keys($dataArray);
|
||||||
|
|
||||||
$newIndexes = array_fill_keys(range(min($existingIndexes), max($existingIndexes)), $fillValue);
|
$newIndexes = array_fill_keys(range(0, max($existingIndexes)), $fillValue);
|
||||||
$dataArray += $newIndexes;
|
$dataArray += $newIndexes;
|
||||||
|
|
||||||
ksort($dataArray);
|
ksort($dataArray);
|
||||||
|
@ -89,6 +89,8 @@ abstract class AbstractWriter implements WriterInterface
|
|||||||
* Inits the writer and opens it to accept data.
|
* Inits the writer and opens it to accept data.
|
||||||
* By using this method, the data will be outputted directly to the browser.
|
* By using this method, the data will be outputted directly to the browser.
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
|
* @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
|
||||||
* @return \Box\Spout\Writer\AbstractWriter
|
* @return \Box\Spout\Writer\AbstractWriter
|
||||||
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
|
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
|
||||||
|
60
tests/Spout/Reader/Helper/XLSX/CellHelperTest.php
Normal file
60
tests/Spout/Reader/Helper/XLSX/CellHelperTest.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Box\Spout\Reader\Helper\XLSX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CellHelperTest
|
||||||
|
*
|
||||||
|
* @package Box\Spout\Reader\Helper\XLSX
|
||||||
|
*/
|
||||||
|
class CellHelperTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFillMissingArrayIndexes()
|
||||||
|
{
|
||||||
|
$arrayToFill = [1 => 1, 3 => 3];
|
||||||
|
$filledArray = CellHelper::fillMissingArrayIndexes($arrayToFill, 'FILL');
|
||||||
|
|
||||||
|
$expectedFilledArray = ['FILL', 1, 'FILL', 3];
|
||||||
|
$this->assertEquals($expectedFilledArray, $filledArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function dataProviderForTestGetColumnIndexFromCellIndex()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['A1', 0],
|
||||||
|
['Z3', 25],
|
||||||
|
['AA5', 26],
|
||||||
|
['AB24', 27],
|
||||||
|
['BC5', 54],
|
||||||
|
['BCZ99', 1455],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataProviderForTestGetColumnIndexFromCellIndex
|
||||||
|
*
|
||||||
|
* @param string $cellIndex
|
||||||
|
* @param int $expectedColumnIndex
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetColumnIndexFromCellIndex($cellIndex, $expectedColumnIndex)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expectedColumnIndex, CellHelper::getColumnIndexFromCellIndex($cellIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Box\Spout\Common\Exception\InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetColumnIndexFromCellIndexShouldThrowIfInvalidCellIndex()
|
||||||
|
{
|
||||||
|
CellHelper::getColumnIndexFromCellIndex('InvalidCellIndex');
|
||||||
|
}
|
||||||
|
}
|
21
tests/Spout/Reader/ReaderFactoryTest.php
Normal file
21
tests/Spout/Reader/ReaderFactoryTest.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Box\Spout\Reader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ReaderFactoryTest
|
||||||
|
*
|
||||||
|
* @package Box\Spout\Writer
|
||||||
|
*/
|
||||||
|
class ReaderFactoryTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @expectedException \Box\Spout\Common\Exception\UnsupportedTypeException
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCreateReaderShouldThrowWithUnsupportedType()
|
||||||
|
{
|
||||||
|
ReaderFactory::create('unsupportedType');
|
||||||
|
}
|
||||||
|
}
|
@ -153,6 +153,19 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedRows, $allRows);
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReadShouldPreserveSpaceIfSpecified()
|
||||||
|
{
|
||||||
|
$allRows = $this->getAllRowsForFile('sheet_with_preserve_space_shared_strings.xlsx');
|
||||||
|
|
||||||
|
$expectedRows = [
|
||||||
|
[' s1--A1', 's1--B1 ', ' s1--C1 '],
|
||||||
|
];
|
||||||
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -171,7 +184,7 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$allRows = $this->getAllRowsForFile('billion_laughs_test_file.xlsx');
|
$allRows = $this->getAllRowsForFile('billion_laughs_test_file.xlsx');
|
||||||
|
|
||||||
$expectedMaxMemoryUsage = 10 * 1024 * 1024; // 10MB
|
$expectedMaxMemoryUsage = 20 * 1024 * 1024; // 20MB
|
||||||
$this->assertLessThan($expectedMaxMemoryUsage, memory_get_peak_usage(true), 'Entities should not be expanded and therefore consume all the memory.');
|
$this->assertLessThan($expectedMaxMemoryUsage, memory_get_peak_usage(true), 'Entities should not be expanded and therefore consume all the memory.');
|
||||||
|
|
||||||
$expectedFirstRow = ['s1--A1', 's1--B1', 's1--C1', 's1--D1', 's1--E1'];
|
$expectedFirstRow = ['s1--A1', 's1--B1', 's1--C1', 's1--D1', 's1--E1'];
|
||||||
|
@ -49,6 +49,16 @@ class CSVTest extends \PHPUnit_Framework_TestCase
|
|||||||
$writer->close();
|
$writer->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Box\Spout\Common\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testAddRowsShouldThrowExceptionIfRowsAreNotArrayOfArrays()
|
||||||
|
{
|
||||||
|
$writer = WriterFactory::create(Type::CSV);
|
||||||
|
$writer->addRows(['csv--11', 'csv--12']);
|
||||||
|
$writer->close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
21
tests/Spout/Writer/WriterFactoryTest.php
Normal file
21
tests/Spout/Writer/WriterFactoryTest.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Box\Spout\Writer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WriterFactoryTest
|
||||||
|
*
|
||||||
|
* @package Box\Spout\Writer
|
||||||
|
*/
|
||||||
|
class WriterFactoryTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @expectedException \Box\Spout\Common\Exception\UnsupportedTypeException
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCreateWriterShouldThrowWithUnsupportedType()
|
||||||
|
{
|
||||||
|
WriterFactory::create('unsupportedType');
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user