Skip to content

Commit 7557dba

Browse files
authored
some phpunit tests for ezSQL 2.17
1 parent a368137 commit 7557dba

File tree

10 files changed

+1940
-0
lines changed

10 files changed

+1940
-0
lines changed

tests/mssql/ezSQL_mssqlTest.php

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?php
2+
3+
require_once 'shared/ez_sql_core.php';
4+
5+
require 'vendor/autoload.php';
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* Test class for ezSQL_mssql.
10+
* Desc..: MS SQL Server component (part of ezSQL databse abstraction library)
11+
*
12+
* @author Justin Vincent ([email protected])
13+
* @author Stefanie Janine Stoelting <[email protected]>
14+
* @link http://twitter.com/justinvincent
15+
* @name ezSQL_mssqlTest
16+
* @package ezSQL
17+
* @subpackage unitTests
18+
* @license FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.)
19+
* @todo The connection to MS SQL Server is not tested by now. There might also
20+
* be tests done for different versions of SQL Server
21+
*
22+
*/
23+
class ezSQL_mssqlTest extends TestCase {
24+
25+
/**
26+
* @var ezSQL_mssql
27+
*/
28+
protected $object;
29+
30+
/**
31+
* Sets up the fixture, for example, opens a network connection.
32+
* This method is called before a test is executed.
33+
*/
34+
protected function setUp() {
35+
if (!extension_loaded('ntwdblib')) {
36+
$this->markTestSkipped(
37+
'The MS-SQL extenstion is not available.'
38+
);
39+
}
40+
require_once 'mssql/ez_sql_mssql.php';
41+
$this->object = new ezSQL_mssql;
42+
} // setUp
43+
44+
/**
45+
* Tears down the fixture, for example, closes a network connection.
46+
* This method is called after a test is executed.
47+
*/
48+
protected function tearDown() {
49+
$this->object = null;
50+
} // tearDown
51+
52+
/**
53+
* @covers ezSQL_mssql::quick_connect
54+
* @todo Implement testQuick_connect().
55+
*/
56+
public function testQuick_connect() {
57+
// Remove the following lines when you implement this test.
58+
$this->markTestIncomplete(
59+
'This test has not been implemented yet.'
60+
);
61+
} // testQuick_connect
62+
63+
/**
64+
* @covers ezSQL_mssql::connect
65+
* @todo Implement testConnect().
66+
*/
67+
public function testConnect() {
68+
// Remove the following lines when you implement this test.
69+
$this->markTestIncomplete(
70+
'This test has not been implemented yet.'
71+
);
72+
} // testConnect
73+
74+
/**
75+
* @covers ezSQL_mssql::select
76+
* @todo Implement testSelect().
77+
*/
78+
public function testSelect() {
79+
// Remove the following lines when you implement this test.
80+
$this->markTestIncomplete(
81+
'This test has not been implemented yet.'
82+
);
83+
} // testSelect
84+
85+
/**
86+
* @covers ezSQL_mssql::escape
87+
*/
88+
public function testEscape() {
89+
$result = $this->object->escape("This is'nt escaped.");
90+
91+
$this->assertEquals("This is''nt escaped.", $result);
92+
} // testEscape
93+
94+
/**
95+
* @covers ezSQL_mssql::sysdate
96+
*/
97+
public function testSysdate() {
98+
$this->assertEquals('getDate()', $this->object->sysdate());
99+
} // testSysdate
100+
101+
/**
102+
* @covers ezSQL_mssql::query
103+
* @todo Implement testQuery().
104+
*/
105+
public function testQuery() {
106+
// Remove the following lines when you implement this test.
107+
$this->markTestIncomplete(
108+
'This test has not been implemented yet.'
109+
);
110+
} // testQuery
111+
112+
/**
113+
* @covers ezSQL_mssql::ConvertMySqlToMSSql
114+
* @todo Implement testConvertMySqlToMSSql().
115+
*/
116+
public function testConvertMySqlToMSSql() {
117+
// Remove the following lines when you implement this test.
118+
$this->markTestIncomplete(
119+
'This test has not been implemented yet.'
120+
);
121+
} // testConvert
122+
123+
/**
124+
* @covers ezSQL_mssql::disconnect
125+
* @todo Implement testDisconnect().
126+
*/
127+
public function testDisconnect() {
128+
// Remove the following lines when you implement this test.
129+
$this->markTestIncomplete(
130+
'This test has not been implemented yet.'
131+
);
132+
} // testDisconnect
133+
134+
/**
135+
* @covers ezSQL_mssql::getDBHost
136+
* @todo Implement testGetDBHost().
137+
*/
138+
public function testGetDBHost() {
139+
// Remove the following lines when you implement this test.
140+
$this->markTestIncomplete(
141+
'This test has not been implemented yet.'
142+
);
143+
} // testGetDBHost
144+
145+
} // ezSQL_mssqlTest

tests/mysql/ezSQL_mysqlTest.php

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?php
2+
3+
require_once 'shared/ez_sql_core.php';
4+
5+
require 'vendor/autoload.php';
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* Test class for ezSQL_mysql.
10+
* Generated by PHPUnit
11+
*
12+
* Needs database tear up to run test, that creates database and a user with
13+
* appropriate rights.
14+
* Run database tear down after tests to get rid of the database and the user.
15+
*
16+
* @author Stefanie Janine Stoelting <[email protected]>
17+
* @name ezSQL_mysqlTest
18+
* @uses mysql_test_db_tear_up.sql
19+
* @uses mysql_test_db_tear_down.sql
20+
* @package ezSQL
21+
* @subpackage unitTests
22+
* @license FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.)
23+
*/
24+
class ezSQL_mysqlTest extends TestCase {
25+
26+
/**
27+
* constant string user name
28+
*/
29+
const TEST_DB_USER = 'ez_test';
30+
31+
/**
32+
* constant string password
33+
*/
34+
const TEST_DB_PASSWORD = 'ezTest';
35+
36+
/**
37+
* constant database name
38+
*/
39+
const TEST_DB_NAME = 'ez_test';
40+
41+
/**
42+
* constant database host
43+
*/
44+
const TEST_DB_HOST = 'localhost';
45+
46+
/**
47+
* constant database connection charset
48+
*/
49+
const TEST_DB_CHARSET = 'utf8';
50+
51+
/**
52+
* @var ezSQL_mysql
53+
*/
54+
protected $object;
55+
56+
/**
57+
* Sets up the fixture, for example, opens a network connection.
58+
* This method is called before a test is executed.
59+
*/
60+
protected function setUp() {
61+
if (!extension_loaded('mysql')) {
62+
$this->markTestSkipped(
63+
'The MySQL Lib is not available.'
64+
);
65+
}
66+
require_once 'mysql/ez_sql_mysql.php';
67+
$this->object = new ezSQL_mysql;
68+
}
69+
70+
/**
71+
* Tears down the fixture, for example, closes a network connection.
72+
* This method is called after a test is executed.
73+
*/
74+
protected function tearDown() {
75+
$this->object = null;
76+
}
77+
78+
/**
79+
* @covers ezSQL_mysql::quick_connect
80+
*/
81+
public function testQuick_connect() {
82+
$result = $this->object->quick_connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME);
83+
84+
$this->assertTrue($result);
85+
}
86+
87+
/**
88+
* @covers ezSQL_mysql::quick_connect
89+
*/
90+
public function testQuick_connect2() {
91+
$result = $this->object->quick_connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_CHARSET);
92+
93+
$this->assertTrue($result);
94+
}
95+
96+
/**
97+
* @covers ezSQL_mysql::connect
98+
*/
99+
public function testConnect() {
100+
$result = $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD);
101+
102+
$this->assertTrue($result);
103+
} // testConnect
104+
105+
/**
106+
* @covers ezSQL_mysql::select
107+
*/
108+
public function testSelect() {
109+
$this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD);
110+
$this->assertTrue($this->object->isConnected());
111+
112+
$result = $this->object->select(self::TEST_DB_NAME);
113+
114+
$this->assertTrue($result);
115+
} // testSelect
116+
117+
/**
118+
* @covers ezSQL_mysql::escape
119+
*/
120+
public function testEscape() {
121+
$result = $this->object->escape("This is'nt escaped.");
122+
123+
$this->assertEquals("This is\\'nt escaped.", $result);
124+
} // testEscape
125+
126+
/**
127+
* @covers ezSQL_mysql::sysdate
128+
*/
129+
public function testSysdate() {
130+
$this->assertEquals('NOW()', $this->object->sysdate());
131+
} // testSysdate
132+
133+
/**
134+
* @covers ezSQL_mysql::query
135+
*/
136+
public function testQueryInsert() {
137+
$this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD);
138+
139+
$this->object->select(self::TEST_DB_NAME);
140+
141+
$this->assertEquals($this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'), 0);
142+
$this->assertEquals($this->object->query('INSERT INTO unit_test(id, test_key) VALUES(1, \'test 1\')'), 1);
143+
$this->assertEquals($this->object->query('DROP TABLE unit_test'), 0);
144+
} // testQueryInsert
145+
146+
/**
147+
* @covers ezSQL_mysql::query
148+
*/
149+
public function testQuerySelect() {
150+
$this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD);
151+
152+
$this->object->select(self::TEST_DB_NAME);
153+
154+
$this->assertEquals($this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'), 0);
155+
156+
$this->assertEquals($this->object->query('INSERT INTO unit_test(id, test_key) VALUES(1, \'test 1\')'), 1);
157+
$this->assertEquals($this->object->query('INSERT INTO unit_test(id, test_key) VALUES(2, \'test 2\')'), 1);
158+
$this->assertEquals($this->object->query('INSERT INTO unit_test(id, test_key) VALUES(3, \'test 3\')'), 1);
159+
160+
$result = $this->object->query('SELECT * FROM unit_test');
161+
162+
$i = 1;
163+
foreach ($this->object->get_results() as $row) {
164+
$this->assertEquals($i, $row->id);
165+
$this->assertEquals('test ' . $i, $row->test_key);
166+
++$i;
167+
}
168+
169+
$this->assertEquals($this->object->query('DROP TABLE unit_test'), 0);
170+
} // testQuerySelect
171+
172+
/**
173+
* @covers ezSQL_mysql::getDBHost
174+
*/
175+
public function testGetDBHost() {
176+
$this->assertEquals(self::TEST_DB_HOST, $this->object->getDBHost());
177+
} // testGetDBHost
178+
179+
/**
180+
* @covers ezSQL_mysql::getCharset
181+
*/
182+
public function testGetCharset() {
183+
$this->assertEquals(self::TEST_DB_CHARSET, $this->object->getCharset());
184+
} // testGetCharset
185+
186+
/**
187+
* @covers ezSQL_mysql::disconnect
188+
*/
189+
public function testDisconnect() {
190+
$this->object->disconnect();
191+
192+
$this->assertTrue(true);
193+
} // testDisconnect
194+
195+
/**
196+
* @covers ezSQL_mysql::getInsertId
197+
*/
198+
public function testGetInsertId() {
199+
$this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD);
200+
201+
$this->object->select(self::TEST_DB_NAME);
202+
203+
$this->assertEquals($this->object->query('CREATE TABLE unit_test(id int(11) NOT NULL AUTO_INCREMENT, test_key varchar(50), PRIMARY KEY (ID))ENGINE=MyISAM DEFAULT CHARSET=utf8'), 0);
204+
$this->assertEquals($this->object->query('INSERT INTO unit_test(id, test_key) VALUES(1, \'test 1\')'), 1);
205+
206+
$this->assertEquals(1, $this->object->getInsertId($this->object->dbh));
207+
208+
$this->assertEquals($this->object->query('DROP TABLE unit_test'), 0);
209+
} // testInsertId
210+
211+
} // ezSQL_mysqlTest

0 commit comments

Comments
 (0)