|
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'); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.