Completed
Push — master ( f08c1d...ffbb02 )
by smiley
02:22
created

QueryTest::testSelect()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 25
rs 8.8571
c 1
b 0
f 0
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * @filesource   QueryTest.php
5
 * @created      12.05.2017
6
 * @package      chillerlan\DatabaseTest\Query
7
 * @author       Smiley <[email protected]>
8
 * @copyright    2017 Smiley
9
 * @license      MIT
10
 */
11
12
namespace chillerlan\DatabaseTest\Query;
13
14
use chillerlan\Database\Drivers\PDO\PDOMySQLDriver;
15
use chillerlan\Database\DBQuery;
16
use chillerlan\Database\Query\CreateInterface;
17
use chillerlan\Database\Query\CreateTableInterface;
18
use chillerlan\Database\Query\DeleteInterface;
19
use chillerlan\Database\Query\SelectInterface;
20
use chillerlan\Database\Query\StatementInterface;
21
use chillerlan\Database\Query\UpdateInterface;
22
use chillerlan\DatabaseTest\TestAbstract;
23
24
/**
25
 * Class QueryTest
26
 */
27
class QueryTest extends TestAbstract{
28
29
	/**
30
	 * @var \chillerlan\Database\DBQuery
31
	 */
32
	protected $statement;
33
34
	protected $driver = PDOMySQLDriver::class;
35
	protected $envVar = 'DB_MYSQLI_';
36
37
	public function setUp(){
38
		parent::setUp();
39
40
		$this->statement = new DBQuery($this->DBDriver);
41
	}
42
43
	public function testSelect(){
44
		$select = $this->statement->select;
45
		$this->assertInstanceOf(SelectInterface::class, $select);
46
		$this->assertInstanceOf(StatementInterface::class, $select);
47
48
		$select
49
			->distinct()
50
			->cols(['t2.what', 't1.foo' => 'foo'])
51
			->cols(['t1.bar' => ['bar', 'lower'], 'nope', ['what', 'upper']])
52
			->from(['foo' => 't1', 'bar' => 't2'])
53
			->from(['whatever'])
54
			->where('t2.what', 3)
55
			->openBracket('and')
56
			->where('t1.what', 't2.what', '>', false)
57
			->where('t2.what', [1,2,3], 'in')
58
			->closeBracket()
59
			->where('t3.what', $this->statement->select->cols(['foo'])->from(['nope'])->where('bar', 42), 'in', true, 'or')
60
			->groupby(['foo', 'bar'])
61
			->orderby(['foo', 'bar' => 'desc'])
62
			->offset(3)
63
			->limit(5);
64
65
#		print_r($select->sql());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
66
67
	}
68
69
	public function testDelete(){
70
		$create = $this->statement->delete;
71
		$this->assertInstanceOf(DeleteInterface::class, $create);
72
		$this->assertInstanceOf(StatementInterface::class, $create);
73
	}
74
75
	public function testUpdate(){
76
		$create = $this->statement->update;
77
		$this->assertInstanceOf(UpdateInterface::class, $create);
78
		$this->assertInstanceOf(StatementInterface::class, $create);
79
	}
80
81
	public function testCreate(){
82
		$create = $this->statement->create;
83
		$this->assertInstanceOf(CreateInterface::class, $create);
84
		$this->assertInstanceOf(StatementInterface::class, $create);
85
86
		$database = $create->database('foo');
0 ignored issues
show
Unused Code introduced by
$database 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...
87
88
#		print_r($database->name('bar')->collate('utf8mb4_bin')->ifNotExists()->sql());
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
89
90
		$table = $create->table();
91
		$this->assertInstanceOf(CreateTableInterface::class, $table);
92
		$this->assertInstanceOf(StatementInterface::class, $table);
93
94
		$table
95
			->name('foo')
96
			->ifNotExists()
97
			->primaryKey('id')
98
			->field('id', 'int', 10, 'unsigned', null, false, null, null, 'AUTO_INCREMENT')
99
			->field('bar', 'varchar', 32, null, 'utf8mb4_bin', true, 'NULL', 'foo')
100
			->field('nope', 'decimal', '9,6');
101
102
#		print_r($table->sql());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
103
	}
104
105
}
106
107
108
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
109
110
		// get skills
111
		$sql = 'SELECT skilldata.`id`,
112
					skilldesc.`pve_name`,
113
					skilldesc.`pve_desc`,
114
					skilldesc.`pve_desc_short`,
115
					skilldesc.`pvp_name`,
116
					skilldesc.`pvp_desc`,
117
					skilldesc.`pvp_desc_short`,
118
					skilldata.`campaign` AS `campaign_id`,
119
					skilldata.`elite`,
120
					skilldata.`pve`,
121
					skilldata.`pvp_split`,
122
					skilldata.`attribute` AS `attribute_id`,
123
					skilldata.`'.$mode.'_activation` AS `activation`,
124
					skilldata.`'.$mode.'_recharge` AS `recharge`,
125
					skilldata.`'.$mode.'_energy` AS `energy`,
126
					skilldata.`'.$mode.'_upkeep` AS `upkeep`,
127
					skilldata.`'.$mode.'_adrenaline` AS `adrenaline`,
128
					skilldata.`'.$mode.'_sacrifice` AS `sacrifice`,
129
					skilldata.`'.$mode.'_overcast` AS `overcast`,
130
					skilldata.`'.$mode.'_type` AS `type_id`,
131
					profs.`name_'.$lang.'` AS `prof`,
132
					profs.`id` AS `prof_id`,
133
					profs.`abbr_'.$lang.'` AS `prof_abbr`,
134
					attribs.`name_'.$lang.'` AS `attribute`,
135
					attribs.`primary`,
136
					attribs.`max` AS `attribute_max`,
137
					types.`name_'.$lang.'` AS `type`,
138
					campaigns.`name_'.$lang.'` AS `campaign`
139
				FROM '.constant('SKILLDESC_'.strtoupper($lang)).' AS skilldesc,
140
					'.SKILLDATA.' AS skilldata,
141
					'.PROFESSIONS.' AS profs,
142
					'.ATTRIBUTES.' AS attribs,
143
					'.SKILLTYPES.' AS types,
144
					'.CAMPAIGNS.' AS campaigns
145
				WHERE skilldata.`profession` = profs.`id`
146
					AND skilldata.`attribute` = attribs.`id`
147
					AND skilldata.`'.$mode.'_type` = types.`id`
148
					AND skilldesc.`id` = skilldata.`id`
149
					AND campaigns.`id` = skilldata.`campaign`
150
					AND skilldata.`id` IN(?,?,?,?,?,?,?,?)';
151
152
153
154
 */