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\ReportPattern; |
15
|
|
|
use Symball\ReportBundle\Service\ReportBuilder; |
16
|
|
|
use Symball\ReportBundle\Interfaces\PatternInterface; |
17
|
|
|
|
18
|
|
|
/* Extend the default PHPUnit test case */ |
19
|
|
|
class ReportPatternTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/* Test that posts can be instantiated */ |
22
|
|
|
public function testCreation() |
23
|
|
|
{ |
24
|
|
|
/* Create a post */ |
25
|
|
|
$reportPattern = new ReportPattern(); |
26
|
|
|
/* Check that it is an object type */ |
27
|
|
|
$this->assertEquals(true, is_object($reportPattern)); |
28
|
|
|
} |
29
|
|
|
public function testAddPattern() |
30
|
|
|
{ |
31
|
|
|
$reportPattern = new ReportPattern(); |
32
|
|
|
|
33
|
|
|
$mockPattern = $this->createMock(PatternInterface::class); |
34
|
|
|
$reportPattern->addPattern($mockPattern, 'an_alias'); |
35
|
|
|
|
36
|
|
|
$this->assertEquals(['an_alias'], $reportPattern->getPatternsLoaded()); |
37
|
|
|
} |
38
|
|
|
public function testRunPattern() |
39
|
|
|
{ |
40
|
|
|
$reportPattern = new ReportPattern(); |
41
|
|
|
|
42
|
|
|
$mockPattern = $this->createMock(PatternInterface::class); |
43
|
|
|
$mockPattern->method('run')->willReturn(true); |
44
|
|
|
$reportPattern->addPattern($mockPattern, 'an_alias'); |
45
|
|
|
|
46
|
|
|
$mockReportBuilder= $this->createMock(ReportBuilder::class); |
47
|
|
|
|
48
|
|
|
$result = $reportPattern->run('an_alias', $mockReportBuilder); |
49
|
|
|
|
50
|
|
|
$this->assertEquals(true, $result); |
51
|
|
|
} |
52
|
|
|
public function testRunNonExistentPattern() |
53
|
|
|
{ |
54
|
|
|
$reportPattern = new ReportPattern(); |
55
|
|
|
|
56
|
|
|
try { |
57
|
|
|
$mockReportBuilder= $this->createMock(ReportBuilder::class); |
58
|
|
|
$result = $reportPattern->run('an_alias', $mockReportBuilder); |
|
|
|
|
59
|
|
|
} catch (\Exception $ex) { |
60
|
|
|
// General exception |
61
|
|
|
$this->assertEquals(0, $ex->getCode()); |
62
|
|
|
$this->assertEquals('Report pattern is not registered: an_alias', $ex->getMessage()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.