Completed
Push — master ( acd4a1...e74c63 )
by Povilas
23s
created

FigletTest::testClear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * This is the part of Povils open-source library.
5
 *
6
 * @author Povilas Susinskas
7
 */
8
9
namespace Povils\Figlet\Tests;
10
11
use Povils\Figlet\Figlet;
12
use PHPUnit\Framework\TestCase as TestCase;
13
14
/**
15
 * Class FigletTest
16
 */
17
class FigletTest extends TestCase
18
{
19
    public function testClear()
20
    {
21
        $figlet = new Figlet();
22
        $output = $figlet->render('Test');
0 ignored issues
show
Unused Code introduced by
$output 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...
23
24
        $this->assertNull($figlet->clear());
25
    }
26
27
    public function testRender_Default()
28
    {
29
        $figlet = new Figlet();
30
        $output = $figlet->render('Test');
31
32
        $this->assertEquals($this->getDefaultBigFontText(), $output);
33
    }
34
35 View Code Duplication
    public function testRender_SlantFont()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $figlet = new Figlet();
38
        $figlet->setFont('slant');
39
        $output = $figlet->render('Test');
40
41
        $this->assertEquals($this->getSlantFontText(), $output);
42
    }
43
44
    public function testRender_StretchedAndColorized()
45
    {
46
        $figlet = new Figlet();
47
        $figlet
48
            ->setFontStretching(1)
49
            ->setFontColor('red')
50
            ->setBackgroundColor('light_gray');
51
52
        $output = $figlet->render('Test');
53
54
        $this->assertEquals($this->getModifiedDefaultBigFontText("0;31", "47"), $output);
55
    }
56
57
    /**
58
     * @expectedException InvalidArgumentException
59
     */
60
    public function testRender_UndefinedFontColor()
61
    {
62
        $figlet = new Figlet();
63
        $figlet
64
            ->setFontColor('bright_red');
65
        $figlet->render('Test');
66
    }
67
68
    /**
69
     * @expectedException InvalidArgumentException
70
     */
71
    public function testRender_UndefinedBackgroundColor()
72
    {
73
        $figlet = new Figlet();
74
        $figlet
75
            ->setBackgroundColor('bright_light_gray');
76
        $figlet->render('Test');
77
    }
78
79
    public function testRender_ChangeFontAndCachedLetters()
80
    {
81
        $figlet = new Figlet();
82
        $figlet->setFont('slant');
83
        $figlet->render('Test');
84
        $figlet->setFont('big');
85
        $figlet->render('Test');
86
        $output = $figlet->render('Test');
87
88
        $this->assertEquals($this->getDefaultBigFontText(), $output);
89
    }
90
91 View Code Duplication
    public function testRender_NewFontDir()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93
        $figlet = new Figlet();
94
95
        $figlet
96
            ->setFontDir(__DIR__  .'/font/')
97
            ->setFont('slant');
98
99
        $output = $figlet->render('Test');
100
101
        $this->assertEquals($this->getSlantFontText(), $output);
102
    }
103
104
    /**
105
     * @expectedException Exception
106
     */
107
    public function testRender_BandFont()
108
    {
109
        $figlet = new Figlet();
110
111
        $figlet
112
            ->setFontDir(__DIR__  .'/font/')
113
            ->setFont('badfile');
114
115
        $figlet->render('Test');
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    private function getDefaultBigFontText()
122
    {
123
      return
124
     '  _______                _   ' . "\n" .
125
     ' |__   __|              | |  ' . "\n" .
126
     '    | |      ___   ___  | |_ ' . "\n" .
127
     '    | |     / _ \ / __| | __|' . "\n" .
128
     '    | |    |  __/ \__ \ | |_ ' . "\n" .
129
     '    |_|     \___| |___/  \__|' . "\n" .
130
     '                             ' . "\n" .
131
     '                             ' . "\n";
132
    }
133
134
    /**
135
     * @return string
136
     */
137
    private function getModifiedDefaultBigFontText($fontColor, $backgroundColor)
138
    {
139
        return
140
            "\033[" . $fontColor . 'm' . "\033[" . $backgroundColor . 'm' .
141
            '  _______                   _    ' . "\n" .
142
            ' |__   __|                 | |   ' . "\n" .
143
            '    | |       ___    ___   | |_  ' . "\n" .
144
            '    | |      / _ \  / __|  | __| ' . "\n" .
145
            '    | |     |  __/  \__ \  | |_  ' . "\n" .
146
            '    |_|      \___|  |___/   \__| ' . "\n" .
147
            '                                 ' . "\n" .
148
            '                                 ' . "\n" .
149
            "\033[0m";
150
    }
151
152
    private function getSlantFontText()
153
    {
154
        return
155
        '  ______                 __ ' .  "\n" .
156
        ' /_  __/  ___    _____  / /_' .  "\n" .
157
        '  / /    / _ \  / ___/ / __/' .  "\n" .
158
        ' / /    /  __/ (__  ) / /_  ' .  "\n" .
159
        '/_/     \___/ /____/  \__/  ' .  "\n" .
160
        '                            ' .  "\n";
161
    }
162
163
}
164