@@ -9,52 +9,63 @@ require __DIR__ . '/../../bootstrap.php';
99$ connection = Mockery::mock (Nette \Database \Drivers \Connection::class);
1010$ engine = new Nette \Database \Drivers \Engines \MSSQLEngine ($ connection );
1111
12- Assert::exception (function () use ($ engine ) {
13- $ query = 'SELECT 1 FROM t ' ;
14- $ engine ->applyLimit ($ query , 10 , 20 );
15- }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
16-
17- Assert::exception (function () use ($ engine ) {
18- $ query = 'SELECT 1 FROM t ' ;
19- $ engine ->applyLimit ($ query , 0 , 20 );
20- }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
21-
22- $ query = 'SELECT 1 FROM t ' ;
23- $ engine ->applyLimit ($ query , 10 , 0 );
24- Assert::same ('SELECT TOP 10 1 FROM t ' , $ query );
25-
26- Assert::exception (function () use ($ engine ) {
27- $ query = 'SELECT 1 FROM t ' ;
28- $ engine ->applyLimit ($ query , null , 20 );
29- }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
30-
31- $ query = 'SELECT 1 FROM t ' ;
32- $ engine ->applyLimit ($ query , 10 , null );
33- Assert::same ('SELECT TOP 10 1 FROM t ' , $ query );
34-
35- $ query = ' select distinct 1 FROM t ' ;
36- $ engine ->applyLimit ($ query , 10 , null );
37- Assert::same (' select distinct TOP 10 1 FROM t ' , $ query );
38-
39- $ query = 'UPDATE t SET ' ;
40- $ engine ->applyLimit ($ query , 10 , null );
41- Assert::same ('UPDATE TOP 10 t SET ' , $ query );
42-
43- $ query = 'DELETE FROM t SET ' ;
44- $ engine ->applyLimit ($ query , 10 , null );
45- Assert::same ('DELETE TOP 10 FROM t SET ' , $ query );
46-
47- Assert::exception (function () use ($ engine ) {
48- $ query = 'SET FROM t ' ;
49- $ engine ->applyLimit ($ query , 10 , null );
50- }, Nette \InvalidArgumentException::class, 'SQL query must begin with SELECT, UPDATE or DELETE command. ' );
51-
52- Assert::exception (function () use ($ engine ) {
53- $ query = 'SELECT 1 FROM t ' ;
54- $ engine ->applyLimit ($ query , -1 , null );
55- }, Nette \InvalidArgumentException::class, 'Negative offset or limit. ' );
56-
57- Assert::exception (function () use ($ engine ) {
58- $ query = 'SELECT 1 FROM t ' ;
59- $ engine ->applyLimit ($ query , null , -1 );
60- }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
12+ Assert::exception (
13+ fn () => $ engine ->applyLimit ('SELECT 1 FROM t ' , 10 , 20 ),
14+ Nette \NotSupportedException::class,
15+ 'Offset is not supported by this database. ' ,
16+ );
17+
18+ Assert::exception (
19+ fn () => $ engine ->applyLimit ('SELECT 1 FROM t ' , 0 , 20 ),
20+ Nette \NotSupportedException::class,
21+ 'Offset is not supported by this database. ' ,
22+ );
23+
24+ Assert::same (
25+ $ engine ->applyLimit ('SELECT 1 FROM t ' , 10 , 0 ),
26+ 'SELECT TOP 10 1 FROM t ' ,
27+ );
28+
29+ Assert::exception (
30+ fn () => $ engine ->applyLimit ('SELECT 1 FROM t ' , null , 20 ),
31+ Nette \NotSupportedException::class,
32+ 'Offset is not supported by this database. ' ,
33+ );
34+
35+ Assert::same (
36+ $ engine ->applyLimit ('SELECT 1 FROM t ' , 10 , null ),
37+ 'SELECT TOP 10 1 FROM t ' ,
38+ );
39+
40+ Assert::same (
41+ $ engine ->applyLimit (' select distinct 1 FROM t ' , 10 , null ),
42+ ' select distinct TOP 10 1 FROM t ' ,
43+ );
44+
45+ Assert::same (
46+ $ engine ->applyLimit ('UPDATE t SET ' , 10 , null ),
47+ 'UPDATE TOP 10 t SET ' ,
48+ );
49+
50+ Assert::same (
51+ $ engine ->applyLimit ('DELETE FROM t SET ' , 10 , null ),
52+ 'DELETE TOP 10 FROM t SET ' ,
53+ );
54+
55+ Assert::exception (
56+ fn () => $ engine ->applyLimit ('SET FROM t ' , 10 , null ),
57+ Nette \InvalidArgumentException::class,
58+ 'SQL query must begin with SELECT, UPDATE or DELETE command. ' ,
59+ );
60+
61+ Assert::exception (
62+ fn () => $ engine ->applyLimit ('SELECT 1 FROM t ' , -1 , null ),
63+ Nette \InvalidArgumentException::class,
64+ 'Negative offset or limit. ' ,
65+ );
66+
67+ Assert::exception (
68+ fn () => $ engine ->applyLimit ('SELECT 1 FROM t ' , null , -1 ),
69+ Nette \NotSupportedException::class,
70+ 'Offset is not supported by this database. ' ,
71+ );
0 commit comments