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
@@ -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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user