File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,9 +52,10 @@ public function testCreatesConstraintViolationExceptions(
5252 string $ message ,
5353 string $ expectedException ,
5454 ): void {
55- $ exception = $ db ->createDatabaseException ($ message , $ code );
55+ $ exception = $ db ->createDatabaseException ($ message , $ code );
56+ $ actualException = $ exception ::class;
5657
57- $ this ->assertSame ($ exception ::class , $ expectedException );
58+ $ this ->assertSame ($ expectedException , $ actualException );
5859 $ this ->assertInstanceOf (ConstraintViolationException::class, $ exception );
5960 $ this ->assertSame ($ code , $ exception ->getDatabaseCode ());
6061 }
Original file line number Diff line number Diff line change 1414namespace CodeIgniter \Database \Live ;
1515
1616use CodeIgniter \Database \Exceptions \ConstraintViolationException ;
17+ use CodeIgniter \Database \Exceptions \DatabaseException ;
1718use CodeIgniter \Database \Exceptions \ForeignKeyConstraintViolationException ;
1819use CodeIgniter \Database \Exceptions \NotNullConstraintViolationException ;
1920use CodeIgniter \Database \Forge ;
@@ -80,12 +81,18 @@ public function testThrowsConstraintViolationExceptionForForeignKeyWithDebugEnab
8081 ? ConstraintViolationException::class
8182 : ForeignKeyConstraintViolationException::class;
8283
83- $ this ->expectException ($ expectedException );
84+ try {
85+ $ this ->db ->table ('cv_child ' )->insert ([
86+ 'id ' => 1 ,
87+ 'parent_id ' => 999 ,
88+ ]);
8489
85- $ this ->db ->table ('cv_child ' )->insert ([
86- 'id ' => 1 ,
87- 'parent_id ' => 999 ,
88- ]);
90+ $ this ->fail ('Expected database exception was not thrown. ' );
91+ } catch (DatabaseException $ e ) {
92+ $ actualException = $ e ::class;
93+
94+ $ this ->assertSame ($ expectedException , $ actualException );
95+ }
8996 }
9097
9198 public function testStoresNotNullConstraintViolationExceptionWithDebugDisabled (): void
You can’t perform that action at this time.
0 commit comments