Completed
Push — master ( 7123c4...c2e283 )
by Povilas
02:54
created

FigletTest::getModifiedDefaultBigFontText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 12
nc 1
nop 2
1
<?php
2
use Povils\Figlet\Figlet;
3
4
/**
5
 * Class FigletTest
6
 */
7
class FigletTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    public function testRender_Default()
10
    {
11
        $figlet = new Figlet();
12
        $output = $figlet->render('Test');
13
14
        $this->assertEquals($this->getDefaultBigFontText(), $output);
15
    }
16
17 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...
18
    {
19
        $figlet = new Figlet();
20
        $figlet->setFont('slant');
21
        $output = $figlet->render('Test');
22
23
        $this->assertEquals($this->getSlantFontText(), $output);
24
    }
25
26
    public function testRender_StretchedAndColorized()
27
    {
28
        $figlet = new Figlet();
29
        $figlet
30
            ->setFontStretching(1)
31
            ->setFontColor('red')
32
            ->setBackgroundColor('light_gray');
33
34
        $output = $figlet->render('Test');
35
36
        $this->assertEquals($this->getModifiedDefaultBigFontText("0;31", "47"), $output);
37
    }
38
39
    /**
40
     * @expectedException InvalidArgumentException
41
     */
42
    public function testRender_UndefinedFontColor()
43
    {
44
        $figlet = new Figlet();
45
        $figlet
46
            ->setFontColor('bright_red');
47
        $figlet->render('Test');
48
    }
49
50
    /**
51
     * @expectedException InvalidArgumentException
52
     */
53
    public function testRender_UndefinedBackgroundColor()
54
    {
55
        $figlet = new Figlet();
56
        $figlet
57
            ->setBackgroundColor('bright_light_gray');
58
        $figlet->render('Test');
59
    }
60
61
    public function testRender_ChangeFontAndCachedLetters()
62
    {
63
        $figlet = new Figlet();
64
        $figlet->setFont('slant');
65
        $figlet->render('Test');
66
        $figlet->setFont('big');
67
        $figlet->render('Test');
68
        $output = $figlet->render('Test');
69
70
        $this->assertEquals($this->getDefaultBigFontText(), $output);
71
    }
72
73 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...
74
    {
75
        $figlet = new Figlet();
76
77
        $figlet
78
            ->setFontDir(__DIR__  .'/font/')
79
            ->setFont('slant');
80
81
        $output = $figlet->render('Test');
82
83
        $this->assertEquals($this->getSlantFontText(), $output);
84
    }
85
86
    /**
87
     * @expectedException Exception
88
     */
89
    public function testRender_BandFont()
90
    {
91
        $figlet = new Figlet();
92
93
        $figlet
94
            ->setFontDir(__DIR__  .'/font/')
95
            ->setFont('badfile');
96
97
        $figlet->render('Test');
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    private function getDefaultBigFontText()
104
    {
105
      return
106
     '  _______                _   ' . "\n" .
107
     ' |__   __|              | |  ' . "\n" .
108
     '    | |      ___   ___  | |_ ' . "\n" .
109
     '    | |     / _ \ / __| | __|' . "\n" .
110
     '    | |    |  __/ \__ \ | |_ ' . "\n" .
111
     '    |_|     \___| |___/  \__|' . "\n" .
112
     '                             ' . "\n" .
113
     '                             ' . "\n";
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    private function getModifiedDefaultBigFontText($fontColor, $backgroundColor)
120
    {
121
        return
122
            "\033[" . $fontColor . 'm' . "\033[" . $backgroundColor . 'm' .
123
            '  _______                   _    ' . "\n" .
124
            ' |__   __|                 | |   ' . "\n" .
125
            '    | |       ___    ___   | |_  ' . "\n" .
126
            '    | |      / _ \  / __|  | __| ' . "\n" .
127
            '    | |     |  __/  \__ \  | |_  ' . "\n" .
128
            '    |_|      \___|  |___/   \__| ' . "\n" .
129
            '                                 ' . "\n" .
130
            '                                 ' . "\n" .
131
            "\033[0m";
132
    }
133
134
    private function getSlantFontText()
135
    {
136
        return
137
        '  ______                 __ ' .  "\n" .
138
        ' /_  __/  ___    _____  / /_' .  "\n" .
139
        '  / /    / _ \  / ___/ / __/' .  "\n" .
140
        ' / /    /  __/ (__  ) / /_  ' .  "\n" .
141
        '/_/     \___/ /____/  \__/  ' .  "\n" .
142
        '                            ' .  "\n";
143
    }
144
145
}
146