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) |
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.