Completed
Push — master ( ec27e4...948d8b )
by smiley
14:17
created

QueryTestAbstract::createDatabase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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