Merge branch 'master' of github.com:box/spout into add-phpstan
Conflicts: .travis.yml CONTRIBUTING.md composer.json src/Spout/Common/Entity/Cell.php tests/Spout/Writer/ODS/WriterTest.php
This commit is contained in:
commit
540667870a
49 files changed
+529
-152
No files matched your search
@@ -129,6 +129,6 @@ class RowTest extends \PHPUnit\Framework\TestCase
|
||||
->setStyle($this->getStyleMock())
|
||||
->setCells([]);
|
||||
|
||||
$this->assertInternalType('object', $row);
|
||||
$this->assertInstanceOf(Row::class, $row);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class FileSystemHelperTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp() : void
|
||||
{
|
||||
$baseFolder = \sys_get_temp_dir();
|
||||
$this->fileSystemHelper = new FileSystemHelper($baseFolder);
|
||||
|
||||
@@ -295,6 +295,10 @@ class ReaderTest extends TestCase
|
||||
*/
|
||||
public function testReadShouldBeProtectedAgainstBillionLaughsAttack()
|
||||
{
|
||||
if (function_exists('xdebug_code_coverage_started') && xdebug_code_coverage_started()) {
|
||||
$this->markTestSkipped('test not compatible with code coverage');
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
$fileName = 'attack_billion_laughs.ods';
|
||||
|
||||
@@ -318,6 +322,10 @@ class ReaderTest extends TestCase
|
||||
*/
|
||||
public function testReadShouldBeProtectedAgainstQuadraticBlowupAttack()
|
||||
{
|
||||
if (function_exists('xdebug_code_coverage_started') && xdebug_code_coverage_started()) {
|
||||
$this->markTestSkipped('test not compatible with code coverage');
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
$fileName = 'attack_quadratic_blowup.ods';
|
||||
|
||||
@@ -197,18 +197,22 @@ class CellValueFormatterTest extends TestCase
|
||||
public function testFormatInlineStringCellValue($value, $expectedFormattedValue)
|
||||
{
|
||||
$nodeListMock = $this->createMock(\DOMNodeList::class);
|
||||
$nodeListMock
|
||||
->expects($this->atLeastOnce())
|
||||
->method('count')
|
||||
->willReturn(1);
|
||||
$nodeListMock
|
||||
->expects($this->atLeastOnce())
|
||||
->method('item')
|
||||
->with(0)
|
||||
->will($this->returnValue((object) ['nodeValue' => $value]));
|
||||
->willReturn((object) ['nodeValue' => $value]);
|
||||
|
||||
$nodeMock = $this->createMock(\DOMElement::class);
|
||||
$nodeMock
|
||||
->expects($this->atLeastOnce())
|
||||
->method('getElementsByTagName')
|
||||
->with(CellValueFormatter::XML_NODE_INLINE_STRING_VALUE)
|
||||
->will($this->returnValue($nodeListMock));
|
||||
->willReturn($nodeListMock);
|
||||
|
||||
/** @var SharedStringsManager $sharedStringManager */
|
||||
$sharedStringManager = $this->createMock(SharedStringsManager::class);
|
||||
|
||||
@@ -25,7 +25,7 @@ class SharedStringsManagerTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp() : void
|
||||
{
|
||||
$this->sharedStringsManager = null;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class SharedStringsManagerTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
public function tearDown() : void
|
||||
{
|
||||
if ($this->sharedStringsManager !== null) {
|
||||
$this->sharedStringsManager->cleanup();
|
||||
|
||||
@@ -72,6 +72,19 @@ class ReaderTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testReadShouldSupportInlineStringsWithMultipleValueNodes()
|
||||
{
|
||||
$allRows = $this->getAllRowsForFile('sheet_with_multiple_value_nodes_in_inline_strings.xlsx');
|
||||
|
||||
$expectedRows = [
|
||||
['VALUE 1 VALUE 2 VALUE 3 VALUE 4', 's1 - B1'],
|
||||
];
|
||||
$this->assertEquals($expectedRows, $allRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -539,6 +552,10 @@ class ReaderTest extends TestCase
|
||||
*/
|
||||
public function testReadShouldBeProtectedAgainstQuadraticBlowupAttack()
|
||||
{
|
||||
if (function_exists('xdebug_code_coverage_started') && xdebug_code_coverage_started()) {
|
||||
$this->markTestSkipped('test not compatible with code coverage');
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
$this->getAllRowsForFile('attack_quadratic_blowup.xlsx');
|
||||
@@ -675,13 +692,29 @@ class ReaderTest extends TestCase
|
||||
$allRows = $this->getAllRowsForFile('sheet_with_empty_cells.xlsx');
|
||||
|
||||
$expectedRows = [
|
||||
['A', 'B', 'C'],
|
||||
['A', '', 'C'],
|
||||
['0', '', ''],
|
||||
['1', '1', ''],
|
||||
];
|
||||
$this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length');
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/box/spout/issues/184
|
||||
* @return void
|
||||
*/
|
||||
public function testReadShouldCreateOutputEmptyCellPreservedWhenNoDimensionsSpecified()
|
||||
{
|
||||
$allRows = $this->getAllRowsForFile('sheet_with_empty_cells_without_dimensions.xlsx');
|
||||
|
||||
$expectedRows = [
|
||||
['A', '', 'C'],
|
||||
['0'],
|
||||
['1', '1'],
|
||||
];
|
||||
$this->assertEquals($expectedRows, $allRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/box/spout/issues/195
|
||||
* @return void
|
||||
@@ -699,6 +732,18 @@ class ReaderTest extends TestCase
|
||||
$this->assertEquals($expectedRows, $allRows, 'Cell values should not be trimmed');
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/box/spout/issues/726
|
||||
* @return void
|
||||
*/
|
||||
public function testReaderShouldSupportStrictOOXML()
|
||||
{
|
||||
$allRows = $this->getAllRowsForFile('sheet_with_strict_ooxml.xlsx');
|
||||
|
||||
$this->assertEquals('UNIQUE_ACCOUNT_IDENTIFIER', $allRows[0][0]);
|
||||
$this->assertEquals('A2Z34NJA7N2ESJ', $allRows[1][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param bool $shouldFormatDates
|
||||
|
||||
@@ -102,7 +102,7 @@ class WriterTest extends TestCase
|
||||
]);
|
||||
$writtenContent = $this->writeToCsvFileAndReturnWrittenContent($allRows, 'csv_with_utf8_bom.csv');
|
||||
|
||||
$this->assertContains(EncodingHelper::BOM_UTF8, $writtenContent, 'The CSV file should contain a UTF-8 BOM');
|
||||
$this->assertStringStartsWith(EncodingHelper::BOM_UTF8, $writtenContent, 'The CSV file should contain a UTF-8 BOM');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ class WriterTest extends TestCase
|
||||
]);
|
||||
$writtenContent = $this->writeToCsvFileAndReturnWrittenContent($allRows, 'csv_no_bom.csv', ',', '"', false);
|
||||
|
||||
$this->assertNotContains(EncodingHelper::BOM_UTF8, $writtenContent, 'The CSV file should not contain a UTF-8 BOM');
|
||||
$this->assertStringNotContainsString(EncodingHelper::BOM_UTF8, $writtenContent, 'The CSV file should not contain a UTF-8 BOM');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ class SheetTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp() : void
|
||||
{
|
||||
$this->sheetManager = new SheetManager(new StringHelper());
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class StyleManagerTest extends TestCase
|
||||
/**
|
||||
* @return StyleManager
|
||||
*/
|
||||
private function getStyleManager()
|
||||
private function getStyleManager() : StyleManager
|
||||
{
|
||||
$style = (new StyleBuilder())->build();
|
||||
$styleRegistry = new StyleRegistry($style);
|
||||
@@ -22,31 +22,37 @@ class StyleManagerTest extends TestCase
|
||||
return new StyleManager($styleRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testApplyExtraStylesIfNeededShouldApplyWrapTextIfCellContainsNewLine()
|
||||
public function testApplyExtraStylesIfNeededShouldApplyWrapTextIfCellContainsNewLine() : void
|
||||
{
|
||||
$style = (new StyleBuilder())->build();
|
||||
$this->assertFalse($style->shouldWrapText());
|
||||
|
||||
$styleManager = $this->getStyleManager();
|
||||
$updatedStyle = $styleManager->applyExtraStylesIfNeeded(new Cell("multi\nlines", $style));
|
||||
$possiblyUpdatedStyle = $styleManager->applyExtraStylesIfNeeded(new Cell("multi\nlines", $style));
|
||||
|
||||
$this->assertTrue($updatedStyle->shouldWrapText());
|
||||
$this->assertTrue($possiblyUpdatedStyle->isUpdated());
|
||||
$this->assertTrue($possiblyUpdatedStyle->getStyle()->shouldWrapText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testApplyExtraStylesIfNeededShouldDoNothingIfWrapTextAlreadyApplied()
|
||||
public function testApplyExtraStylesIfNeededShouldReturnNullIfWrapTextNotNeeded() : void
|
||||
{
|
||||
$style = (new StyleBuilder())->build();
|
||||
$this->assertFalse($style->shouldWrapText());
|
||||
|
||||
$styleManager = $this->getStyleManager();
|
||||
$possiblyUpdatedStyle = $styleManager->applyExtraStylesIfNeeded(new Cell('oneline', $style));
|
||||
|
||||
$this->assertFalse($possiblyUpdatedStyle->isUpdated());
|
||||
}
|
||||
|
||||
public function testApplyExtraStylesIfNeededShouldReturnNullIfWrapTextAlreadyApplied() : void
|
||||
{
|
||||
$style = (new StyleBuilder())->setShouldWrapText()->build();
|
||||
$this->assertTrue($style->shouldWrapText());
|
||||
|
||||
$styleManager = $this->getStyleManager();
|
||||
$updatedStyle = $styleManager->applyExtraStylesIfNeeded(new Cell("multi\nlines", $style));
|
||||
$possiblyUpdatedStyle = $styleManager->applyExtraStylesIfNeeded(new Cell("multi\nlines", $style));
|
||||
|
||||
$this->assertTrue($updatedStyle->shouldWrapText());
|
||||
$this->assertFalse($possiblyUpdatedStyle->isUpdated());
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ class StyleMergerTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp() : void
|
||||
{
|
||||
$this->styleMerger = new StyleMerger();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class StyleRegistryTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp() : void
|
||||
{
|
||||
$this->defaultStyle = (new StyleBuilder())->build();
|
||||
$this->styleRegistry = new StyleRegistry($this->defaultStyle);
|
||||
|
||||
@@ -89,7 +89,7 @@ class SheetTest extends TestCase
|
||||
$pathToContentFile = $resourcePath . '#content.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToContentFile);
|
||||
|
||||
$this->assertContains(' table:display="false"', $xmlContents, 'The sheet visibility should have been changed to "hidden"');
|
||||
$this->assertStringContainsString(' table:display="false"', $xmlContents, 'The sheet visibility should have been changed to "hidden"');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,6 +164,6 @@ class SheetTest extends TestCase
|
||||
$pathToWorkbookFile = $resourcePath . '#content.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToWorkbookFile);
|
||||
|
||||
$this->assertContains("table:name=\"$expectedName\"", $xmlContents, $message);
|
||||
$this->assertStringContainsString("table:name=\"$expectedName\"", $xmlContents, $message);
|
||||
}
|
||||
}
|
||||
@@ -279,6 +279,41 @@ class WriterTest extends TestCase
|
||||
$this->assertValueWasWrittenToSheet($fileName, 1, 10.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowShouldSupportFloatValuesInDifferentLocale()
|
||||
{
|
||||
$previousLocale = \setlocale(LC_ALL, 0);
|
||||
|
||||
try {
|
||||
// Pick a supported locale whose decimal point is a comma.
|
||||
// Installed locales differ from one system to another, so we can't pick
|
||||
// a given locale.
|
||||
$supportedLocales = explode("\n", shell_exec('locale -a'));
|
||||
foreach ($supportedLocales as $supportedLocale) {
|
||||
\setlocale(LC_ALL, $supportedLocale);
|
||||
if (\localeconv()['decimal_point'] === ',') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(',', \localeconv()['decimal_point']);
|
||||
|
||||
$fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx';
|
||||
$dataRows = $this->createRowsFromValues([
|
||||
[1234.5],
|
||||
]);
|
||||
|
||||
$this->writeToODSFile($dataRows, $fileName);
|
||||
|
||||
$this->assertValueWasNotWrittenToSheet($fileName, 1, "1234,5");
|
||||
$this->assertValueWasWrittenToSheet($fileName, 1, "1234.5");
|
||||
} finally {
|
||||
// reset locale
|
||||
\setlocale(LC_ALL, $previousLocale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array>
|
||||
*/
|
||||
@@ -548,7 +583,7 @@ class WriterTest extends TestCase
|
||||
$pathToContentFile = $resourcePath . '#content.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToContentFile);
|
||||
|
||||
$this->assertContains($value, $xmlContents, $message);
|
||||
$this->assertStringContainsString($value, $xmlContents, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -563,7 +598,7 @@ class WriterTest extends TestCase
|
||||
$sheetXmlAsString = $this->getSheetXmlNodeAsString($fileName, $sheetIndex);
|
||||
$valueAsXmlString = "<text:p>$value</text:p>";
|
||||
|
||||
$this->assertContains($valueAsXmlString, $sheetXmlAsString, $message);
|
||||
$this->assertStringContainsString($valueAsXmlString, $sheetXmlAsString, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -578,7 +613,7 @@ class WriterTest extends TestCase
|
||||
$sheetXmlAsString = $this->getSheetXmlNodeAsString($fileName, $sheetIndex);
|
||||
$valueAsXmlString = "<text:p>$value</text:p>";
|
||||
|
||||
$this->assertNotContains($valueAsXmlString, $sheetXmlAsString, $message);
|
||||
$this->assertStringNotContainsString($valueAsXmlString, $sheetXmlAsString, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,7 +30,7 @@ class WriterWithStyleTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp() : void
|
||||
{
|
||||
$this->defaultStyle = (new StyleBuilder())->build();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class SheetTest extends TestCase
|
||||
$pathToWorkbookFile = $resourcePath . '#xl/workbook.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToWorkbookFile);
|
||||
|
||||
$this->assertContains(' state="hidden"', $xmlContents, 'The sheet visibility should have been changed to "hidden"');
|
||||
$this->assertStringContainsString(' state="hidden"', $xmlContents, 'The sheet visibility should have been changed to "hidden"');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,6 +166,6 @@ class SheetTest extends TestCase
|
||||
$pathToWorkbookFile = $resourcePath . '#xl/workbook.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToWorkbookFile);
|
||||
|
||||
$this->assertContains("<sheet name=\"$expectedName\"", $xmlContents, $message);
|
||||
$this->assertStringContainsString("<sheet name=\"$expectedName\"", $xmlContents, $message);
|
||||
}
|
||||
}
|
||||
@@ -394,6 +394,42 @@ class WriterTest extends TestCase
|
||||
$this->assertInlineDataWasWrittenToSheet($fileName, 1, 't="e"><v>#DIV/0</v>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowShouldSupportFloatValuesInDifferentLocale()
|
||||
{
|
||||
$previousLocale = \setlocale(LC_ALL, 0);
|
||||
$valueToWrite = 1234.5; // needs to be defined before changing the locale as PHP8 would expect 1234,5
|
||||
|
||||
try {
|
||||
// Pick a supported locale whose decimal point is a comma.
|
||||
// Installed locales differ from one system to another, so we can't pick
|
||||
// a given locale.
|
||||
$supportedLocales = explode("\n", shell_exec('locale -a'));
|
||||
foreach ($supportedLocales as $supportedLocale) {
|
||||
\setlocale(LC_ALL, $supportedLocale);
|
||||
if (\localeconv()['decimal_point'] === ',') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(',', \localeconv()['decimal_point']);
|
||||
|
||||
$fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx';
|
||||
$dataRows = $this->createRowsFromValues([
|
||||
[$valueToWrite],
|
||||
]);
|
||||
|
||||
$this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false);
|
||||
|
||||
$this->assertInlineDataWasNotWrittenToSheet($fileName, 1, "1234,5");
|
||||
$this->assertInlineDataWasWrittenToSheet($fileName, 1, "1234.5");
|
||||
} finally {
|
||||
// reset locale
|
||||
\setlocale(LC_ALL, $previousLocale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -609,7 +645,7 @@ class WriterTest extends TestCase
|
||||
$pathToSheetFile = $resourcePath . '#xl/worksheets/sheet' . $sheetIndex . '.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToSheetFile);
|
||||
|
||||
$this->assertContains((string) $inlineData, $xmlContents, $message);
|
||||
$this->assertStringContainsString((string) $inlineData, $xmlContents, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -625,7 +661,7 @@ class WriterTest extends TestCase
|
||||
$pathToSheetFile = $resourcePath . '#xl/worksheets/sheet' . $sheetIndex . '.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToSheetFile);
|
||||
|
||||
$this->assertNotContains((string) $inlineData, $xmlContents, $message);
|
||||
$this->assertStringNotContainsString((string) $inlineData, $xmlContents, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -640,6 +676,6 @@ class WriterTest extends TestCase
|
||||
$pathToSharedStringsFile = $resourcePath . '#xl/sharedStrings.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToSharedStringsFile);
|
||||
|
||||
$this->assertContains($sharedString, $xmlContents, $message);
|
||||
$this->assertStringContainsString($sharedString, $xmlContents, $message);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class WriterWithStyleTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp() : void
|
||||
{
|
||||
$this->defaultStyle = (new StyleBuilder())->build();
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user