Skip to content

Commit 7228a4a

Browse files
committed
#14 - Test Database class
1 parent 652b8fa commit 7228a4a

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/TgDatabase/DatabaseTest.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace TgDatabase;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use TgUtils\Date;
7+
8+
/**
9+
* Tests the Database class.
10+
* @author ralph
11+
*
12+
*/
13+
final class DatabaseTest extends TestCase {
14+
15+
public function testQuote(): void {
16+
$database = TestHelper::getDatabase();
17+
if ($database != NULL) {
18+
$this->assertEquals('\'aString\'', $database->quote('aString'));
19+
}
20+
}
21+
22+
public function testQuoteName(): void {
23+
$database = TestHelper::getDatabase();
24+
if ($database != NULL) {
25+
$this->assertEquals('`aString`', $database->quoteName('aString'));
26+
}
27+
}
28+
29+
public function testPrepareValueString(): void {
30+
$database = TestHelper::getDatabase();
31+
if ($database != NULL) {
32+
$this->assertEquals('\'aString\'', $database->prepareValue('aString'));
33+
}
34+
}
35+
36+
public function testPrepareValueInt(): void {
37+
$database = TestHelper::getDatabase();
38+
if ($database != NULL) {
39+
$this->assertEquals(12, $database->prepareValue(12));
40+
}
41+
}
42+
43+
public function testPrepareValueFloat(): void {
44+
$database = TestHelper::getDatabase();
45+
if ($database != NULL) {
46+
$this->assertEquals(12.3, $database->prepareValue(12.3));
47+
}
48+
}
49+
50+
public function testPrepareValueDate(): void {
51+
$database = TestHelper::getDatabase();
52+
if ($database != NULL) {
53+
$this->assertEquals('\'1970-01-01 00:00:00\'', $database->prepareValue(new Date(0, 'UTC')));
54+
}
55+
}
56+
57+
public function testPrepareValueObject(): void {
58+
$database = TestHelper::getDatabase();
59+
if ($database != NULL) {
60+
$obj = new \stdClass;
61+
$obj->attr = 'value';
62+
$this->assertEquals('\'{\\"attr\\":\\"value\\"}\'', $database->prepareValue($obj));
63+
}
64+
}
65+
66+
public function testReplaceTablePrefix(): void {
67+
$database = TestHelper::getDatabase();
68+
if ($database != NULL) {
69+
$this->assertEquals('phpunittest_table', $database->replaceTablePrefix('#__table'));
70+
}
71+
}
72+
73+
}

0 commit comments

Comments
 (0)