From 25a12ed141f4bb2ffafa4dbfe63832a430b091c4 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 22 Jan 2025 17:53:22 +0200 Subject: [PATCH 1/3] getId returns string --- phpunit.xml | 2 +- tests/e2e/Adapter/Base.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index ccdaa969e..783265d80 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false"> + stopOnFailure="true"> ./tests/unit diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index e100ee69e..63d9f1ed1 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -3122,6 +3122,12 @@ public function testFind(): array $this->assertEquals(true, static::getDatabase()->createAttribute('movies', 'with-dash', Database::VAR_STRING, 128, true)); $this->assertEquals(true, static::getDatabase()->createAttribute('movies', 'nullable', Database::VAR_STRING, 128, false)); + $document = static::getDatabase()->createDocument('movies', new Document([ + '$id' => [ID::custom('frozen')], + ])); + + $this->assertEquals('dsdsdsd', 'dsdddd'); + $document = static::getDatabase()->createDocument('movies', new Document([ '$id' => ID::custom('frozen'), '$permissions' => [ From b3137930df90193ea1d9cea39a7da3db003f7aff Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 22 Jan 2025 18:21:44 +0200 Subject: [PATCH 2/3] Check Document types --- src/Database/Document.php | 7 ++++++- tests/e2e/Adapter/Base.php | 12 +++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Database/Document.php b/src/Database/Document.php index f605f615f..9d41f171b 100644 --- a/src/Database/Document.php +++ b/src/Database/Document.php @@ -4,6 +4,7 @@ use ArrayObject; use Utopia\Database\Exception as DatabaseException; +use Utopia\Database\Exception\Structure as StructureException; /** * @extends ArrayObject @@ -26,8 +27,12 @@ class Document extends ArrayObject */ public function __construct(array $input = []) { + if (isset($input['$id']) && !\is_string($input['$id'])) { + throw new StructureException('$id must be of type string'); + } + if (isset($input['$permissions']) && !is_array($input['$permissions'])) { - throw new DatabaseException('$permissions must be of type array'); + throw new StructureException('$permissions must be of type array'); } foreach ($input as $key => &$value) { diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index 63d9f1ed1..467410cc3 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -3122,11 +3122,13 @@ public function testFind(): array $this->assertEquals(true, static::getDatabase()->createAttribute('movies', 'with-dash', Database::VAR_STRING, 128, true)); $this->assertEquals(true, static::getDatabase()->createAttribute('movies', 'nullable', Database::VAR_STRING, 128, false)); - $document = static::getDatabase()->createDocument('movies', new Document([ - '$id' => [ID::custom('frozen')], - ])); - - $this->assertEquals('dsdsdsd', 'dsdddd'); + try { + static::getDatabase()->createDocument('movies', new Document(['$id' => ['id_as_array']])); + $this->fail('Failed to throw exception'); + } catch (Throwable $e) { + $this->assertEquals('$id must be of type string', $e->getMessage()); + $this->assertInstanceOf(StructureException::class, $e); + } $document = static::getDatabase()->createDocument('movies', new Document([ '$id' => ID::custom('frozen'), From 4aa3aac26b28309bcd338b8870c909e8838d3b94 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 22 Jan 2025 18:22:51 +0200 Subject: [PATCH 3/3] stopOnFailure --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 783265d80..ccdaa969e 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true"> + stopOnFailure="false"> ./tests/unit