@@ -1657,6 +1657,87 @@ public function testProcessIndexes(): void
1657
1657
$ this ->forge ->dropTable ('user2 ' , true );
1658
1658
}
1659
1659
1660
+ public function testProcessIndexesWithKeyOnly (): void
1661
+ {
1662
+ // make sure tables don't exist
1663
+ $ this ->forge ->dropTable ('actions ' , true );
1664
+
1665
+ $ this ->createActionsTable ();
1666
+ $ this ->forge ->addKey ('name ' , false , false , 'db_actions_name ' );
1667
+
1668
+ // create indexes
1669
+ $ this ->forge ->processIndexes ('actions ' );
1670
+
1671
+ // get a list of all indexes
1672
+ $ allIndexes = $ this ->db ->getIndexData ('actions ' );
1673
+
1674
+ // check that db_actions_name key exists
1675
+ $ indexes = array_filter (
1676
+ $ allIndexes ,
1677
+ static fn ($ index ) => ($ index ->name === 'db_actions_name ' )
1678
+ && ($ index ->fields === [0 => 'name ' ])
1679
+ );
1680
+ $ this ->assertCount (1 , $ indexes );
1681
+
1682
+ // drop tables to avoid any future conflicts
1683
+ $ this ->forge ->dropTable ('actions ' , true );
1684
+ }
1685
+
1686
+ public function testProcessIndexesWithPrimaryKeyOnly (): void
1687
+ {
1688
+ // make sure tables don't exist
1689
+ $ this ->forge ->dropTable ('actions ' , true );
1690
+
1691
+ $ this ->createActionsTable ();
1692
+ $ this ->forge ->addPrimaryKey ('id ' );
1693
+
1694
+ // create indexes
1695
+ $ this ->forge ->processIndexes ('actions ' );
1696
+
1697
+ // get a list of all indexes
1698
+ $ allIndexes = $ this ->db ->getIndexData ('actions ' );
1699
+
1700
+ // check that the primary key exists
1701
+ $ indexes = array_filter (
1702
+ $ allIndexes ,
1703
+ static fn ($ index ) => $ index ->type === 'PRIMARY '
1704
+ );
1705
+ $ this ->assertCount (1 , $ indexes );
1706
+
1707
+ // drop tables to avoid any future conflicts
1708
+ $ this ->forge ->dropTable ('actions ' , true );
1709
+ }
1710
+
1711
+ public function testProcessIndexesWithForeignKeyOnly (): void
1712
+ {
1713
+ // make sure tables don't exist
1714
+ $ this ->forge ->dropTable ('actions ' , true );
1715
+ $ this ->forge ->dropTable ('user2 ' , true );
1716
+
1717
+ $ this ->createUser2TableWithKeys ();
1718
+ $ this ->populateUser2Table ();
1719
+ $ this ->createActionsTable ();
1720
+
1721
+ // SQLite does not support custom foreign key name
1722
+ if ($ this ->db ->DBDriver === 'SQLite3 ' ) {
1723
+ $ this ->forge ->addForeignKey ('userid ' , 'user ' , 'id ' );
1724
+ $ this ->forge ->addForeignKey ('userid2 ' , 'user2 ' , 'id ' );
1725
+ } else {
1726
+ $ this ->forge ->addForeignKey ('userid ' , 'user ' , 'id ' , '' , '' , 'db_actions_userid_foreign ' );
1727
+ $ this ->forge ->addForeignKey ('userid2 ' , 'user2 ' , 'id ' , '' , '' , 'db_actions_userid2_foreign ' );
1728
+ }
1729
+
1730
+ // create indexes
1731
+ $ this ->forge ->processIndexes ('actions ' );
1732
+
1733
+ // check that the two foreign keys exist
1734
+ $ this ->assertCount (2 , $ this ->db ->getForeignKeyData ('actions ' ));
1735
+
1736
+ // drop tables to avoid any future conflicts
1737
+ $ this ->forge ->dropTable ('actions ' , true );
1738
+ $ this ->forge ->dropTable ('user2 ' , true );
1739
+ }
1740
+
1660
1741
private function createUser2TableWithKeys (): void
1661
1742
{
1662
1743
$ fields = [
0 commit comments