mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-22 08:09:15 +00:00
ec4098c8fd
While we might never be able to have 100% of our code strict, we can at the very least do it for all of our tests. This ensures that our tests are using our API with the types as intended by the test author, and not silently be cast to what our API requires.
64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as SpException;
|
|
use PhpOffice\PhpSpreadsheet\Settings;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SettingsTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Settings::setCache(null);
|
|
}
|
|
|
|
public function testGetXMLSettings(): void
|
|
{
|
|
$result = Settings::getLibXmlLoaderOptions();
|
|
self::assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR) & $result));
|
|
}
|
|
|
|
public function testSetXMLSettings(): void
|
|
{
|
|
$original = Settings::getLibXmlLoaderOptions();
|
|
Settings::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID);
|
|
$result = Settings::getLibXmlLoaderOptions();
|
|
self::assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID) & $result));
|
|
Settings::setLibXmlLoaderOptions($original);
|
|
}
|
|
|
|
public function testInvalidChartRenderer(): void
|
|
{
|
|
$this->expectException(SpException::class);
|
|
$this->expectExceptionMessage('Chart renderer must implement');
|
|
Settings::setChartRenderer(self::class);
|
|
}
|
|
|
|
public function testInvalidRequestFactory(): void
|
|
{
|
|
$this->expectException(SpException::class);
|
|
$this->expectExceptionMessage('HTTP client must be configured');
|
|
Settings::getRequestFactory();
|
|
}
|
|
|
|
public function testCache(): void
|
|
{
|
|
$cache1 = Settings::getCache();
|
|
self::assertNotNull($cache1);
|
|
Settings::setCache(null);
|
|
$cache2 = Settings::getCache();
|
|
self::assertEquals($cache1, $cache2);
|
|
self::assertNotSame($cache1, $cache2);
|
|
$array = ['A1' => 10, 'B2' => 20];
|
|
$cache2->setMultiple($array);
|
|
self::assertSame($array, $cache2->getMultiple(array_keys($array)));
|
|
self::assertNull($cache2->get('C3'));
|
|
$cache2->clear();
|
|
self::assertNull($cache2->get('A1'));
|
|
self::assertNull($cache2->get('B2'));
|
|
}
|
|
}
|