Test Failed
Push — master ( 13f09e...19b9f2 )
by Dan
03:10
created

CloudBuilderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 45
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructor() 0 15 1
A testAddWords() 0 12 1
A testWordNeverUsedShouldNotBreakBuilder() 0 13 1
1
<?php
2
3
namespace SixtyNine\Cloud\Tests\Builder;
4
5
use SixtyNine\Cloud\Builder\CloudBuilder;
6
use SixtyNine\Cloud\Builder\WordsListBuilder;
7
use SixtyNine\Cloud\Model\WordsList;
8
use SixtyNine\Cloud\Model\Word;
9
use SixtyNine\Cloud\Factory\FontsFactory;
10
use SixtyNine\Cloud\Model\Cloud;
11
use PHPUnit\Framework\TestCase;
12
13
class CloudBuilderTest extends TestCase
14
{
15
    public function testConstructor()
16
    {
17
        $factory = FontsFactory::create(__DIR__ . '/../fixtures/fonts');
18
        $cloud = CloudBuilder::create($factory)
19
            ->setBackgroundColor('#ffffff')
20
            ->setDimension(1024, 768)
21
            ->setFont('Arial.ttf')
22
            ->build()
23
        ;
24
        $this->assertInstanceOf(Cloud::class, $cloud);
25
        $this->assertEquals('Arial.ttf', $cloud->getFont());
26
        $this->assertEquals(1024, $cloud->getWidth());
27
        $this->assertEquals(768, $cloud->getHeight());
28
        $this->assertEmpty($cloud->getWords());
29
    }
30
31
    public function testAddWords()
32
    {
33
        $list = WordsListBuilder::create()->importWords('foobar foo foo bar')->build('foobar');
34
        $factory = FontsFactory::create(__DIR__ . '/../fixtures/fonts');
35
        $cloud = CloudBuilder::create($factory)
36
            ->setFont('Arial.ttf')
37
            ->useList($list)
38
            ->build()
39
        ;
40
41
        $this->assertCount(3, $cloud->getWords());
42
    }
43
44
    public function testWordNeverUsedShouldNotBreakBuilder()
45
    {
46
        $list = new WordsList();
47
        $list->addWord((new Word())->setCount(0)->setText('1'));
48
        $factory = FontsFactory::create(__DIR__ . '/../fixtures/fonts');
49
        $cloud = CloudBuilder::create($factory)
0 ignored issues
show
Unused Code introduced by
$cloud is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
50
            ->setFont('Arial.ttf')
51
            ->useList($list)
52
            ->build()
53
        ;
54
55
        $this->assertTrue(true); // If the code above didn't make a division by zero then it's ok...
56
    }
57
}
58