reorganizing tests
This commit is contained in:
parent
068a89d451
commit
03826b87d6
8 changed files with 12 additions and 89 deletions
|
@ -16,6 +16,6 @@ test:local:
|
|||
# - docker-php-ext-install pdo_mysql
|
||||
# - php composer.phar test-db
|
||||
|
||||
test:legacydb:
|
||||
test:sqlite:
|
||||
script:
|
||||
- php composer.phar test-legacydb
|
||||
- php composer.phar test-sqlite
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
"test-db": [
|
||||
"phpunit --testsuite DB"
|
||||
],
|
||||
"test-legacydb": [
|
||||
"phpunit --testsuite LegacyDB"
|
||||
"test-sqlite": [
|
||||
"phpunit --testsuite SQLite"
|
||||
]
|
||||
},
|
||||
"autoload": {
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
<exclude>tests/Drivers</exclude>
|
||||
<exclude>tests/LegacyDrivers</exclude>
|
||||
</testsuite>
|
||||
<testsuite name="DB">
|
||||
<testsuite name="Drivers">
|
||||
<directory>tests/Drivers</directory>
|
||||
</testsuite>
|
||||
<testsuite name="LegacyDB">
|
||||
<directory>tests/LegacyDrivers</directory>
|
||||
<testsuite name="SQLite">
|
||||
<directory>tests/LegacyDrivers/SQLite</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
/* Destructr | https://gitlab.com/byjoby/destructr | MIT License */
|
||||
namespace Destructr\LegacyDrivers;
|
||||
|
||||
/**
|
||||
* What this driver supports: MySQL 5.6, as long as you have permissions to
|
||||
* create user-defined functions
|
||||
*
|
||||
* Also, this driver does flatten its JSON data, so complex unstructured data
|
||||
* will not be straight compatible with modern drivers. You'll need to run a
|
||||
* migration tool to unflatten and resave everything.
|
||||
*
|
||||
* Complex queries on JSON fields will almost certainly fail in edge cases.
|
||||
* This should work for most basic uses though.
|
||||
*/
|
||||
class MySQL56Driver extends AbstractLegacyDriver
|
||||
{
|
||||
public function createTable(string $table, array $virtualColumns) : bool
|
||||
{
|
||||
$this->createLegacyUDF();
|
||||
return parent::createTable($table, $virtualColumns);
|
||||
}
|
||||
|
||||
public function createLegacyUDF()
|
||||
{
|
||||
$drop = $this->pdo->exec('DROP FUNCTION IF EXISTS `destructr_json_extract`;');
|
||||
$create = $this->pdo->exec(file_get_contents(__DIR__.'/destructr_json_extract.sql'));
|
||||
}
|
||||
|
||||
protected function expandPath(string $path) : string
|
||||
{
|
||||
$path = str_replace('.', '|', $path);
|
||||
return "destructr_json_extract(`json_data`,'$.{$path}')";
|
||||
}
|
||||
}
|
|
@ -41,19 +41,5 @@ using SQLite if you don't have access to a fully supported database version.
|
|||
|
||||
### MySQL 5.6
|
||||
|
||||
**\Destructr\LegacyDrivers\MySQL56Driver**
|
||||
|
||||
**Overall support level: Decent performance, highly suspect accuracy**
|
||||
|
||||
LegacyDrivers\MySQL56Driver provides bare-minimum support for MySQL < 5.7.
|
||||
This driver now passes the basic tests and basic integration tests, but hasn't
|
||||
been verified in the slightest beyond that.
|
||||
|
||||
It flattens unstructured JSON and uses a highly dodgy user-defined function to
|
||||
extract values from it. There are absolutely edge cases that will extract the
|
||||
wrong data. That said, outside of those edge cases it should actually work
|
||||
fairly well. All the sorting and filtering is happening in SQL, and things
|
||||
should mostly be fairly predictable.
|
||||
|
||||
This driver should be your last resort. I cannot emphasize enough that this
|
||||
thing is extremely kludgey and should not be trusted.
|
||||
** No longer supported. You should really use SQLite if you don't have access to
|
||||
something better. Will most likely never be supported. **
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
CREATE FUNCTION `destructr_json_extract`(
|
||||
details TEXT,
|
||||
required_field VARCHAR (255)
|
||||
) RETURNS TEXT CHARSET utf8
|
||||
BEGIN
|
||||
DECLARE search_term TEXT;
|
||||
SET details = SUBSTRING_INDEX(details, "{", -1);
|
||||
SET details = SUBSTRING_INDEX(details, "}", 1);
|
||||
SET search_term = CONCAT('"', SUBSTRING_INDEX(required_field,'$.', - 1), '"');
|
||||
IF INSTR(details, search_term) > 0 THEN
|
||||
RETURN TRIM(
|
||||
BOTH '"' FROM SUBSTRING_INDEX(
|
||||
SUBSTRING_INDEX(
|
||||
SUBSTRING_INDEX(
|
||||
details,
|
||||
search_term,
|
||||
- 1
|
||||
),
|
||||
',"',
|
||||
1
|
||||
),
|
||||
':',
|
||||
-1
|
||||
)
|
||||
);
|
||||
ELSE
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
END;
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/* Destructr | https://gitlab.com/byjoby/destructr | MIT License */
|
||||
declare(strict_types=1);
|
||||
namespace Destructr\LegacyDrivers\IntegrationTests;
|
||||
namespace Destructr\LegacyDrivers\SQLite;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Destructr\Drivers\IntegrationTests\AbstractDriverIntegrationTest;
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
/* Destructr | https://gitlab.com/byjoby/destructr | MIT License */
|
||||
declare(strict_types=1);
|
||||
namespace Destructr\LegacyDrivers;
|
||||
namespace Destructr\LegacyDrivers\SQLite;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Destructr\Drivers\AbstractDriverTest;
|
||||
use Destructr\LegacyDrivers\SQLiteDriver;
|
||||
|
||||
class SQLiteDriverTest extends AbstractDriverTest
|
||||
{
|
Loading…
Reference in a new issue