99
1010/**
1111 * Regression coverage for Schema::create() double-emitting foreign key
12- * constraints.
13- *
14- * Schema::create() compiles the CREATE TABLE statement (which already
15- * inlines every `$table->foreign()` as a column-level CONSTRAINT, see
16- * SchemaGrammar::compileCreate()) and then, unconditionally, ALSO runs
17- * SchemaGrammar::compileForeignKeys() — which re-emits the very same
18- * constraints as separate `ALTER TABLE ... ADD CONSTRAINT` statements.
19- * No grammar overrides compileForeignKeys() to suppress this for the
20- * "already inlined at CREATE TABLE time" case, so every driver executes
21- * a duplicate constraint statement:
22- *
23- * - MySQL: rejects the duplicate constraint name (errno 121,
24- * "Duplicate key on write or update").
25- * - SQLite: has no `ALTER TABLE ... ADD CONSTRAINT` syntax at all, so
26- * the statement is a hard syntax error.
27- *
28- * A table defined with `$table->foreign()` therefore cannot be created
29- * via Schema::create() on any driver.
12+ * constraints (once inlined in CREATE TABLE, once more via a redundant
13+ * ALTER TABLE ADD CONSTRAINT).
3014 */
3115class SchemaForeignKeyTest extends IntegrationTestCase
3216{
@@ -54,19 +38,8 @@ public function testCreateWithForeignKeyDoesNotThrow(): void
5438 }
5539 }
5640
57- /**
58- * SQLite never enforces foreign keys unless the connection issues
59- * `PRAGMA foreign_keys = ON` — this library does not do so, which is a
60- * separate, pre-existing gap unrelated to the double-emission bug this
61- * file targets. Skipped here rather than silently asserting something
62- * false for that driver.
63- */
6441 public function testCreateWithForeignKeyActuallyEnforcesTheConstraint (): void
6542 {
66- if (strtolower ((string ) (getenv ('DB_DRIVER ' ) ?: 'sqlite ' )) === 'sqlite ' ) {
67- $ this ->markTestSkipped ('SQLite FK enforcement requires PRAGMA foreign_keys=ON, which this library does not set (separate gap). ' );
68- }
69-
7043 $ parent = 'sfk_test_parents2 ' ;
7144 $ child = 'sfk_test_children2 ' ;
7245
@@ -81,9 +54,6 @@ public function testCreateWithForeignKeyActuallyEnforcesTheConstraint(): void
8154 $ t ->foreign ('parent_id ' )->references ('id ' )->on ($ parent );
8255 });
8356
84- // A reference to a non-existent parent row must be rejected —
85- // proof the constraint is really enforced by the DB, not just
86- // that CREATE TABLE happened to succeed some other way.
8757 $ threw = false ;
8858 try {
8959 \Foxdb \DB ::table ($ child )->insert (['parent_id ' => 999999 ]);
0 commit comments