@@ -20,32 +20,30 @@ test('Exception thrown for unable to open database file', function () {
2020 fn () => new Nette \Database \Connection ('sqlite:. ' ),
2121 Nette \Database \ConnectionException::class,
2222 'SQLSTATE[HY000] [14] unable to open database file ' ,
23- ' HY000 ' ,
23+ 14 ,
2424 );
25-
26- Assert::same (14 , $ e ->getDriverCode ());
27- Assert::same ($ e ->getCode (), $ e ->getSqlState ());
25+ Assert::same ('HY000 ' , $ e ->getSqlState ());
2826});
2927
3028
31- testException (
32- 'Exception thrown when calling rollback with no active transaction ' ,
33- fn () => $ connection ->rollback (),
34- Nette \Database \DriverException::class,
35- 'There is no active transaction ' ,
36- );
29+ test ('Exception thrown when calling rollback with no active transaction ' , function () use ($ connection ) {
30+ $ e = Assert::exception (
31+ fn () => $ connection ->rollback (),
32+ Nette \Database \DriverException::class,
33+ 'There is no active transaction ' ,
34+ );
35+ Assert::null ($ e ->getSqlState ());
36+ });
3737
3838
3939test ('Exception thrown for error in SQL query ' , function () use ($ connection ) {
4040 $ e = Assert::exception (
4141 fn () => $ connection ->query ('SELECT ' ),
4242 Nette \Database \DriverException::class,
4343 '%a% error%a% ' ,
44- ' HY000 ' ,
44+ 1 ,
4545 );
46-
47- Assert::same (1 , $ e ->getDriverCode ());
48- Assert::same ($ e ->getCode (), $ e ->getSqlState ());
46+ Assert::same ('HY000 ' , $ e ->getSqlState ());
4947});
5048
5149
@@ -54,11 +52,9 @@ test('Exception thrown for unique constraint violation', function () use ($conne
5452 fn () => $ connection ->query ('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL) ' ),
5553 Nette \Database \UniqueConstraintViolationException::class,
5654 '%a% Integrity constraint violation: %a% ' ,
57- ' 23000 ' ,
55+ 19 ,
5856 );
59-
60- Assert::same (19 , $ e ->getDriverCode ());
61- Assert::same ($ e ->getCode (), $ e ->getSqlState ());
57+ Assert::same ('23000 ' , $ e ->getSqlState ());
6258});
6359
6460
@@ -67,20 +63,16 @@ test('Exception thrown for not null constraint violation', function () use ($con
6763 fn () => $ connection ->query ('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL) ' ),
6864 Nette \Database \NotNullConstraintViolationException::class,
6965 '%a% Integrity constraint violation: %a% ' ,
70- ' 23000 ' ,
66+ 19 ,
7167 );
72-
73- Assert::same (19 , $ e ->getDriverCode ());
74- Assert::same ($ e ->getCode (), $ e ->getSqlState ());
68+ Assert::same ('23000 ' , $ e ->getSqlState ());
7569});
7670
7771
7872test ('Exception thrown for foreign key constraint violation ' , function () use ($ connection ) {
7973 $ e = Assert::exception (function () use ($ connection ) {
8074 $ connection ->query ('PRAGMA foreign_keys=true ' );
8175 $ connection ->query ('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "") ' );
82- }, Nette \Database \ForeignKeyConstraintViolationException::class, '%a% Integrity constraint violation: %a% ' , '23000 ' );
83-
84- Assert::same (19 , $ e ->getDriverCode ());
85- Assert::same ($ e ->getCode (), $ e ->getSqlState ());
76+ }, Nette \Database \ForeignKeyConstraintViolationException::class, '%a% Integrity constraint violation: %a% ' , 19 );
77+ Assert::same ('23000 ' , $ e ->getSqlState ());
8678});
0 commit comments