From be195dc1101665248e4e0b555ef5642e6544fac8 Mon Sep 17 00:00:00 2001 From: Adrien Loison Date: Fri, 12 Nov 2021 15:00:14 +0100 Subject: [PATCH] Fix tests with no locales + Apply CSFixer fixes --- .github/workflows/ci.yml | 2 +- .php_cs.dist => .php-cs-fixer.dist.php | 4 ++-- tests/Spout/Writer/ODS/WriterTest.php | 11 +++++++++-- tests/Spout/Writer/XLSX/WriterTest.php | 11 +++++++++-- 4 files changed, 21 insertions(+), 7 deletions(-) rename .php_cs.dist => .php-cs-fixer.dist.php (97%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac8a3b605..56d4a550e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -158,7 +158,7 @@ jobs: run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Run PHP-CS-Fixer - run: vendor/bin/php-cs-fixer fix --config=.php_cs.dist --verbose --diff --dry-run --diff-format=udiff + run: vendor/bin/php-cs-fixer fix --verbose --diff --dry-run --diff-format=udiff static-analysis: name: Static Analysis diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 97% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 9879a529c..c7e7f81df 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -19,7 +19,7 @@ 'no_break_comment' => ['comment_text' => 'do nothing'], 'no_empty_phpdoc' => false, 'no_null_property_initialization' => true, - 'no_short_echo_tag' => true, + 'echo_tag_syntax' => false, 'no_superfluous_elseif' => true, 'no_superfluous_phpdoc_tags' => false, 'no_unneeded_control_parentheses' => ['statements' => ['break', 'clone', 'continue', 'echo_print', 'switch_case', 'yield']], @@ -37,7 +37,7 @@ 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], 'phpdoc_separation' => false, 'protected_to_private' => true, - 'psr4' => true, + 'psr_autoloading' => true, 'return_type_declaration' => ['space_before' => 'one'], 'semicolon_after_instruction' => true, 'simplified_null_return' => false, diff --git a/tests/Spout/Writer/ODS/WriterTest.php b/tests/Spout/Writer/ODS/WriterTest.php index a9aaa0e39..790b0946d 100644 --- a/tests/Spout/Writer/ODS/WriterTest.php +++ b/tests/Spout/Writer/ODS/WriterTest.php @@ -291,12 +291,19 @@ public function testAddRowShouldSupportFloatValuesInDifferentLocale() // Installed locales differ from one system to another, so we can't pick // a given locale. $supportedLocales = explode("\n", shell_exec('locale -a')); + $foundCommaLocale = false; foreach ($supportedLocales as $supportedLocale) { \setlocale(LC_ALL, $supportedLocale); if (\localeconv()['decimal_point'] === ',') { + $foundCommaLocale = true; break; } } + + if (!$foundCommaLocale) { + $this->markTestSkipped('No locale with comma decimal separator'); + } + $this->assertEquals(',', \localeconv()['decimal_point']); $fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx'; @@ -306,8 +313,8 @@ public function testAddRowShouldSupportFloatValuesInDifferentLocale() $this->writeToODSFile($dataRows, $fileName); - $this->assertValueWasNotWrittenToSheet($fileName, 1, "1234,5"); - $this->assertValueWasWrittenToSheet($fileName, 1, "1234.5"); + $this->assertValueWasNotWrittenToSheet($fileName, 1, '1234,5'); + $this->assertValueWasWrittenToSheet($fileName, 1, '1234.5'); } finally { // reset locale \setlocale(LC_ALL, $previousLocale); diff --git a/tests/Spout/Writer/XLSX/WriterTest.php b/tests/Spout/Writer/XLSX/WriterTest.php index 26b379257..a1cbc2d58 100644 --- a/tests/Spout/Writer/XLSX/WriterTest.php +++ b/tests/Spout/Writer/XLSX/WriterTest.php @@ -406,12 +406,19 @@ public function testAddRowShouldSupportFloatValuesInDifferentLocale() // Installed locales differ from one system to another, so we can't pick // a given locale. $supportedLocales = explode("\n", shell_exec('locale -a')); + $foundCommaLocale = false; foreach ($supportedLocales as $supportedLocale) { \setlocale(LC_ALL, $supportedLocale); if (\localeconv()['decimal_point'] === ',') { + $foundCommaLocale = true; break; } } + + if (!$foundCommaLocale) { + $this->markTestSkipped('No locale with comma decimal separator'); + } + $this->assertEquals(',', \localeconv()['decimal_point']); $fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx'; @@ -421,8 +428,8 @@ public function testAddRowShouldSupportFloatValuesInDifferentLocale() $this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false); - $this->assertInlineDataWasNotWrittenToSheet($fileName, 1, "1234,5"); - $this->assertInlineDataWasWrittenToSheet($fileName, 1, "1234.5"); + $this->assertInlineDataWasNotWrittenToSheet($fileName, 1, '1234,5'); + $this->assertInlineDataWasWrittenToSheet($fileName, 1, '1234.5'); } finally { // reset locale \setlocale(LC_ALL, $previousLocale);