Skip to content

Commit e68457f

Browse files
committed
Add test inside upsert supported check
1 parent 43fb280 commit e68457f

1 file changed

Lines changed: 47 additions & 45 deletions

File tree

tests/e2e/Adapter/Base.php

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16524,60 +16524,62 @@ public function testSharedTablesTenantPerDocument(): void
1652416524
$this->assertEquals(1, \count($docs));
1652516525
$this->assertEquals($doc1Id, $docs[0]->getId());
1652616526

16527-
// Test upsert with tenant per doc
16528-
$doc3Id = ID::unique();
16529-
$database
16530-
->setTenant(null)
16531-
->setTenantPerDocument(true)
16532-
->createOrUpdateDocuments(__FUNCTION__, [new Document([
16533-
'$id' => $doc3Id,
16534-
'$tenant' => 3,
16535-
'name' => 'Superman',
16536-
])]);
16537-
16538-
// Set to tenant 1 and read
16539-
$doc = $database
16540-
->setTenantPerDocument(false)
16541-
->setTenant(3)
16542-
->getDocument(__FUNCTION__, $doc3Id);
16543-
16544-
$this->assertEquals('Superman', $doc['name']);
16545-
$this->assertEquals(3, $doc->getTenant());
16546-
$this->assertEquals($doc3Id, $doc->getId());
16547-
16548-
// Test no read from other tenants
16549-
$docs = $database
16550-
->setTenantPerDocument(false)
16551-
->setTenant(1)
16552-
->find(__FUNCTION__);
16553-
16554-
$this->assertEquals(1, \count($docs));
16555-
16556-
// Ensure no cross-tenant upsert
16557-
try {
16527+
if (static::getDatabase()->getAdapter()->getSupportForUpserts()) {
16528+
// Test upsert with tenant per doc
16529+
$doc3Id = ID::unique();
1655816530
$database
1655916531
->setTenant(null)
1656016532
->setTenantPerDocument(true)
1656116533
->createOrUpdateDocuments(__FUNCTION__, [new Document([
1656216534
'$id' => $doc3Id,
16563-
'$tenant' => 1,
16564-
'name' => 'Superman updated',
16535+
'$tenant' => 3,
16536+
'name' => 'Superman3',
1656516537
])]);
1656616538

16567-
$this->fail('Expected to throw for cross-tenant upsert');
16568-
} catch (\Throwable) {
16569-
// Expected
16570-
}
16571-
16572-
// Ensure no cross-tenant read from upsert
16573-
try {
16574-
$database
16575-
->setTenant(1)
16539+
// Set to tenant 3 and read
16540+
$doc = $database
1657616541
->setTenantPerDocument(false)
16542+
->setTenant(3)
1657716543
->getDocument(__FUNCTION__, $doc3Id);
16578-
$this->fail('Expected to throw for cross-tenant read');
16579-
} catch (\Throwable) {
16580-
// Expected
16544+
16545+
$this->assertEquals('Superman3', $doc['name']);
16546+
$this->assertEquals(3, $doc->getTenant());
16547+
$this->assertEquals($doc3Id, $doc->getId());
16548+
16549+
// Test no read from other tenants
16550+
$docs = $database
16551+
->setTenantPerDocument(false)
16552+
->setTenant(1)
16553+
->find(__FUNCTION__);
16554+
16555+
$this->assertEquals(1, \count($docs));
16556+
16557+
// Ensure no cross-tenant upsert
16558+
try {
16559+
$database
16560+
->setTenant(null)
16561+
->setTenantPerDocument(true)
16562+
->createOrUpdateDocuments(__FUNCTION__, [new Document([
16563+
'$id' => $doc3Id,
16564+
'$tenant' => 1,
16565+
'name' => 'Superman updated',
16566+
])]);
16567+
16568+
$this->fail('Expected to throw for cross-tenant upsert');
16569+
} catch (\Throwable) {
16570+
// Expected
16571+
}
16572+
16573+
// Ensure no cross-tenant read from upsert
16574+
try {
16575+
$database
16576+
->setTenant(1)
16577+
->setTenantPerDocument(false)
16578+
->getDocument(__FUNCTION__, $doc3Id);
16579+
$this->fail('Expected to throw for cross-tenant read');
16580+
} catch (\Throwable) {
16581+
// Expected
16582+
}
1658116583
}
1658216584

1658316585
// Reset instance

0 commit comments

Comments
 (0)