Skip to content

Commit

Permalink
Order tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fogelito committed Jan 4, 2024
1 parent cc22abd commit 9846af4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
10 changes: 4 additions & 6 deletions src/Database/Validator/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ public function checkArrayIndex(Document $index): bool
$arrayAttributes = [];
foreach ($attributes as $key => $attribute) {
$attribute = $this->attributes[\strtolower($attribute)] ?? new Document();
var_dump($attribute);

if($attribute->getAttribute('array') === true){
// Database::INDEX_UNIQUE Is not allowed! since mariaDB VS MySQL makes the unique Different on values
if(!in_array($index->getAttribute('type'), [Database::INDEX_ARRAY, Database::INDEX_KEY])){
$this->message = 'Invalid "' . ucfirst($index->getAttribute('type')) . '" index on array attributes';
$this->message = ucfirst($index->getAttribute('type')) . '" index is forbidden on array attributes';
return false;
}

var_dump($attribute);
$arrayAttributes[] = $attribute->getAttribute('key', '');
if(count($arrayAttributes) > 1){
$this->message = 'Only a single index can be created on array attributes found "' . implode(',', $arrayAttributes) . '"';
Expand Down Expand Up @@ -173,24 +174,21 @@ public function checkIndexLength(Document $index): bool
}

if(!$isArray && $attribute->getAttribute('type') !== Database::VAR_STRING && !empty($lengths[$attributePosition])){
$this->message = 'Key part length are forbidden on "' . $attribute->getAttribute('type') . '" data-type';
$this->message = 'Key part length are forbidden on "' . $attribute->getAttribute('type') . '" data-type for "' . $attributeName . '"';
return false;
}

switch ($attribute->getAttribute('type')) {
case Database::VAR_STRING:
$attributeSize = $attribute->getAttribute('size', 0);
$indexLength = $lengths[$attributePosition] ?? $attributeSize;
var_dump($attributeName);
var_dump($indexLength);
break;
case Database::VAR_FLOAT:
$attributeSize = 2; // 8 bytes / 4 mb4
$indexLength = 2;
break;
default:
$attributeSize = 1; // 4 bytes / 4 mb4
// $attributeSize = $attribute->getAttribute('size', 1); // 4 bytes / 4 mb4
$indexLength = 1;
break;
}
Expand Down
20 changes: 4 additions & 16 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -1673,16 +1673,6 @@ public function testArrayAttribute(): void
$this->assertEquals('Invalid document structure: Attribute "age" has invalid type. Value must be a valid integer', $e->getMessage());
}

try {
static::getDatabase()->createDocument($collection, new Document([
'booleans' => [false],
'age' => -1,
]));
$this->fail('Failed to throw exception');
} catch(Throwable $e) {
//$this->assertEquals('Should fail since it is Signed = false!!!!', $e->getMessage());
}

static::getDatabase()->createDocument($collection, new Document([
'$id' => 'joe',
'$permissions' => $permissions,
Expand All @@ -1701,7 +1691,7 @@ public function testArrayAttribute(): void
static::getDatabase()->createIndex($collection, 'indx', Database::INDEX_FULLTEXT, ['names']);
$this->fail('Failed to throw exception');
} catch(Throwable $e) {
$this->assertEquals('Invalid "Fulltext" index on array attributes', $e->getMessage());
$this->assertEquals('Fulltext" index is forbidden on array attributes', $e->getMessage());
}

try {
Expand Down Expand Up @@ -1753,17 +1743,17 @@ public function testArrayAttribute(): void
static::getDatabase()->createIndex($collection, 'indx', Database::INDEX_KEY, ['age', 'names'], [10, 255], []);
$this->fail('Failed to throw exception');
} catch(Throwable $e) {
$this->assertEquals('Key part length are forbidden on "integer" data-type', $e->getMessage());
$this->assertEquals('Key part length are forbidden on "integer" data-type for "age"', $e->getMessage());
}

$this->assertTrue(static::getDatabase()->createIndex($collection, 'indx_names', Database::INDEX_KEY, ['names'], [255], []));
$this->assertTrue(static::getDatabase()->createIndex($collection, 'indx_age_names1', Database::INDEX_KEY, ['age', 'names'], [null, 255], []));
$this->assertTrue(static::getDatabase()->createIndex($collection, 'indx_age_names2', Database::INDEX_KEY, ['age', 'booleans'], [0, 255], []));
// $this->assertTrue(static::getDatabase()->createIndex($collection, 'indx_age_names', Database::INDEX_ARRAY, ['age', 'names'], [255, 255], []));


$this->assertEquals(true,false);
$this->assertTrue(static::getDatabase()->createIndex($collection, 'test', Database::INDEX_ARRAY, ['names'], [255], []));

$this->assertEquals(true,false);


if ($this->getDatabase()->getAdapter()->getSupportForQueryContains()) {
Expand All @@ -1777,7 +1767,6 @@ public function testArrayAttribute(): void
]);
$this->assertCount(1, $documents);


$documents = static::getDatabase()->find($collection, [
Query::contains('active', [false])
]);
Expand All @@ -1787,7 +1776,6 @@ public function testArrayAttribute(): void
}

$this->assertEquals(true,false);

}

/**
Expand Down

0 comments on commit 9846af4

Please sign in to comment.