Files
oleibman 641b6d0ccb Improve Coverage for Shared/Font (#2961)
Shared/Font is hardly covered in unit tests (as opposed to Style/Font which is completely covered). And it presented some good opportunities for code optimization. I wrote and tested the new unit tests first, then optimized the code and confirmed that everything still works.

There is still a bit of a gap with "exact" measurements. I had tests ready, but had to withdraw them when I discovered they weren't quite portable (see https://github.com/php/php-src/issues/9073).
2022-07-29 07:11:37 -07:00

54 lines
1.5 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Shared;
use PhpOffice\PhpSpreadsheet\Exception as SSException;
use PhpOffice\PhpSpreadsheet\Shared\Font;
use PhpOffice\PhpSpreadsheet\Style\Font as StyleFont;
use PHPUnit\Framework\TestCase;
class Font3Test extends TestCase
{
/** @var string */
private $holdDirectory;
protected function setUp(): void
{
$this->holdDirectory = Font::getTrueTypeFontPath();
}
protected function tearDown(): void
{
Font::setTrueTypeFontPath($this->holdDirectory);
}
public function testGetTrueTypeException1(): void
{
$this->expectException(SSException::class);
$this->expectExceptionMessage('Valid directory to TrueType Font files not specified');
$font = new StyleFont();
$font->setName('unknown');
Font::getTrueTypeFontFileFromFont($font);
}
public function testGetTrueTypeException2(): void
{
Font::setTrueTypeFontPath(__DIR__);
$this->expectException(SSException::class);
$this->expectExceptionMessage('Unknown font name');
$font = new StyleFont();
$font->setName('unknown');
Font::getTrueTypeFontFileFromFont($font);
}
public function testGetTrueTypeException3(): void
{
Font::setTrueTypeFontPath(__DIR__);
$this->expectException(SSException::class);
$this->expectExceptionMessage('TrueType Font file not found');
$font = new StyleFont();
$font->setName('Calibri');
Font::getTrueTypeFontFileFromFont($font);
}
}