Skip to content

Commit 8d235cd

Browse files
abnegateclaude
andcommitted
fix: resolve test failures for CacheKey, ORM entities, and Collection constants
- Fix CacheKeyTest to use Capability enum instead of removed getSupportForHostname method, restore filter-aware cache key logic - Extract ORM test entities into separate files for PSR-4 autoloading - Replace removed Database::VAR_*, EVENT_*, INDEX_* constants with ColumnType/Event/IndexType enums and new Attribute/Index constructors - Update PHPStan baseline Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d21d4ce commit 8d235cd

10 files changed

Lines changed: 230 additions & 334 deletions

phpstan-baseline.neon

Lines changed: 16 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -444,180 +444,6 @@ parameters:
444444
count: 1
445445
path: src/Database/Validator/Sequence.php
446446

447-
-
448-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_ALL\.$#'
449-
identifier: classConstant.notFound
450-
count: 4
451-
path: tests/e2e/Adapter/Base.php
452-
453-
-
454-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_ATTRIBUTE_CREATE\.$#'
455-
identifier: classConstant.notFound
456-
count: 1
457-
path: tests/e2e/Adapter/Base.php
458-
459-
-
460-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_ATTRIBUTE_DELETE\.$#'
461-
identifier: classConstant.notFound
462-
count: 2
463-
path: tests/e2e/Adapter/Base.php
464-
465-
-
466-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_ATTRIBUTE_UPDATE\.$#'
467-
identifier: classConstant.notFound
468-
count: 1
469-
path: tests/e2e/Adapter/Base.php
470-
471-
-
472-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_COLLECTION_CREATE\.$#'
473-
identifier: classConstant.notFound
474-
count: 1
475-
path: tests/e2e/Adapter/Base.php
476-
477-
-
478-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_COLLECTION_DELETE\.$#'
479-
identifier: classConstant.notFound
480-
count: 2
481-
path: tests/e2e/Adapter/Base.php
482-
483-
-
484-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_COLLECTION_LIST\.$#'
485-
identifier: classConstant.notFound
486-
count: 1
487-
path: tests/e2e/Adapter/Base.php
488-
489-
-
490-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_COLLECTION_READ\.$#'
491-
identifier: classConstant.notFound
492-
count: 1
493-
path: tests/e2e/Adapter/Base.php
494-
495-
-
496-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DATABASE_CREATE\.$#'
497-
identifier: classConstant.notFound
498-
count: 1
499-
path: tests/e2e/Adapter/Base.php
500-
501-
-
502-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DATABASE_DELETE\.$#'
503-
identifier: classConstant.notFound
504-
count: 2
505-
path: tests/e2e/Adapter/Base.php
506-
507-
-
508-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DATABASE_LIST\.$#'
509-
identifier: classConstant.notFound
510-
count: 1
511-
path: tests/e2e/Adapter/Base.php
512-
513-
-
514-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENTS_CREATE\.$#'
515-
identifier: classConstant.notFound
516-
count: 1
517-
path: tests/e2e/Adapter/Base.php
518-
519-
-
520-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENTS_DELETE\.$#'
521-
identifier: classConstant.notFound
522-
count: 2
523-
path: tests/e2e/Adapter/Base.php
524-
525-
-
526-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENTS_UPDATE\.$#'
527-
identifier: classConstant.notFound
528-
count: 1
529-
path: tests/e2e/Adapter/Base.php
530-
531-
-
532-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_COUNT\.$#'
533-
identifier: classConstant.notFound
534-
count: 1
535-
path: tests/e2e/Adapter/Base.php
536-
537-
-
538-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_CREATE\.$#'
539-
identifier: classConstant.notFound
540-
count: 1
541-
path: tests/e2e/Adapter/Base.php
542-
543-
-
544-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_DECREASE\.$#'
545-
identifier: classConstant.notFound
546-
count: 1
547-
path: tests/e2e/Adapter/Base.php
548-
549-
-
550-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_DELETE\.$#'
551-
identifier: classConstant.notFound
552-
count: 1
553-
path: tests/e2e/Adapter/Base.php
554-
555-
-
556-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_FIND\.$#'
557-
identifier: classConstant.notFound
558-
count: 2
559-
path: tests/e2e/Adapter/Base.php
560-
561-
-
562-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_INCREASE\.$#'
563-
identifier: classConstant.notFound
564-
count: 1
565-
path: tests/e2e/Adapter/Base.php
566-
567-
-
568-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_PURGE\.$#'
569-
identifier: classConstant.notFound
570-
count: 13
571-
path: tests/e2e/Adapter/Base.php
572-
573-
-
574-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_READ\.$#'
575-
identifier: classConstant.notFound
576-
count: 2
577-
path: tests/e2e/Adapter/Base.php
578-
579-
-
580-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_SUM\.$#'
581-
identifier: classConstant.notFound
582-
count: 1
583-
path: tests/e2e/Adapter/Base.php
584-
585-
-
586-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_DOCUMENT_UPDATE\.$#'
587-
identifier: classConstant.notFound
588-
count: 1
589-
path: tests/e2e/Adapter/Base.php
590-
591-
-
592-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_INDEX_CREATE\.$#'
593-
identifier: classConstant.notFound
594-
count: 1
595-
path: tests/e2e/Adapter/Base.php
596-
597-
-
598-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:EVENT_INDEX_DELETE\.$#'
599-
identifier: classConstant.notFound
600-
count: 1
601-
path: tests/e2e/Adapter/Base.php
602-
603-
-
604-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:INDEX_KEY\.$#'
605-
identifier: classConstant.notFound
606-
count: 1
607-
path: tests/e2e/Adapter/Base.php
608-
609-
-
610-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:VAR_INTEGER\.$#'
611-
identifier: classConstant.notFound
612-
count: 1
613-
path: tests/e2e/Adapter/Base.php
614-
615-
-
616-
message: '#^Access to undefined constant Utopia\\Database\\Database\:\:VAR_STRING\.$#'
617-
identifier: classConstant.notFound
618-
count: 4
619-
path: tests/e2e/Adapter/Base.php
620-
621447
-
622448
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
623449
identifier: foreach.nonIterable
@@ -667,20 +493,14 @@ parameters:
667493
path: tests/e2e/Adapter/Base.php
668494

669495
-
670-
message: '#^Call to an undefined method Utopia\\Database\\Database\:\:before\(\)\.$#'
671-
identifier: method.notFound
496+
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
497+
identifier: function.alreadyNarrowedType
672498
count: 1
673499
path: tests/e2e/Adapter/Base.php
674500

675501
-
676-
message: '#^Call to an undefined method Utopia\\Database\\Database\:\:on\(\)\.$#'
677-
identifier: method.notFound
678-
count: 4
679-
path: tests/e2e/Adapter/Base.php
680-
681-
-
682-
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
683-
identifier: function.alreadyNarrowedType
502+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertFalse\(\) with false will always evaluate to false\.$#'
503+
identifier: method.impossibleType
684504
count: 1
685505
path: tests/e2e/Adapter/Base.php
686506

@@ -1248,6 +1068,12 @@ parameters:
12481068
count: 1
12491069
path: tests/e2e/Adapter/Base.php
12501070

1071+
-
1072+
message: '#^Cannot call method assertEquals\(\) on mixed\.$#'
1073+
identifier: method.nonObject
1074+
count: 1
1075+
path: tests/e2e/Adapter/Base.php
1076+
12511077
-
12521078
message: '#^Cannot call method getArrayCopy\(\) on array\<string, mixed\>\.$#'
12531079
identifier: method.nonObject
@@ -1357,20 +1183,14 @@ parameters:
13571183
path: tests/e2e/Adapter/Base.php
13581184

13591185
-
1360-
message: '#^Method Utopia\\Database\\Database\:\:createAttribute\(\) invoked with 5 parameters, 2 required\.$#'
1361-
identifier: arguments.count
1362-
count: 2
1363-
path: tests/e2e/Adapter/Base.php
1364-
1365-
-
1366-
message: '#^Method Utopia\\Database\\Database\:\:createIndex\(\) invoked with 4 parameters, 2 required\.$#'
1367-
identifier: arguments.count
1186+
message: '#^Method Utopia\\Database\\Hook\\Lifecycle@anonymous/tests/e2e/Adapter/Scopes/CollectionTests\.php\:1069\:\:__construct\(\) has parameter \$events with no value type specified in iterable type array\.$#'
1187+
identifier: missingType.iterableValue
13681188
count: 1
13691189
path: tests/e2e/Adapter/Base.php
13701190

13711191
-
1372-
message: '#^Method Utopia\\Database\\Database\:\:silent\(\) invoked with 2 parameters, 1 required\.$#'
1373-
identifier: arguments.count
1192+
message: '#^Method Utopia\\Database\\Hook\\Lifecycle@anonymous/tests/e2e/Adapter/Scopes/CollectionTests\.php\:1069\:\:__construct\(\) has parameter \$test with no type specified\.$#'
1193+
identifier: missingType.parameter
13741194
count: 1
13751195
path: tests/e2e/Adapter/Base.php
13761196

@@ -1512,12 +1332,6 @@ parameters:
15121332
count: 108
15131333
path: tests/e2e/Adapter/Base.php
15141334

1515-
-
1516-
message: '#^Parameter \#2 \$attribute of method Utopia\\Database\\Database\:\:createAttribute\(\) expects Utopia\\Database\\Attribute, string given\.$#'
1517-
identifier: argument.type
1518-
count: 2
1519-
path: tests/e2e/Adapter/Base.php
1520-
15211335
-
15221336
message: '#^Parameter \#2 \$collection of method Utopia\\Database\\Database\:\:exists\(\) expects string\|null, mixed given\.$#'
15231337
identifier: argument.type
@@ -1560,12 +1374,6 @@ parameters:
15601374
count: 1
15611375
path: tests/e2e/Adapter/Base.php
15621376

1563-
-
1564-
message: '#^Parameter \#2 \$index of method Utopia\\Database\\Database\:\:createIndex\(\) expects Utopia\\Database\\Index, string given\.$#'
1565-
identifier: argument.type
1566-
count: 1
1567-
path: tests/e2e/Adapter/Base.php
1568-
15691377
-
15701378
message: '#^Parameter \#2 \$max of class Utopia\\Validator\\Range constructor expects float\|int, mixed given\.$#'
15711379
identifier: argument.type
@@ -2140,13 +1948,13 @@ parameters:
21401948
message: '#^Property Tests\\Unit\\ORM\\TestAllRelationsEntity\:\:\$posts type has no value type specified in iterable type array\.$#'
21411949
identifier: missingType.iterableValue
21421950
count: 1
2143-
path: tests/unit/ORM/MappingAttributeTest.php
1951+
path: tests/unit/ORM/TestAllRelationsEntity.php
21441952

21451953
-
21461954
message: '#^Property Tests\\Unit\\ORM\\TestAllRelationsEntity\:\:\$tags type has no value type specified in iterable type array\.$#'
21471955
identifier: missingType.iterableValue
21481956
count: 1
2149-
path: tests/unit/ORM/MappingAttributeTest.php
1957+
path: tests/unit/ORM/TestAllRelationsEntity.php
21501958

21511959
-
21521960
message: '#^Property Tests\\Unit\\ORM\\TestEntity\:\:\$permissions type has no value type specified in iterable type array\.$#'

src/Database/Database.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,9 +1872,38 @@ public function getCacheKeys(string $collectionId, ?string $documentId = null, a
18721872
if ($documentId) {
18731873
$documentKey = $documentHashKey = "{$collectionKey}:{$documentId}";
18741874

1875-
if (! empty($selects)) {
1876-
$documentHashKey = $documentKey.':'.\md5(\implode($selects));
1875+
$sortedSelects = $selects;
1876+
\sort($sortedSelects);
1877+
1878+
$filterSignatures = [];
1879+
if ($this->filter) {
1880+
$disabled = $this->disabledFilters ?? [];
1881+
1882+
foreach (self::$filters as $name => $callbacks) {
1883+
if (isset($disabled[$name])) {
1884+
continue;
1885+
}
1886+
if (\array_key_exists($name, $this->instanceFilters)) {
1887+
continue;
1888+
}
1889+
$filterSignatures[$name] = $callbacks['signature'];
1890+
}
1891+
1892+
foreach ($this->instanceFilters as $name => $callbacks) {
1893+
if (isset($disabled[$name])) {
1894+
continue;
1895+
}
1896+
$filterSignatures[$name] = $callbacks['signature'];
1897+
}
1898+
1899+
\ksort($filterSignatures);
18771900
}
1901+
1902+
$payload = \json_encode([
1903+
'selects' => $sortedSelects,
1904+
'filters' => $filterSignatures,
1905+
]) ?: '';
1906+
$documentHashKey = $documentKey . ':' . \md5($payload);
18781907
}
18791908

18801909
return [

0 commit comments

Comments
 (0)