Initial unit test for locale floats (#1304)
* Initial unit test for locale floats This will require potential modification of the TravisCI environment to support other locales * var_dump to check output on TravisCI * Fix assertions for double/float and with/without line reference * Style in unit test
This commit is contained in:
parent
596aecab68
commit
1b2c99b190
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LocaleFloatsTest extends TestCase
|
||||
{
|
||||
protected $localeAdjusted;
|
||||
|
||||
protected $currentLocale;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->currentLocale = setlocale(LC_ALL, '0');
|
||||
|
||||
if (!setlocale(LC_ALL, 'fr_FR.UTF-8')) {
|
||||
$this->localeAdjusted = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->localeAdjusted = true;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if ($this->localeAdjusted) {
|
||||
setlocale(LC_ALL, $this->currentLocale);
|
||||
}
|
||||
}
|
||||
|
||||
public function testLocaleFloatsCorrectlyConvertedByWriter()
|
||||
{
|
||||
if (!$this->localeAdjusted) {
|
||||
$this->markTestSkipped('Unable to set locale for testing.');
|
||||
}
|
||||
|
||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
||||
$spreadsheet->getActiveSheet()->setCellValue('A1', 1.1);
|
||||
|
||||
$filename = 'decimalcomma.xlsx';
|
||||
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
||||
$writer->save($filename);
|
||||
|
||||
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
|
||||
$result = $spreadsheet->getActiveSheet()->getCell('A1')->getValue();
|
||||
|
||||
ob_start();
|
||||
var_dump($result);
|
||||
preg_match('/(?:double|float)\(([^\)]+)\)/mui', ob_get_clean(), $matches);
|
||||
$this->assertArrayHasKey(1, $matches);
|
||||
$actual = $matches[1];
|
||||
$this->assertEquals('1,1', $actual);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue