HelperTest::testColor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/**
3
 * Grandstream-XMLApp
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
namespace mrcnpdlk\Grandstream\XMLApp;
16
17
18
use mrcnpdlk\Grandstream\XMLApp\Application\ModelConstant;
19
use mrcnpdlk\Grandstream\XMLApp\Helper\Color;
20
use mrcnpdlk\Grandstream\XMLApp\Helper\Font;
21
use mrcnpdlk\Grandstream\XMLApp\Helper\Point;
22
use mrcnpdlk\Grandstream\XMLApp\Helper\Rectangle;
23
use mrcnpdlk\Grandstream\XMLApp\Helper\Vector;
24
25
class HelperTest extends TestCase
26
{
27
    public function testColor()
28
    {
29
        $oColor = new Color();
30
        $this->assertEquals('None', $oColor->get());
31
        $oColor = new Color(0);
32
        $this->assertEquals('White', $oColor->get());
33
        $oColor = new Color(100);
34
        $this->assertEquals('Black', $oColor->get());
35
    }
36
37
    public function testColorOutOfRange()
38
    {
39
        $oColor = new Color(-1);
40
        $this->assertEquals('White', $oColor->get());
41
        $oColor = new Color(101);
42
        $this->assertEquals('Black', $oColor->get());
43
    }
44
45
    public function testFont()
46
    {
47
        $oFont = new Font();
48
        $this->assertEquals('Black', $oFont->getColor()->get());
49
        $this->assertEquals(ModelConstant::FONT_UNIFONT, $oFont->getType());
50
        $this->assertEquals(ModelConstant::HORIZONTAL_ALIGN_LEFT, $oFont->getHorizontalAlign());
51
52
        $this->assertEquals(ModelConstant::HORIZONTAL_ALIGN_CENTER,
53
            $oFont->setHorizontalAlign(ModelConstant::HORIZONTAL_ALIGN_CENTER)->getHorizontalAlign());
54
        $this->assertInstanceOf(Color::class,
55
            $oFont->setColor(new Color(100))->getColor());
56
        $this->assertEquals(ModelConstant::FONT_BOLD,
57
            $oFont->setType(ModelConstant::FONT_BOLD)->getType());
58
    }
59
60
    public function testPoint()
61
    {
62
        $oPoint = new Point(3, 4);
63
        $this->assertEquals(3, $oPoint->getX());
64
        $this->assertEquals(4, $oPoint->getY());
65
66
        $movedPoint = $oPoint->move(new Vector(-4, -5));
67
        $this->assertEquals(-1, $movedPoint->getX());
68
        $this->assertEquals(-1, $movedPoint->getY());
69
    }
70
71
    public function testVector()
72
    {
73
        $oVector = new Vector(3, 4);
74
        $this->assertEquals(5, $oVector->getLength());
75
        $this->assertEquals(3, $oVector->getDeltaX());
76
        $this->assertEquals(4, $oVector->getDeltaY());
77
78
        $newVector = $oVector->add(new Vector(-7, -7));
79
        $this->assertEquals(5, $newVector->getLength());
80
        $this->assertEquals(-4, $newVector->getDeltaX());
81
        $this->assertEquals(-3, $newVector->getDeltaY());
82
    }
83
84 View Code Duplication
    public function testRectangle()
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...
85
    {
86
        $oRectangle = new Rectangle(5, 2);
87
        $this->assertEquals(10, $oRectangle->getArea());
88
        $this->assertEquals(5, $oRectangle->getWidth());
89
        $this->assertEquals(2, $oRectangle->getHeight());
90
    }
91
92 View Code Duplication
    public function testRectangleSquare()
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...
93
    {
94
        $oRectangle = new Rectangle(5);
95
        $this->assertEquals(25, $oRectangle->getArea());
96
        $this->assertEquals(5, $oRectangle->getWidth());
97
        $this->assertEquals(5, $oRectangle->getHeight());
98
    }
99
100 View Code Duplication
    public function testRectangleOutOfRange()
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...
101
    {
102
        $oRectangle = new Rectangle(-5, -2);
103
        $this->assertEquals(0, $oRectangle->getArea());
104
        $this->assertEquals(0, $oRectangle->getWidth());
105
        $this->assertEquals(0, $oRectangle->getHeight());
106
    }
107
}
108