mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
cleanup unused json queries and fix kmeans rng test
This commit is contained in:
parent
a91463d9bd
commit
0d1b8f5e65
File diff suppressed because it is too large
Load Diff
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
// where create sub array
|
||||
// order
|
||||
// select data from where
|
||||
// limit
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\DataStorage\File
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\DataStorage\File;
|
||||
|
||||
/**
|
||||
* Json query JsonGrammar.
|
||||
*
|
||||
* @package phpOMS\DataStorage\File
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class JsonGrammar
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\DataStorage\File
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\DataStorage\File;
|
||||
|
||||
use phpOMS\Stdlib\Base\Enum;
|
||||
|
||||
/**
|
||||
* Query type enum.
|
||||
*
|
||||
* @package phpOMS\DataStorage\File
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class QueryType extends Enum
|
||||
{
|
||||
public const SELECT = 0;
|
||||
public const INSERT = 1;
|
||||
public const UPDATE = 2;
|
||||
public const DELETE = 3;
|
||||
public const RANDOM = 4;
|
||||
}
|
||||
|
|
@ -41,13 +41,13 @@ class KmeansTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$kmeans = new Kmeans($points, 2);
|
||||
|
||||
if (0 === $kmeans->cluster($points[0])->getGroup()
|
||||
&& 0 === $kmeans->cluster($points[1])->getGroup()
|
||||
&& 1 === $kmeans->cluster($points[2])->getGroup()
|
||||
&& 1 === $kmeans->cluster($points[3])->getGroup()
|
||||
&& 1 === $kmeans->cluster($points[4])->getGroup()
|
||||
&& 1 === $kmeans->cluster($points[5])->getGroup()
|
||||
&& 1 === $kmeans->cluster($points[6])->getGroup()
|
||||
if ($kmeans->cluster($points[0])->getGroup() === 0
|
||||
&& $kmeans->cluster($points[1])->getGroup() === 0
|
||||
&& $kmeans->cluster($points[2])->getGroup() === 1
|
||||
&& $kmeans->cluster($points[3])->getGroup() === 1
|
||||
&& $kmeans->cluster($points[4])->getGroup() === 1
|
||||
&& $kmeans->cluster($points[5])->getGroup() === 1
|
||||
&& $kmeans->cluster($points[6])->getGroup() === 1
|
||||
) {
|
||||
$result = true;
|
||||
|
||||
|
|
@ -57,4 +57,4 @@ class KmeansTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
self::assertTrue($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,149 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\DataStorage\File;
|
||||
|
||||
use phpOMS\DataStorage\File\JsonBuilder;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class JsonBuilderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $table1 = [];
|
||||
private $table2 = [];
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->table1 = \json_decode(\file_get_contents(__DIR__ . '/testDb1.json'), true);
|
||||
$this->table2 = \json_decode(\file_get_contents(__DIR__ . '/testDb2.json'), true);
|
||||
}
|
||||
|
||||
public function testJsonSelect() : void
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
|
||||
$query = new JsonBuilder();
|
||||
self::assertEquals('acc1', $query->select('/0/account/*/name')->from($this->table1, $this->table2)->where('/0/account/*/id', '=', 1)->execute()['name']);
|
||||
self::assertEquals('acc6', $query->select('/1/account/*/name')->from($this->table1, $this->table2)->where('/1/account/*/id', '=', 2)->execute()['name']);
|
||||
|
||||
//$query = new JsonBuilder();
|
||||
//self::assertEquals($sql, $query->select('a.test')->distinct()->from('a')->where('a.test', '=', 1)->execute());
|
||||
|
||||
$query = new JsonBuilder();
|
||||
$datetime = new \DateTime('1999-31-12');
|
||||
self::assertEquals('dog2', $query->select('/0/animals/dog')->from($this->table2)->where('/0/animals/dog/created', '>', $datetime)->execute()['name']);
|
||||
|
||||
$table = $this->table2;
|
||||
$query = new JsonBuilder();
|
||||
self::assertEquals(['dog1', 'dog2', 'cat2'], $query->select('/0/animals/dog/*/name', function () {
|
||||
return '/0/animals/cat/*/name';
|
||||
})->from(function () use ($table) {
|
||||
return $table;
|
||||
})->where(['/0/animals/cat/*/owner', '/0/animals/dog/*/owner'], ['=', '='], [1, 4], ['and', 'or'])->execute());
|
||||
}
|
||||
|
||||
public function testJsonOrder() : void
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
|
||||
$query = new JsonBuilder();
|
||||
self::assertEquals(['acc2', 'acc1', 'acc4'],
|
||||
$query->select('/0/account/*/name')
|
||||
->from($this->table1)
|
||||
->where('/0/account/*/id', '>', 0)
|
||||
->orderBy('/0/account/status', 'ASC')
|
||||
->execute()
|
||||
);
|
||||
}
|
||||
|
||||
public function testJsonOffsetLimit() : void
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
|
||||
$query = new JsonBuilder();
|
||||
self::assertEquals(['acc2', 'acc1'],
|
||||
$query->select('/0/account/*/name')
|
||||
->from($this->table1)
|
||||
->where('/0/account/*/id', '>', 0)
|
||||
->orderBy('/0/account/status', 'ASC')
|
||||
->limit(2)
|
||||
->execute()
|
||||
);
|
||||
}
|
||||
|
||||
public function testReadOnlyInsert() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
||||
$query = new JsonBuilder(true);
|
||||
$query->insert('test');
|
||||
}
|
||||
|
||||
public function testReadOnlyUpdate() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
||||
$query = new JsonBuilder(true);
|
||||
$query->update();
|
||||
}
|
||||
|
||||
public function testReadOnlyDelete() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
||||
$query = new JsonBuilder(true);
|
||||
$query->delete();
|
||||
}
|
||||
|
||||
public function testInvalidWhereOperator() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
||||
$query = new JsonBuilder(true);
|
||||
$query->where('a', 'invalid', 'b');
|
||||
}
|
||||
|
||||
public function testInvalidJoinTable() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
||||
$query = new JsonBuilder(true);
|
||||
$query->join(null);
|
||||
}
|
||||
|
||||
public function testInvalidJoinOperator() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
||||
$query = new JsonBuilder(true);
|
||||
$query->join('b')->on('a', 'invalid', 'b');
|
||||
}
|
||||
|
||||
public function testInvalidOrOrderType() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
||||
$query = new JsonBuilder(true);
|
||||
$query->orderBy('a', 1);
|
||||
}
|
||||
|
||||
public function testInvalidOrColumnType() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
||||
$query = new JsonBuilder(true);
|
||||
$query->orderBy(null, 'DESC');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
{
|
||||
"account": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "acc1",
|
||||
"status": 2
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "acc2",
|
||||
"status": 1
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "acc4",
|
||||
"status": 2
|
||||
}
|
||||
],
|
||||
"news": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "news1",
|
||||
"by": 2
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "news2",
|
||||
"by": 4
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "news4",
|
||||
"by": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
{
|
||||
"account": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "acc5",
|
||||
"status": 2
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "acc6",
|
||||
"status": 1
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "acc7",
|
||||
"status": 2
|
||||
}
|
||||
],
|
||||
"animals": {
|
||||
"dog": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "dog1",
|
||||
"owner": 4,
|
||||
"created": "1999-01-01"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "dog2",
|
||||
"owner": 1,
|
||||
"created": "2000-01-01"
|
||||
}
|
||||
],
|
||||
"cat": {
|
||||
"1": {
|
||||
"id": 1,
|
||||
"name": "cat1",
|
||||
"owner": 2
|
||||
},
|
||||
"2": {
|
||||
"id": 2,
|
||||
"name": "cat2",
|
||||
"owner": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user