Completed
Push — master ( ffbb02...68e5b2 )
by smiley
02:42
created

QueryTestAbstract::testCreateDatabaseNoName()   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
/*
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...
74
	public function testSelect(){
75
		$select = $this->statement->select;
76
77
		$select
78
			->distinct()
79
			->cols(['t2.what', 't1.foo' => 'foo'])
80
			->cols(['t1.bar' => ['bar', 'lower'], 'nope', ['what', 'upper']])
81
			->from(['foo' => 't1', 'bar' => 't2'])
82
			->from(['whatever'])
83
			->where('t2.what', 3)
84
			->openBracket('and')
85
			->where('t1.what', 't2.what', '>', false)
86
			->where('t2.what', [1,2,3], 'in')
87
			->closeBracket()
88
			->where('t3.what', $this->statement->select->cols(['foo'])->from(['nope'])->where('bar', 42), 'in', true, 'or')
89
			->groupby(['foo', 'bar'])
90
			->orderby(['foo', 'bar' => 'desc'])
91
			->offset(3)
92
			->limit(5);
93
94
#		print_r($select->sql());
95
96
	}
97
*/
98
	#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...
99
100
	#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...
101
/*
102
	public function testCreate(){
103
104
		$create = $this->statement->create;
105
106
#		print_r($database->name('bar')->charset('utf8mb4_bin')->ifNotExists()->sql());
107
108
		$table = $create->table();
109
		$this->assertInstanceOf(CreateTableInterface::class, $table);
110
		$this->assertInstanceOf(StatementInterface::class, $table);
111
112
		$table
113
			->name('foo')
114
			->ifNotExists()
115
			->primaryKey('id')
116
			->field('id', 'int', 10, 'unsigned', null, false, null, null, 'AUTO_INCREMENT')
117
			->field('bar', 'varchar', 32, null, 'utf8mb4_bin', true, 'NULL', 'foo')
118
			->field('nope', 'decimal', '9,6');
119
120
#		print_r($table->sql());
121
	}
122
*/
123
}
124
125
126
/*
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...
127
128
		// get skills
129
		$sql = 'SELECT skilldata.`id`,
130
					skilldesc.`pve_name`,
131
					skilldesc.`pve_desc`,
132
					skilldesc.`pve_desc_short`,
133
					skilldesc.`pvp_name`,
134
					skilldesc.`pvp_desc`,
135
					skilldesc.`pvp_desc_short`,
136
					skilldata.`campaign` AS `campaign_id`,
137
					skilldata.`elite`,
138
					skilldata.`pve`,
139
					skilldata.`pvp_split`,
140
					skilldata.`attribute` AS `attribute_id`,
141
					skilldata.`'.$mode.'_activation` AS `activation`,
142
					skilldata.`'.$mode.'_recharge` AS `recharge`,
143
					skilldata.`'.$mode.'_energy` AS `energy`,
144
					skilldata.`'.$mode.'_upkeep` AS `upkeep`,
145
					skilldata.`'.$mode.'_adrenaline` AS `adrenaline`,
146
					skilldata.`'.$mode.'_sacrifice` AS `sacrifice`,
147
					skilldata.`'.$mode.'_overcast` AS `overcast`,
148
					skilldata.`'.$mode.'_type` AS `type_id`,
149
					profs.`name_'.$lang.'` AS `prof`,
150
					profs.`id` AS `prof_id`,
151
					profs.`abbr_'.$lang.'` AS `prof_abbr`,
152
					attribs.`name_'.$lang.'` AS `attribute`,
153
					attribs.`primary`,
154
					attribs.`max` AS `attribute_max`,
155
					types.`name_'.$lang.'` AS `type`,
156
					campaigns.`name_'.$lang.'` AS `campaign`
157
				FROM '.constant('SKILLDESC_'.strtoupper($lang)).' AS skilldesc,
158
					'.SKILLDATA.' AS skilldata,
159
					'.PROFESSIONS.' AS profs,
160
					'.ATTRIBUTES.' AS attribs,
161
					'.SKILLTYPES.' AS types,
162
					'.CAMPAIGNS.' AS campaigns
163
				WHERE skilldata.`profession` = profs.`id`
164
					AND skilldata.`attribute` = attribs.`id`
165
					AND skilldata.`'.$mode.'_type` = types.`id`
166
					AND skilldesc.`id` = skilldata.`id`
167
					AND campaigns.`id` = skilldata.`campaign`
168
					AND skilldata.`id` IN(?,?,?,?,?,?,?,?)';
169
170
171
172
 */