FontMetricsTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testMetricsHorizontal() 0 17 1
A testMetricsVertical() 0 17 1
A testLoadSingleFont() 0 8 1
A testLoadMultipleFonts() 0 8 1
1
<?php
2
3
namespace SixtyNine\Cloud\Tests\Builder;
4
5
use SixtyNine\Cloud\Factory\FontsFactory;
6
use SixtyNine\Cloud\FontMetrics;
7
use PHPUnit\Framework\TestCase;
8
9
class FontMetricsTest extends TestCase
10
{
11
    public function testMetricsHorizontal()
12
    {
13
        $factory = FontsFactory::create(__DIR__ . '/fixtures/fonts');
14
        $calc = new FontMetrics($factory);
15
16
        $size1 = $calc->calculateSize('abc', 'Arial.ttf', 10);
17
        $size2 = $calc->calculateSize('abc', 'Arial.ttf', 12);
18
        $size3 = $calc->calculateSize('abc', 'Arial.ttf', 1);
19
        $size4 = $calc->calculateSize('a', 'Arial.ttf', 1);
20
21
        $this->assertTrue($size1->getWidth() < $size2->getWidth());
22
        $this->assertTrue($size1->getHeight() < $size2->getHeight());
23
        $this->assertTrue($size3->getWidth() < $size1->getWidth());
24
        $this->assertTrue($size3->getHeight() < $size1->getHeight());
25
        $this->assertTrue($size4->getWidth() < $size3->getWidth());
26
        $this->assertEquals($size4->getHeight(),  $size3->getHeight());
27
    }
28
29
    public function testMetricsVertical()
30
    {
31
        $factory = FontsFactory::create(__DIR__ . '/fixtures/fonts');
32
        $calc = new FontMetrics($factory);
33
34
        $size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270);
35
        $size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270);
36
        $size3 = $calc->calculateSize('abc', 'Arial.ttf', 1, 270);
37
        $size4 = $calc->calculateSize('a', 'Arial.ttf', 1, 270);
38
39
        $this->assertTrue($size1->getWidth() < $size2->getWidth());
40
        $this->assertTrue($size1->getHeight() < $size2->getHeight());
41
        $this->assertTrue($size3->getWidth() < $size1->getWidth());
42
        $this->assertTrue($size3->getHeight() < $size1->getHeight());
43
        $this->assertEquals($size4->getWidth(), $size3->getWidth());
44
        $this->assertTrue($size4->getHeight() <  $size3->getHeight());
45
    }
46
47
    public function testLoadSingleFont()
48
    {
49
        $factory = FontsFactory::create(__DIR__ . '/fixtures/fonts/Arial.ttf', false);
50
        $calc = new FontMetrics($factory);
51
        $size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270);
52
        $size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270);
53
        $this->assertTrue($size1->getWidth() < $size2->getWidth());
54
    }
55
56
    public function testLoadMultipleFonts()
57
    {
58
        $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...
59
        $calc = new FontMetrics($factory);
60
        $size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270);
61
        $size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270);
62
        $this->assertTrue($size1->getWidth() < $size2->getWidth());
63
    }
64
}
65