1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace QB\Generic\Clause; |
6
|
|
|
|
7
|
|
|
use PDO; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use QB\Generic\Expr\Expr; |
10
|
|
|
use QB\Generic\Statement\Select; |
11
|
|
|
|
12
|
|
|
class QueryAsTableTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testToStringFromStringQuery() |
15
|
|
|
{ |
16
|
|
|
$expectedSql = "(SELECT 'foo') AS f"; |
17
|
|
|
|
18
|
|
|
$query = "SELECT 'foo'"; |
19
|
|
|
$alias = 'f'; |
20
|
|
|
|
21
|
|
|
$sut = new QueryAsTable($query, $alias); |
22
|
|
|
$actualSql = (string)$sut; |
23
|
|
|
|
24
|
|
|
$this->assertSame($expectedSql, $actualSql); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testToStringFromObjectQuery() |
28
|
|
|
{ |
29
|
|
|
$expectedSql = "(SELECT 'foo') AS f"; |
30
|
|
|
|
31
|
|
|
$query = new Select("'foo'"); |
32
|
|
|
$alias = 'f'; |
33
|
|
|
|
34
|
|
|
$sut = new QueryAsTable($query, $alias); |
35
|
|
|
$actualSql = (string)$sut; |
36
|
|
|
|
37
|
|
|
$this->assertSame($expectedSql, $actualSql); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGetParamFromStringQuery() |
41
|
|
|
{ |
42
|
|
|
$expectedParams = []; |
43
|
|
|
|
44
|
|
|
$query = "SELECT 'foo'"; |
45
|
|
|
$alias = 'f'; |
46
|
|
|
|
47
|
|
|
$sut = new QueryAsTable($query, $alias); |
48
|
|
|
$actualParams = $sut->getParams(); |
49
|
|
|
|
50
|
|
|
$this->assertSame($expectedParams, $actualParams); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testGetParamFromObjectQuery() |
54
|
|
|
{ |
55
|
|
|
$expectedParams = [['foo', PDO::PARAM_STR]]; |
56
|
|
|
|
57
|
|
|
$query = new Select( |
58
|
|
|
new Column(new Expr('?', ['foo'])) |
59
|
|
|
); |
60
|
|
|
$alias = 'f'; |
61
|
|
|
|
62
|
|
|
$sut = new QueryAsTable($query, $alias); |
63
|
|
|
$actualParams = $sut->getParams(); |
64
|
|
|
|
65
|
|
|
$this->assertSame($expectedParams, $actualParams); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|