2017-12-17 07:34:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Functional;
|
|
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for functional test to write and reload file on disk across different formats.
|
|
|
|
*/
|
|
|
|
abstract class AbstractFunctional extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Write spreadsheet to disk, reload and return it.
|
|
|
|
*
|
|
|
|
* @param string $format
|
|
|
|
*
|
|
|
|
* @return Spreadsheet
|
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
protected function writeAndReload(Spreadsheet $spreadsheet, $format, ?callable $readerCustomizer = null)
|
2017-12-17 07:34:40 +00:00
|
|
|
{
|
|
|
|
$filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
|
|
|
|
$writer = IOFactory::createWriter($spreadsheet, $format);
|
|
|
|
$writer->save($filename);
|
|
|
|
|
|
|
|
$reader = IOFactory::createReader($format);
|
2018-02-25 18:38:53 +00:00
|
|
|
if ($readerCustomizer) {
|
|
|
|
$readerCustomizer($reader);
|
|
|
|
}
|
2017-12-17 07:34:40 +00:00
|
|
|
$reloadedSpreadsheet = $reader->load($filename);
|
|
|
|
unlink($filename);
|
|
|
|
|
|
|
|
return $reloadedSpreadsheet;
|
|
|
|
}
|
|
|
|
}
|