sagacity/inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Functional/AbstractFunctional.php
Ryan Prather d52454d1bb Updates to 3rd party libraries
Add Dockerfile and specific docker-php.ini
2018-08-28 21:27:13 -04:00

40 lines
1.1 KiB
PHP

<?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 Spreadsheet $spreadsheet
* @param string $format
* @param null|callable $readerCustomizer
*
* @return Spreadsheet
*/
protected function writeAndReload(Spreadsheet $spreadsheet, $format, callable $readerCustomizer = null)
{
$filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
$writer = IOFactory::createWriter($spreadsheet, $format);
$writer->save($filename);
$reader = IOFactory::createReader($format);
if ($readerCustomizer) {
$readerCustomizer($reader);
}
$reloadedSpreadsheet = $reader->load($filename);
unlink($filename);
return $reloadedSpreadsheet;
}
}