Skip to content

Commit 4b12be6

Browse files
committed
[feature] Medoo test case
1 parent 93827c2 commit 4b12be6

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,10 @@ pip-log.txt
216216
.mr.developer.cfg
217217

218218
#php-cs-fixer
219-
/.php_cs
219+
/.php_cs
220+
221+
#PHPUnit
222+
/.phpunit.cache
223+
224+
/composer.lock
225+
/vendor

composer.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"php": ">=5.4",
1717
"ext-pdo": "*"
1818
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^9.0"
21+
},
1922
"suggest": {
2023
"ext-pdo_mysql": "For MySQL or MariaDB database",
2124
"ext-pdo_sqlsrv": "For MSSQL database on both Window/Liunx platform",
@@ -27,7 +30,15 @@
2730
},
2831
"autoload": {
2932
"psr-4": {
30-
"Medoo\\": "/src"
33+
"Medoo\\": "src/"
3134
}
35+
},
36+
"autoload-dev": {
37+
"psr-4": {
38+
"Medoo\\Tests\\": "tests/"
39+
}
40+
},
41+
"scripts": {
42+
"test": "phpunit"
3243
}
3344
}

phpunit.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheResultFile=".phpunit.cache/test-results"
6+
executionOrder="depends,defects"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
verbose="true">
10+
<testsuites>
11+
<testsuite name="Medoo Test Suite">
12+
<directory suffix="Test.php">./tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
16+
<coverage cacheDirectory=".phpunit.cache/code-coverage"
17+
processUncoveredFiles="true">
18+
<include>
19+
<directory suffix=".php">src</directory>
20+
</include>
21+
</coverage>
22+
</phpunit>

tests/MedooTestCase.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Medoo\Tests;
4+
5+
use Medoo\Medoo;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class MedooTestCase extends TestCase
9+
{
10+
protected Medoo $database;
11+
12+
public function setUp() : void
13+
{
14+
$this->database = new Medoo([
15+
'testMode' => true
16+
]);
17+
}
18+
19+
public function typesProvider(): array
20+
{
21+
return [
22+
'MySQL' => ['mysql'],
23+
'MSSQL' => ['mssql'],
24+
'SQLite' => ['sqlite'],
25+
'PostgreSQL' => ['pgsql'],
26+
'Oracle' => ['oracle']
27+
];
28+
}
29+
30+
public function setType($type) : void
31+
{
32+
$this->database->type = $type;
33+
}
34+
35+
public function expectedQuery($expected) : string
36+
{
37+
$identifier = [
38+
'mysql' => '`$1`',
39+
'mssql' => '[$1]'
40+
];
41+
42+
return preg_replace(
43+
'/"((?![_\d])[\p{N}\p{L}_]+)"/u',
44+
$identifier[$this->database->type] ?? '"$1"',
45+
$expected
46+
);
47+
}
48+
49+
public function assertQuery($expected, $query) : void
50+
{
51+
if (is_array($expected)) {
52+
53+
$this->assertEquals(
54+
$this->expectedQuery($expected[$this->database->type] ?? $expected['default']),
55+
$query
56+
);
57+
}
58+
else {
59+
$this->assertEquals($this->expectedQuery($expected), $query);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)