QueryTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 47
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreation() 0 7 1
A testAddQuery() 0 9 1
A testGetQuery() 0 12 1
A testGetNonExistentQuery() 0 12 2
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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');
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...
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