Test Failed
Pull Request — master (#66)
by David
03:31
created

TestCountryDao::getCountriesUsingDistinctQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace TheCodingMachine\TDBM\Dao;
4
5
use Porpaginas\Result;
6
use TheCodingMachine\TDBM\Test\Dao\Bean\CountryBean;
7
use TheCodingMachine\TDBM\Test\Dao\Generated\CountryBaseDao;
8
9
/**
10
 * The CountryDao class will maintain the persistence of CountryBean class into the country table.
11
 */
12
class TestCountryDao extends CountryBaseDao
13
{
14
    /**
15
     * @return CountryBean[]|Result
16
     */
17
    public function getCountriesByUserCount()
18
    {
19
        $sql = <<<SQL
20
SELECT country.*
21
FROM country
22
LEFT JOIN users ON users.country_id = country.id
23
GROUP BY country.id
24
ORDER BY COUNT(users.id) DESC
25
SQL;
26
27
        return $this->findFromRawSql($sql);
28
    }
29
30
    /**
31
     * @return CountryBean[]|Result
32
     */
33
    public function getCountriesUsingUnion()
34
    {
35
        $sql = <<<SQL
36
SELECT country.*
37
FROM country
38
WHERE country.id = 1
39
UNION
40
SELECT country.*
41
FROM country
42
WHERE country.id = 2
43
SQL;
44
45
        return $this->findFromRawSql($sql);
46
    }
47
48
    /**
49
     * @return CountryBean[]|Result
50
     */
51
    public function getCountriesUsingSimpleQuery()
52
    {
53
        $sql = <<<SQL
54
SELECT country.*
55
FROM country
56
WHERE country.id = 1
57
SQL;
58
59
        return $this->findFromRawSql($sql);
60
    }
61
62
    /**
63
     * @return CountryBean[]|Result
64
     */
65
    public function getCountriesUsingDistinctQuery()
66
    {
67
        $sql = <<<SQL
68
SELECT DISTINCT country.*
69
FROM country
70
WHERE country.id = 1
71
SQL;
72
73
        return $this->findFromRawSql($sql);
74
    }
75
}
76