Skip to content

Commit 4f02d63

Browse files
committed
(test): Add array index schema and query tests, update expectations for NOT NULL arrays
1 parent f76a0de commit 4f02d63

17 files changed

Lines changed: 222 additions & 5 deletions

tests/e2e/Adapter/Base.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ abstract class Base extends TestCase
4949
*/
5050
abstract protected function getDatabase(): Database;
5151

52+
/**
53+
* @return \Utopia\Database\PDO|\PDO|null
54+
*/
55+
abstract protected function getPDO(): mixed;
56+
5257
/**
5358
* @param string $collection
5459
* @param string $column

tests/e2e/Adapter/MariaDBTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public function getDatabase(bool $fresh = false): Database
5252
return self::$database = $database;
5353
}
5454

55+
protected function getPDO(): mixed
56+
{
57+
return self::$pdo;
58+
}
59+
5560
protected function deleteColumn(string $collection, string $column): bool
5661
{
5762
$sqlTable = "`" . $this->getDatabase()->getDatabase() . "`.`" . $this->getDatabase()->getNamespace() . "_" . $collection . "`";

tests/e2e/Adapter/MirrorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ public function testDeleteMirroredDocument(): void
313313
$this->assertTrue($database->getDestination()->getDocument('testDeleteMirroredDocument', $document->getId())->isEmpty());
314314
}
315315

316+
protected function getPDO(): mixed
317+
{
318+
return self::$sourcePdo;
319+
}
320+
316321
protected function deleteColumn(string $collection, string $column): bool
317322
{
318323
$sqlTable = "`" . self::$source->getDatabase() . "`.`" . self::$source->getNamespace() . "_" . $collection . "`";

tests/e2e/Adapter/MongoDBTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public function testKeywords(): void
9898
$this->assertTrue(true);
9999
}
100100

101+
protected function getPDO(): mixed
102+
{
103+
return null;
104+
}
105+
101106
protected function deleteColumn(string $collection, string $column): bool
102107
{
103108
return true;

tests/e2e/Adapter/MySQLTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function getDatabase(): Database
5858
return self::$database = $database;
5959
}
6060

61+
protected function getPDO(): mixed
62+
{
63+
return self::$pdo;
64+
}
65+
6166
protected function deleteColumn(string $collection, string $column): bool
6267
{
6368
$sqlTable = "`" . $this->getDatabase()->getDatabase() . "`.`" . $this->getDatabase()->getNamespace() . "_" . $collection . "`";

tests/e2e/Adapter/PoolTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ public function getDatabase(): Database
7979
return self::$database = $database;
8080
}
8181

82+
protected function getPDO(): mixed
83+
{
84+
$pdo = null;
85+
self::$pool->use(function (Adapter $adapter) use (&$pdo) {
86+
$class = new ReflectionClass($adapter);
87+
$property = $class->getProperty('pdo');
88+
$property->setAccessible(true);
89+
$pdo = $property->getValue($adapter);
90+
});
91+
return $pdo;
92+
}
93+
8294
protected function deleteColumn(string $collection, string $column): bool
8395
{
8496
$sqlTable = "`" . $this->getDatabase()->getDatabase() . "`.`" . $this->getDatabase()->getNamespace() . "_" . $collection . "`";

tests/e2e/Adapter/PostgresTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function getDatabase(): Database
5151
return self::$database = $database;
5252
}
5353

54+
protected function getPDO(): mixed
55+
{
56+
return self::$pdo;
57+
}
58+
5459
protected function deleteColumn(string $collection, string $column): bool
5560
{
5661
$sqlTable = '"' . $this->getDatabase()->getDatabase(). '"."' . $this->getDatabase()->getNamespace() . '_' . $collection . '"';

tests/e2e/Adapter/SQLiteTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public function getDatabase(): Database
5555
return self::$database = $database;
5656
}
5757

58+
protected function getPDO(): mixed
59+
{
60+
return self::$pdo;
61+
}
62+
5863
protected function deleteColumn(string $collection, string $column): bool
5964
{
6065
$sqlTable = "`" . $this->getDatabase()->getNamespace() . "_" . $collection . "`";

tests/e2e/Adapter/Scopes/AttributeTests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,10 +1620,11 @@ public function testArrayAttribute(): void
16201620
$this->assertEquals('Invalid query: Cannot query contains on attribute "age" because it is not an array, string, or object.', $e->getMessage());
16211621
}
16221622

1623+
// Array columns are NOT NULL with DEFAULT empty array, so isNull returns nothing
16231624
$documents = $database->find($collection, [
16241625
Query::isNull('long_size')
16251626
]);
1626-
$this->assertCount(1, $documents);
1627+
$this->assertCount(0, $documents);
16271628

16281629
$documents = $database->find($collection, [
16291630
Query::contains('tv_show', ['love'])

tests/e2e/Adapter/Scopes/CollectionTests.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,10 @@ public function testSchemaAttributes(): void
569569

570570
$attribute = $attributes['string_list'];
571571
$this->assertEquals('string_list', $attribute['$id']);
572-
$this->assertTrue(in_array($attribute['dataType'], ['json', 'longtext'])); // mysql vs maria
573-
$this->assertTrue(in_array($attribute['columnType'], ['json', 'longtext']));
572+
$this->assertTrue(in_array($attribute['dataType'], ['json', 'jsonb', 'longtext']));
573+
$this->assertTrue(in_array($attribute['columnType'], ['json', 'jsonb', 'longtext']));
574574
$this->assertTrue(in_array($attribute['characterMaximumLength'], [null, '4294967295']));
575-
$this->assertEquals('YES', $attribute['isNullable']);
575+
$this->assertEquals('NO', $attribute['isNullable']);
576576

577577
$attribute = $attributes['dob'];
578578
$this->assertEquals('dob', $attribute['$id']);

0 commit comments

Comments
 (0)