Skip to content

Commit 9f9d8ad

Browse files
committed
Merge pull request #26 from BernardoSilva/add-unit-test-ttf
Add unit test to ensure factory is loading TrueType correctly.
2 parents b8af0ca + fc8d99c commit 9f9d8ad

File tree

7 files changed

+83
-0
lines changed

7 files changed

+83
-0
lines changed

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: php
2+
3+
env:
4+
- PREFER_LOWEST="--prefer-lowest"
5+
- PREFER_LOWEST=""
6+
7+
php:
8+
- 5.4
9+
- 5.5
10+
11+
before_script:
12+
- composer dump-autoload
13+
- composer self-update
14+
- composer update --prefer-source $PREFER_LOWEST
15+
16+
script: bin/phpunit
17+
18+
19+
# Use Travis' new container-based infrastructure.
20+
# See http://docs.travis-ci.com/user/migrating-from-legacy/#How-can-I-use-container-based-infrastructure%3F
21+
sudo: false

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"psr-0": {
1515
"FontLib\\": "src/"
1616
}
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^4.8"
1720
}
1821
}

phpunit.xml.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="false"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
stopOnFailure="false"
10+
syntaxCheck="false"
11+
bootstrap="vendor/autoload.php"
12+
>
13+
<testsuites>
14+
<testsuite name="PHP Font Lib Test Suite">
15+
<directory>./tests/FontLib/</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
</phpunit>

sample-fonts/IntelClear-Light.ttf

94.4 KB
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace FontLib\Exception;
4+
5+
class FontNotFoundException extends \Exception
6+
{
7+
public function __construct($fontPath)
8+
{
9+
$this->message = 'Font not found in: ' . $fontPath;
10+
}
11+
}

src/FontLib/Font.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace FontLib;
1010

11+
use FontLib\Exception\FontNotFoundException;
12+
1113
/**
1214
* Generic font file.
1315
*
@@ -22,6 +24,10 @@ class Font {
2224
* @return TrueType\File|null $file
2325
*/
2426
public static function load($file) {
27+
if(!file_exists($file)){
28+
throw new FontNotFoundException($file);
29+
}
30+
2531
$header = file_get_contents($file, false, null, null, 4);
2632
$class = null;
2733

tests/FontLib/FontTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace FontLib\Tests;
4+
5+
use FontLib\Font;
6+
7+
class FontTest extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* @expectedException \Fontlib\Exception\FontNotFoundException
11+
*/
12+
public function testLoadFileNotFound()
13+
{
14+
Font::load('non-existing/font.ttf');
15+
}
16+
17+
public function testLoadTTFFontSuccessfully()
18+
{
19+
$trueTypeFont = Font::load('sample-fonts/IntelClear-Light.ttf');
20+
21+
$this->assertInstanceOf('FontLib\TrueType\File', $trueTypeFont);
22+
}
23+
}

0 commit comments

Comments
 (0)