(test): verify empty object dependency chain

This commit is contained in:
Jake Barnby committed 2026-08-12 16:58:51 +12:00
1 parent c96d5de857
commit 74d9af5994
4 files changed
+71 -3

No files matched your search

+3
View File
@@ -25,6 +25,9 @@ jobs:
uses: docker/build-push-action@1104d471370f9806843c095c1db02b5a90c5f8b6 # v3.3.1
with:
context: .
build-args: |
UTOPIA_CACHE_REFERENCE=d7c0806f9bbdafee794849398f65e8ece322711d
UTOPIA_MONGO_REFERENCE=daea8f8213c33f52e8b66d0f5366428bf2f5a4b8
push: false
tags: ${{ env.IMAGE }}
load: true
+18 -1
View File
@@ -1,5 +1,8 @@
FROM composer:2.8 AS composer
ARG UTOPIA_CACHE_REFERENCE=''
ARG UTOPIA_MONGO_REFERENCE=''
WORKDIR /usr/local/src/
COPY composer.lock /usr/local/src/
@@ -10,7 +13,21 @@ RUN composer install \
--optimize-autoloader \
--no-plugins \
--no-scripts \
--prefer-dist
--prefer-dist \
&& if [ -n "$UTOPIA_CACHE_REFERENCE" ] || [ -n "$UTOPIA_MONGO_REFERENCE" ]; then \
test -n "$UTOPIA_CACHE_REFERENCE" \
&& test -n "$UTOPIA_MONGO_REFERENCE" \
&& git init /tmp/utopia-cache \
&& git -C /tmp/utopia-cache remote add origin https://github.com/utopia-php/monorepo.git \
&& git -C /tmp/utopia-cache fetch --depth 1 origin "$UTOPIA_CACHE_REFERENCE" \
&& git -C /tmp/utopia-cache checkout --detach FETCH_HEAD \
&& cp -R /tmp/utopia-cache/packages/cache/src/. vendor/utopia-php/cache/src/ \
&& git init /tmp/utopia-mongo \
&& git -C /tmp/utopia-mongo remote add origin https://github.com/utopia-php/mongo.git \
&& git -C /tmp/utopia-mongo fetch --depth 1 origin "$UTOPIA_MONGO_REFERENCE" \
&& git -C /tmp/utopia-mongo checkout --detach FETCH_HEAD \
&& cp -R /tmp/utopia-mongo/src/. vendor/utopia-php/mongo/src/; \
fi
FROM php:8.5.8-cli-alpine AS compile
+24 -1
View File
@@ -739,6 +739,29 @@ class Database
return $value;
}
private static function valuesEqual(mixed $value, mixed $old): bool
{
if ($value instanceof \stdClass && $old instanceof \stdClass) {
return self::valuesEqual((array)$value, (array)$old);
}
if (is_array($value) && is_array($old)) {
if (array_keys($value) !== array_keys($old)) {
return false;
}
foreach ($value as $key => $item) {
if (!self::valuesEqual($item, $old[$key])) {
return false;
}
}
return true;
}
return $value === $old;
}
/**
* Add listener to events
* Passing a null $callback will remove the listener
@@ -6385,7 +6408,7 @@ class Database
$oldValue = $old->getAttribute($key);
if ($value !== $oldValue) {
if (!self::valuesEqual($value, $oldValue)) {
$shouldUpdate = true;
break;
}
@@ -5,6 +5,7 @@ namespace Tests\E2E\Adapter\Scopes;
use Exception;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\Authorization as AuthorizationException;
use Utopia\Database\Exception\Duplicate as DuplicateException;
use Utopia\Database\Exception\Index as IndexException;
use Utopia\Database\Exception\Query as QueryException;
@@ -991,6 +992,21 @@ trait ObjectAttributeTests
$cached = $database->getDocument($collectionId, 'emptyObject');
$this->assertSame('{}', json_encode($cached->getAttribute('meta')));
$updated = $database->updateDocument($collectionId, 'emptyObject', new Document([
'meta' => new \stdClass(),
]));
$this->assertSame($cached->getUpdatedAt(), $updated->getUpdatedAt());
$this->assertSame('{}', json_encode($updated->getAttribute('meta')));
try {
$database->updateDocument($collectionId, 'emptyObject', new Document([
'meta' => [],
]));
$this->fail('Changing an empty object to an empty array must require update permission');
} catch (AuthorizationException) {
$this->addToAssertionCount(1);
}
$database->deleteCollection($collectionId);
}
@@ -1029,12 +1045,21 @@ trait ObjectAttributeTests
$this->assertSame('{"x":1}', json_encode($readMeta['arr'][1]));
$this->assertSame('[]', json_encode($readMeta['emptyArray']));
$cachedMeta = $database->getDocument($collectionId, 'nestedEmptyObjects')->getAttribute('meta');
$cached = $database->getDocument($collectionId, 'nestedEmptyObjects');
$cachedMeta = $cached->getAttribute('meta');
$this->assertSame('{}', json_encode($cachedMeta['inner']));
$this->assertSame('{}', json_encode($cachedMeta['arr'][0]));
$this->assertSame('{"x":1}', json_encode($cachedMeta['arr'][1]));
$this->assertSame('[]', json_encode($cachedMeta['emptyArray']));
$updatedMeta = $cachedMeta;
$updatedMeta['inner'] = new \stdClass();
$updatedMeta['arr'][0] = new \stdClass();
$updated = $database->updateDocument($collectionId, 'nestedEmptyObjects', new Document([
'meta' => $updatedMeta,
]));
$this->assertSame($cached->getUpdatedAt(), $updated->getUpdatedAt());
$database->deleteCollection($collectionId);
}