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\ReportQuery; |
15
|
|
|
use Symball\ReportBundle\Interfaces\QueryInterface; |
16
|
|
|
|
17
|
|
|
/* Extend the default PHPUnit test case */ |
18
|
|
|
class QueryTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/* Test that posts can be instantiated */ |
21
|
|
|
public function testCreation() |
22
|
|
|
{ |
23
|
|
|
/* Create a post */ |
24
|
|
|
$query = new ReportQuery(); |
25
|
|
|
/* Check that it is an object type */ |
26
|
|
|
$this->assertEquals(true, is_object($query)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testAddQuery() |
30
|
|
|
{ |
31
|
|
|
$reportQuery = new ReportQuery(); |
32
|
|
|
|
33
|
|
|
$mockQuery = $this->createMock(QueryInterface::class); |
34
|
|
|
$reportQuery->addQuery($mockQuery, 'an_alias'); |
35
|
|
|
|
36
|
|
|
$this->assertEquals(['an_alias'], $reportQuery->getQueriesLoaded()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetQuery() |
40
|
|
|
{ |
41
|
|
|
$reportQuery = new ReportQuery(); |
42
|
|
|
|
43
|
|
|
$mockQuery = $this->createMock(QueryInterface::class); |
44
|
|
|
// $mockQuery->method('run')->willReturn(true); |
|
|
|
|
45
|
|
|
$reportQuery->addQuery($mockQuery, 'an_alias'); |
46
|
|
|
|
47
|
|
|
$queryService = $reportQuery->get('an_alias'); |
48
|
|
|
|
49
|
|
|
$this->assertEquals($mockQuery, $queryService); |
50
|
|
|
} |
51
|
|
|
public function testGetNonExistentQuery() |
52
|
|
|
{ |
53
|
|
|
$reportQuery = new ReportQuery(); |
54
|
|
|
|
55
|
|
|
try { |
56
|
|
|
$result = $reportQuery->get('an_alias'); |
|
|
|
|
57
|
|
|
} catch (\Exception $ex) { |
58
|
|
|
// General exception |
59
|
|
|
$this->assertEquals(0, $ex->getCode()); |
60
|
|
|
$this->assertEquals('Query type is not registered: an_alias', $ex->getMessage()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.