ReportStyleTest::testCreation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Symball\ReportBundle\Tests\Unit;
10
11
/* The base PHPUnit test class */
12
use PHPUnit\Framework\TestCase;
13
14
use Symball\ReportBundle\Service\Meta;
15
use Symball\ReportBundle\Service\ReportStyle;
16
use Symball\ReportBundle\Service\ReportBuilder;
17
use Symball\ReportBundle\Interfaces\StyleInterface;
18
19
/* Extend the default PHPUnit test case */
20
class ReportStyleTest extends TestCase
21
{
22
    /* Test that posts can be instantiated */
23
    public function testCreation()
24
    {
25
        /* Create a post */
26
        $reportStyle = new ReportStyle();
27
        /* Check that it is an object type */
28
        $this->assertEquals(true, is_object($reportStyle));
29
    }
30
    public function testAddStyle()
31
    {
32
        $reportStyle = new ReportStyle();
33
34
        $mockStyle = $this->createMock(StyleInterface::class);
35
        $reportStyle->addStyle($mockStyle, 'an_alias');
36
37
        $this->assertEquals(['an_alias'], $reportStyle->getStylesLoaded());
38
    }
39
    public function testRunStyle()
40
    {
41
        $reportStyle = new ReportStyle();
42
43
        $mockStyle = $this->createMock(StyleInterface::class);
44
        $mockStyle->method('run')->willReturn(true);
45
        $reportStyle->addStyle($mockStyle, 'an_alias');
46
47
        $mockMeta = $this->createMock(Meta::class);
48
        $mockMeta->method('getOptions')->willReturn([]);
49
50
        $mockReportBuilder= $this->createMock(ReportBuilder::class);
51
        $mockReportBuilder->method('meta')->will($this->returnValue($mockMeta));
52
53
        $result = $reportStyle->run('an_alias', $mockReportBuilder, 'A1');
54
55
        $this->assertEquals(true, $result);
56
    }
57
    public function testRunNonExistentStyle()
58
    {
59
        $reportStyle = new ReportStyle();
60
61
        $mockMeta = $this->createMock(Meta::class);
62
        $mockMeta->method('getOptions')->willReturn([]);
63
64
        $mockReportBuilder= $this->createMock(ReportBuilder::class);
65
        $mockReportBuilder->method('meta')->will($this->returnValue($mockMeta));
66
67
        try {
68
            $result = $reportStyle->run('an_alias', $mockReportBuilder, 'A1');
0 ignored issues
show
Unused Code introduced by
$result 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...
69
        } catch (\Exception $ex) {
70
            // General exception
71
            $this->assertEquals(0, $ex->getCode());
72
            $this->assertEquals('Report style is not registered: an_alias', $ex->getMessage());
73
        }
74
    }
75
}
76