PhpSpreadsheet/tests/PhpSpreadsheetTests/Writer/Xlsx/FloatsRetainedTest.php
oleibman 585409a949
Testing - Delete Temp Files When No Longer Needed (#1488)
No code changes. The tests in all of these scripts write to at least
one temporary file, which is then read and not used again. The file
should be deleted to avoid filling up the disk system.
2020-05-24 20:03:07 +09:00

56 lines
1.5 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as Reader;
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as Writer;
use PHPUnit\Framework\TestCase;
class FloatsRetainedTest extends TestCase
{
/**
* @dataProvider providerIntyFloatsRetainedByWriter
*
* @param float|int $value
*/
public function testIntyFloatsRetainedByWriter($value): void
{
$outputFilename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
Settings::setLibXmlLoaderOptions(null);
$sheet = new Spreadsheet();
$sheet->getActiveSheet()->getCell('A1')->setValue($value);
$writer = new Writer($sheet);
$writer->save($outputFilename);
$reader = new Reader();
$sheet = $reader->load($outputFilename);
unlink($outputFilename);
self::assertSame($value, $sheet->getActiveSheet()->getCell('A1')->getValue());
}
public function providerIntyFloatsRetainedByWriter()
{
return [
[-1.0],
[-1],
[0.0],
[0],
[1.0],
[1],
[1e-3],
[1.3e-10],
[1e10],
[3.00000000000000000001],
[99999999999999999],
[99999999999999999.0],
[999999999999999999999999999999999999999999],
[999999999999999999999999999999999999999999.0],
];
}
}