Skip to content

Commit 15d8eed

Browse files
abnegateclaude
andcommitted
fix: resolve adapter test failures across all databases
- Fix user:x role management in DocumentTests to ensure testFindBasicChecks runs without elevated permissions matching original test behavior - Fix MongoTenantFilter and TenantWrite type mismatch to accept string tenant IDs matching the base Adapter's int|string|null type - Convert deprecated @Depends annotations to PHPUnit 12 #[Depends] attributes - Update PHPStan baseline Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8d235cd commit 15d8eed

6 files changed

Lines changed: 19 additions & 52 deletions

File tree

phpstan-baseline.neon

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,6 @@ parameters:
4242
count: 4
4343
path: src/Database/Adapter/MariaDB.php
4444

45-
-
46-
message: '#^Method Utopia\\Database\\Adapter\\Mongo\:\:getTenantFilters\(\) should return array\<string, array\<int\>\>\|int\|null but returns array\<string, array\<int\|string\>\>\.$#'
47-
identifier: return.type
48-
count: 2
49-
path: src/Database/Adapter/Mongo.php
50-
51-
-
52-
message: '#^Method Utopia\\Database\\Adapter\\Mongo\:\:getTenantFilters\(\) should return array\<string, array\<int\>\>\|int\|null but returns int\|string\.$#'
53-
identifier: return.type
54-
count: 1
55-
path: src/Database/Adapter/Mongo.php
56-
57-
-
58-
message: '#^Parameter \#1 \$tenant of class Utopia\\Database\\Hook\\MongoTenantFilter constructor expects int\|null, int\|string\|null given\.$#'
59-
identifier: argument.type
60-
count: 1
61-
path: src/Database/Adapter/Mongo.php
62-
63-
-
64-
message: '#^Parameter \#1 \$tenant of class Utopia\\Database\\Hook\\TenantWrite constructor expects int, int\|string given\.$#'
65-
identifier: argument.type
66-
count: 1
67-
path: src/Database/Adapter/Mongo.php
68-
69-
-
70-
message: '#^Parameter \#2 \$tenants of method Utopia\\Database\\Adapter\\Mongo\:\:getTenantFilters\(\) expects array\<int\>, array\<int\|string\> given\.$#'
71-
identifier: argument.type
72-
count: 1
73-
path: src/Database/Adapter/Mongo.php
74-
7545
-
7646
message: '#^Method Utopia\\Database\\Adapter\\Pool\:\:getSchemaIndexes\(\) should return array\<Utopia\\Database\\Document\> but returns mixed\.$#'
7747
identifier: return.type
@@ -132,12 +102,6 @@ parameters:
132102
count: 1
133103
path: src/Database/Adapter/SQL.php
134104

135-
-
136-
message: '#^Parameter \#1 \$tenant of class Utopia\\Database\\Hook\\TenantWrite constructor expects int, int\|string given\.$#'
137-
identifier: argument.type
138-
count: 1
139-
path: src/Database/Adapter/SQL.php
140-
141105
-
142106
message: '#^Parameter \#2 \$arrays of function array_diff expects an array of values castable to string, array\<int, mixed\> given\.$#'
143107
identifier: argument.type
@@ -1183,13 +1147,13 @@ parameters:
11831147
path: tests/e2e/Adapter/Base.php
11841148

11851149
-
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\.$#'
1150+
message: '#^Method Utopia\\Database\\Hook\\Lifecycle@anonymous/tests/e2e/Adapter/Scopes/CollectionTests\.php\:1070\:\:__construct\(\) has parameter \$events with no value type specified in iterable type array\.$#'
11871151
identifier: missingType.iterableValue
11881152
count: 1
11891153
path: tests/e2e/Adapter/Base.php
11901154

11911155
-
1192-
message: '#^Method Utopia\\Database\\Hook\\Lifecycle@anonymous/tests/e2e/Adapter/Scopes/CollectionTests\.php\:1069\:\:__construct\(\) has parameter \$test with no type specified\.$#'
1156+
message: '#^Method Utopia\\Database\\Hook\\Lifecycle@anonymous/tests/e2e/Adapter/Scopes/CollectionTests\.php\:1070\:\:__construct\(\) has parameter \$test with no type specified\.$#'
11931157
identifier: missingType.parameter
11941158
count: 1
11951159
path: tests/e2e/Adapter/Base.php

src/Database/Adapter/Mongo.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,18 +2427,18 @@ public function getSizeOfCollectionOnDisk(string $collection): int
24272427
}
24282428

24292429
/**
2430-
* @param array<int> $tenants
2431-
* @return int|null|array<string, array<int>>
2430+
* @param array<int|string> $tenants
2431+
* @return int|string|null|array<string, array<int|string>>
24322432
*/
24332433
public function getTenantFilters(
24342434
string $collection,
24352435
array $tenants = [],
2436-
): int|null|array {
2436+
): int|string|null|array {
24372437
if (! $this->sharedTables) {
24382438
return null;
24392439
}
24402440

2441-
/** @var array<int> $values */
2441+
/** @var array<int|string> $values */
24422442
$values = [];
24432443

24442444
if (\count($tenants) === 0) {

src/Database/Hook/MongoTenantFilter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
class MongoTenantFilter implements Read
1111
{
1212
/**
13-
* @param int|null $tenant The current tenant ID
13+
* @param int|string|null $tenant The current tenant ID
1414
* @param bool $sharedTables Whether shared tables mode is enabled
15-
* @param Closure(string, array<int>=): (int|null|array<string, array<int>>) $getTenantFilters Closure that returns tenant filter values for a collection
15+
* @param Closure(string, array<int|string>=): (int|string|null|array<string, array<int|string>>) $getTenantFilters Closure that returns tenant filter values for a collection
1616
*/
1717
public function __construct(
18-
private ?int $tenant,
18+
private int|string|null $tenant,
1919
private bool $sharedTables,
2020
private Closure $getTenantFilters,
2121
) {

src/Database/Hook/TenantWrite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
class TenantWrite implements Write
1111
{
1212
/**
13-
* @param int $tenant The current tenant identifier
13+
* @param int|string $tenant The current tenant identifier
1414
* @param string $column The column name used to store the tenant value
1515
*/
1616
public function __construct(
17-
private int $tenant,
17+
private int|string $tenant,
1818
private string $column = '_tenant',
1919
) {
2020
}

tests/e2e/Adapter/Scopes/CollectionTests.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\E2E\Adapter\Scopes;
44

55
use Exception;
6+
use PHPUnit\Framework\Attributes\Depends;
67
use Utopia\Database\Attribute;
78
use Utopia\Database\Capability;
89
use Utopia\Database\Database;
@@ -1169,9 +1170,7 @@ public function testCreatedAtUpdatedAt(): void
11691170
$this->assertNotNull($document->getSequence());
11701171
}
11711172

1172-
/**
1173-
* @depends testCreatedAtUpdatedAt
1174-
*/
1173+
#[Depends('testCreatedAtUpdatedAt')]
11751174
public function testCreatedAtUpdatedAtAssert(): void
11761175
{
11771176
/** @var Database $database */

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use PDOException;
7+
use PHPUnit\Framework\Attributes\Depends;
78
use Throwable;
89
use Utopia\Database\Adapter\SQL;
910
use Utopia\Database\Attribute;
@@ -4874,6 +4875,8 @@ public function testFindBasicChecks(): void
48744875
/** @var Database $database */
48754876
$database = $this->getDatabase();
48764877

4878+
$this->getDatabase()->getAuthorization()->removeRole('user:x');
4879+
48774880
$documents = $database->find('movies');
48784881
$movieDocuments = $documents;
48794882

@@ -4935,6 +4938,8 @@ public function testFindBasicChecks(): void
49354938
Query::orderAsc(''),
49364939
]);
49374940
$this->assertEquals($movieDocuments[0]->getId(), $documents[0]->getId());
4941+
4942+
$this->getDatabase()->getAuthorization()->addRole('user:x');
49384943
}
49394944

49404945
public function testFindCheckPermissions(): void
@@ -6376,8 +6381,7 @@ public function testFindSelect(): void
63766381
}
63776382
}
63786383

6379-
/** @depends testFind */
6380-
6384+
#[Depends('testFindCheckPermissions')]
63816385
public function testForeach(): void
63826386
{
63836387
$this->initMoviesFixture();

0 commit comments

Comments
 (0)