@@ -1355,58 +1355,60 @@ public function testSharedTablesMultiTenantCreateCollection(): void
13551355 return ;
13561356 }
13571357
1358- $ tenant1 = $ database ->getAdapter ()->getIdAttributeType () === Database::VAR_INTEGER ? 10 : 'tenant_10 ' ;
1359- $ tenant2 = $ database ->getAdapter ()->getIdAttributeType () === Database::VAR_INTEGER ? 20 : 'tenant_20 ' ;
1360- $ colName = 'multiTenantCol ' ;
1361-
1362- $ database ->setTenant ($ tenant1 );
1358+ try {
1359+ $ tenant1 = $ database ->getAdapter ()->getIdAttributeType () === Database::VAR_INTEGER ? 10 : 'tenant_10 ' ;
1360+ $ tenant2 = $ database ->getAdapter ()->getIdAttributeType () === Database::VAR_INTEGER ? 20 : 'tenant_20 ' ;
1361+ $ colName = 'multiTenantCol ' ;
13631362
1364- $ database ->createCollection ($ colName , [
1365- new Document ([
1366- '$id ' => 'name ' ,
1367- 'type ' => Database::VAR_STRING ,
1368- 'size ' => 128 ,
1369- 'required ' => true ,
1370- ]),
1371- ]);
1363+ $ database ->setTenant ($ tenant1 );
13721364
1373- $ col1 = $ database ->getCollection ($ colName );
1374- $ this ->assertFalse ($ col1 ->isEmpty ());
1375- $ this ->assertEquals (1 , \count ($ col1 ->getAttribute ('attributes ' )));
1365+ $ database ->createCollection ($ colName , [
1366+ new Document ([
1367+ '$id ' => 'name ' ,
1368+ 'type ' => Database::VAR_STRING ,
1369+ 'size ' => 128 ,
1370+ 'required ' => true ,
1371+ ]),
1372+ ]);
13761373
1377- $ database ->setTenant ($ tenant2 );
1374+ $ col1 = $ database ->getCollection ($ colName );
1375+ $ this ->assertFalse ($ col1 ->isEmpty ());
1376+ $ this ->assertEquals (1 , \count ($ col1 ->getAttribute ('attributes ' )));
13781377
1379- $ database ->createCollection ($ colName , [
1380- new Document ([
1381- '$id ' => 'name ' ,
1382- 'type ' => Database::VAR_STRING ,
1383- 'size ' => 128 ,
1384- 'required ' => true ,
1385- ]),
1386- ]);
1378+ $ database ->setTenant ($ tenant2 );
13871379
1388- $ col2 = $ database ->getCollection ($ colName );
1389- $ this ->assertFalse ($ col2 ->isEmpty ());
1390- $ this ->assertEquals (1 , \count ($ col2 ->getAttribute ('attributes ' )));
1380+ $ database ->createCollection ($ colName , [
1381+ new Document ([
1382+ '$id ' => 'name ' ,
1383+ 'type ' => Database::VAR_STRING ,
1384+ 'size ' => 128 ,
1385+ 'required ' => true ,
1386+ ]),
1387+ ]);
13911388
1392- $ database ->setTenant ( $ tenant1 );
1393- $ col1Again = $ database -> getCollection ( $ colName );
1394- $ this ->assertFalse ( $ col1Again -> isEmpty ( ));
1389+ $ col2 = $ database ->getCollection ( $ colName );
1390+ $ this -> assertFalse ( $ col2 -> isEmpty () );
1391+ $ this ->assertEquals ( 1 , \count ( $ col2 -> getAttribute ( ' attributes ' ) ));
13951392
1396- if ($ createdDb ) {
1397- $ database ->delete ();
1398- } else {
13991393 $ database ->setTenant ($ tenant1 );
1400- $ database ->deleteCollection ($ colName );
1401- $ database ->setTenant ($ tenant2 );
1402- $ database ->deleteCollection ($ colName );
1403- }
1394+ $ col1Again = $ database ->getCollection ($ colName );
1395+ $ this ->assertFalse ($ col1Again ->isEmpty ());
14041396
1405- $ database
1406- ->setSharedTables ($ sharedTables )
1407- ->setNamespace ($ namespace )
1408- ->setDatabase ($ schema )
1409- ->setTenant ($ originalTenant );
1397+ if ($ createdDb ) {
1398+ $ database ->delete ();
1399+ } else {
1400+ $ database ->setTenant ($ tenant1 );
1401+ $ database ->deleteCollection ($ colName );
1402+ $ database ->setTenant ($ tenant2 );
1403+ $ database ->deleteCollection ($ colName );
1404+ }
1405+ } finally {
1406+ $ database
1407+ ->setSharedTables ($ sharedTables )
1408+ ->setNamespace ($ namespace )
1409+ ->setDatabase ($ schema )
1410+ ->setTenant ($ originalTenant );
1411+ }
14101412 }
14111413
14121414 public function testSharedTablesMultiTenantCreate (): void
@@ -1417,47 +1419,47 @@ public function testSharedTablesMultiTenantCreate(): void
14171419 $ namespace = $ database ->getNamespace ();
14181420 $ schema = $ database ->getDatabase ();
14191421 $ originalTenant = $ database ->getTenant ();
1420- $ createdDb = false ;
14211422
1422- $ tenant1 = $ database ->getAdapter ()->getIdAttributeType () === Database::VAR_INTEGER ? 100 : 'tenant_100 ' ;
1423- $ tenant2 = $ database ->getAdapter ()->getIdAttributeType () === Database::VAR_INTEGER ? 200 : 'tenant_200 ' ;
1424-
1425- if ($ sharedTables ) {
1426- // Already in shared-tables mode; create() should be idempotent.
1427- // No assertion on exists() since SQLite always returns false for
1428- // database-level exists. The test verifies create() doesn't throw.
1429- $ database ->setTenant ($ tenant1 );
1430- $ database ->create ();
1431- $ database ->setTenant ($ tenant2 );
1432- $ database ->create ();
1433- $ this ->assertTrue (true );
1434- } elseif ($ database ->getAdapter ()->getSupportForSchemas ()) {
1435- $ dbName = 'stMultiCreate ' ;
1436- if ($ database ->exists ($ dbName )) {
1437- $ database ->setDatabase ($ dbName )->delete ();
1423+ try {
1424+ $ tenant1 = $ database ->getAdapter ()->getIdAttributeType () === Database::VAR_INTEGER ? 100 : 'tenant_100 ' ;
1425+ $ tenant2 = $ database ->getAdapter ()->getIdAttributeType () === Database::VAR_INTEGER ? 200 : 'tenant_200 ' ;
1426+
1427+ if ($ sharedTables ) {
1428+ // Already in shared-tables mode; create() should be idempotent.
1429+ // No assertion on exists() since SQLite always returns false for
1430+ // database-level exists. The test verifies create() doesn't throw.
1431+ $ database ->setTenant ($ tenant1 );
1432+ $ database ->create ();
1433+ $ database ->setTenant ($ tenant2 );
1434+ $ database ->create ();
1435+ $ this ->assertTrue (true );
1436+ } elseif ($ database ->getAdapter ()->getSupportForSchemas ()) {
1437+ $ dbName = 'stMultiCreate ' ;
1438+ if ($ database ->exists ($ dbName )) {
1439+ $ database ->setDatabase ($ dbName )->delete ();
1440+ }
1441+ $ database
1442+ ->setDatabase ($ dbName )
1443+ ->setNamespace ('' )
1444+ ->setSharedTables (true )
1445+ ->setTenant ($ tenant1 )
1446+ ->create ();
1447+ $ this ->assertTrue ($ database ->exists ($ dbName ));
1448+ $ database ->setTenant ($ tenant2 );
1449+ $ database ->create ();
1450+ $ this ->assertTrue ($ database ->exists ($ dbName ));
1451+ $ database ->delete ();
1452+ } else {
1453+ $ this ->expectNotToPerformAssertions ();
1454+ return ;
14381455 }
1456+ } finally {
14391457 $ database
1440- ->setDatabase ($ dbName )
1441- ->setNamespace ('' )
1442- ->setSharedTables (true )
1443- ->setTenant ($ tenant1 )
1444- ->create ();
1445- $ this ->assertTrue ($ database ->exists ($ dbName ));
1446- $ database ->setTenant ($ tenant2 );
1447- $ database ->create ();
1448- $ this ->assertTrue ($ database ->exists ($ dbName ));
1449- $ database ->delete ();
1450- $ createdDb = true ;
1451- } else {
1452- $ this ->expectNotToPerformAssertions ();
1453- return ;
1458+ ->setSharedTables ($ sharedTables )
1459+ ->setNamespace ($ namespace )
1460+ ->setDatabase ($ schema )
1461+ ->setTenant ($ originalTenant );
14541462 }
1455-
1456- $ database
1457- ->setSharedTables ($ sharedTables )
1458- ->setNamespace ($ namespace )
1459- ->setDatabase ($ schema )
1460- ->setTenant ($ originalTenant );
14611463 }
14621464
14631465 public function testEvents (): void
0 commit comments