Skip to content

Commit

Permalink
[feature] Medoo test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelaon committed Mar 30, 2021
1 parent 93827c2 commit 4b12be6
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,10 @@ pip-log.txt
.mr.developer.cfg

#php-cs-fixer
/.php_cs
/.php_cs

#PHPUnit
/.phpunit.cache

/composer.lock
/vendor
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"php": ">=5.4",
"ext-pdo": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"suggest": {
"ext-pdo_mysql": "For MySQL or MariaDB database",
"ext-pdo_sqlsrv": "For MSSQL database on both Window/Liunx platform",
Expand All @@ -27,7 +30,15 @@
},
"autoload": {
"psr-4": {
"Medoo\\": "/src"
"Medoo\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Medoo\\Tests\\": "tests/"
}
},
"scripts": {
"test": "phpunit"
}
}
22 changes: 22 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="Medoo Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
62 changes: 62 additions & 0 deletions tests/MedooTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Medoo\Tests;

use Medoo\Medoo;
use PHPUnit\Framework\TestCase;

class MedooTestCase extends TestCase
{
protected Medoo $database;

public function setUp() : void
{
$this->database = new Medoo([
'testMode' => true
]);
}

public function typesProvider(): array
{
return [
'MySQL' => ['mysql'],
'MSSQL' => ['mssql'],
'SQLite' => ['sqlite'],
'PostgreSQL' => ['pgsql'],
'Oracle' => ['oracle']
];
}

public function setType($type) : void
{
$this->database->type = $type;
}

public function expectedQuery($expected) : string
{
$identifier = [
'mysql' => '`$1`',
'mssql' => '[$1]'
];

return preg_replace(
'/"((?![_\d])[\p{N}\p{L}_]+)"/u',
$identifier[$this->database->type] ?? '"$1"',
$expected
);
}

public function assertQuery($expected, $query) : void
{
if (is_array($expected)) {

$this->assertEquals(
$this->expectedQuery($expected[$this->database->type] ?? $expected['default']),
$query
);
}
else {
$this->assertEquals($this->expectedQuery($expected), $query);
}
}
}

0 comments on commit 4b12be6

Please sign in to comment.