Passed
Push — master ( b8250a...45c3a8 )
by Dan
02:25
created

FontMetricsTest::testMetricsVertical()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace SixtyNine\Cloud\Tests\Builder;
4
5
use SixtyNine\Cloud\Factory\FontsFactory;
6
use SixtyNine\Cloud\FontMetrics;
7
8
class FontMetricsTest extends \PHPUnit_Framework_TestCase
9
{
10
    public function testMetricsHorizontal()
11
    {
12
        $factory = FontsFactory::create(__DIR__ . '/fixtures/fonts');
13
        $calc = new FontMetrics($factory);
14
15
        $size1 = $calc->calculateSize('abc', 'Arial.ttf', 10);
16
        $size2 = $calc->calculateSize('abc', 'Arial.ttf', 12);
17
        $size3 = $calc->calculateSize('abc', 'Arial.ttf', 1);
18
        $size4 = $calc->calculateSize('a', 'Arial.ttf', 1);
19
20
        $this->assertTrue($size1->getWidth() < $size2->getWidth());
21
        $this->assertTrue($size1->getHeight() < $size2->getHeight());
22
        $this->assertTrue($size3->getWidth() < $size1->getWidth());
23
        $this->assertTrue($size3->getHeight() < $size1->getHeight());
24
        $this->assertTrue($size4->getWidth() < $size3->getWidth());
25
        $this->assertEquals($size4->getHeight(),  $size3->getHeight());
26
    }
27
28
    public function testMetricsVertical()
29
    {
30
        $factory = FontsFactory::create(__DIR__ . '/fixtures/fonts');
31
        $calc = new FontMetrics($factory);
32
33
        $size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270);
34
        $size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270);
35
        $size3 = $calc->calculateSize('abc', 'Arial.ttf', 1, 270);
36
        $size4 = $calc->calculateSize('a', 'Arial.ttf', 1, 270);
37
38
        $this->assertTrue($size1->getWidth() < $size2->getWidth());
39
        $this->assertTrue($size1->getHeight() < $size2->getHeight());
40
        $this->assertTrue($size3->getWidth() < $size1->getWidth());
41
        $this->assertTrue($size3->getHeight() < $size1->getHeight());
42
        $this->assertEquals($size4->getWidth(), $size3->getWidth());
43
        $this->assertTrue($size4->getHeight() <  $size3->getHeight());
44
    }
45
46
    public function testLoadSingleFont()
47
    {
48
        $factory = FontsFactory::create(__DIR__ . '/fixtures/fonts/Arial.ttf', false);
49
        $calc = new FontMetrics($factory);
50
        $size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270);
51
        $size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270);
52
        $this->assertTrue($size1->getWidth() < $size2->getWidth());
53
    }
54
55
    public function testLoadMultipleFonts()
56
    {
57
        $factory = FontsFactory::create([__DIR__ . '/fixtures/fonts/Arial.ttf'], false);
0 ignored issues
show
Documentation introduced by
array(__DIR__ . '/fixtures/fonts/Arial.ttf') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
        $calc = new FontMetrics($factory);
59
        $size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270);
60
        $size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270);
61
        $this->assertTrue($size1->getWidth() < $size2->getWidth());
62
    }
63
}
64