2222namespace Test \DB \QueryBuilder ;
2323
2424use Doctrine \DBAL \Query \Expression \CompositeExpression ;
25+ use Doctrine \DBAL \Query \QueryException ;
26+ use Doctrine \DBAL \Result ;
2527use OC \DB \QueryBuilder \Literal ;
2628use OC \DB \QueryBuilder \Parameter ;
2729use OC \DB \QueryBuilder \QueryBuilder ;
@@ -1223,6 +1225,10 @@ public function testExecuteWithoutLogger() {
12231225 ->expects ($ this ->once ())
12241226 ->method ('execute ' )
12251227 ->willReturn (3 );
1228+ $ queryBuilder
1229+ ->expects ($ this ->any ())
1230+ ->method ('getParameters ' )
1231+ ->willReturn ([]);
12261232 $ this ->logger
12271233 ->expects ($ this ->never ())
12281234 ->method ('debug ' );
@@ -1239,14 +1245,14 @@ public function testExecuteWithoutLogger() {
12391245 public function testExecuteWithLoggerAndNamedArray () {
12401246 $ queryBuilder = $ this ->createMock (\Doctrine \DBAL \Query \QueryBuilder::class);
12411247 $ queryBuilder
1242- ->expects ($ this ->at ( 0 ))
1248+ ->expects ($ this ->any ( ))
12431249 ->method ('getParameters ' )
12441250 ->willReturn ([
12451251 'foo ' => 'bar ' ,
12461252 'key ' => 'value ' ,
12471253 ]);
12481254 $ queryBuilder
1249- ->expects ($ this ->at ( 1 ))
1255+ ->expects ($ this ->any ( ))
12501256 ->method ('getSQL ' )
12511257 ->willReturn ('SELECT * FROM FOO WHERE BAR = ? ' );
12521258 $ queryBuilder
@@ -1277,11 +1283,11 @@ public function testExecuteWithLoggerAndNamedArray() {
12771283 public function testExecuteWithLoggerAndUnnamedArray () {
12781284 $ queryBuilder = $ this ->createMock (\Doctrine \DBAL \Query \QueryBuilder::class);
12791285 $ queryBuilder
1280- ->expects ($ this ->at ( 0 ))
1286+ ->expects ($ this ->any ( ))
12811287 ->method ('getParameters ' )
12821288 ->willReturn (['Bar ' ]);
12831289 $ queryBuilder
1284- ->expects ($ this ->at ( 1 ))
1290+ ->expects ($ this ->any ( ))
12851291 ->method ('getSQL ' )
12861292 ->willReturn ('SELECT * FROM FOO WHERE BAR = ? ' );
12871293 $ queryBuilder
@@ -1312,11 +1318,11 @@ public function testExecuteWithLoggerAndUnnamedArray() {
13121318 public function testExecuteWithLoggerAndNoParams () {
13131319 $ queryBuilder = $ this ->createMock (\Doctrine \DBAL \Query \QueryBuilder::class);
13141320 $ queryBuilder
1315- ->expects ($ this ->at ( 0 ))
1321+ ->expects ($ this ->any ( ))
13161322 ->method ('getParameters ' )
13171323 ->willReturn ([]);
13181324 $ queryBuilder
1319- ->expects ($ this ->at ( 1 ))
1325+ ->expects ($ this ->any ( ))
13201326 ->method ('getSQL ' )
13211327 ->willReturn ('SELECT * FROM FOO WHERE BAR = ? ' );
13221328 $ queryBuilder
@@ -1342,4 +1348,74 @@ public function testExecuteWithLoggerAndNoParams() {
13421348 $ this ->invokePrivate ($ this ->queryBuilder , 'queryBuilder ' , [$ queryBuilder ]);
13431349 $ this ->assertEquals (3 , $ this ->queryBuilder ->execute ());
13441350 }
1351+
1352+ public function testExecuteWithParameterTooLarge () {
1353+ $ queryBuilder = $ this ->createMock (\Doctrine \DBAL \Query \QueryBuilder::class);
1354+ $ p = array_fill (0 , 1001 , 'foo ' );
1355+ $ queryBuilder
1356+ ->expects ($ this ->any ())
1357+ ->method ('getParameters ' )
1358+ ->willReturn ([$ p ]);
1359+ $ queryBuilder
1360+ ->expects ($ this ->any ())
1361+ ->method ('getSQL ' )
1362+ ->willReturn ('SELECT * FROM FOO WHERE BAR IN (?) ' );
1363+ $ queryBuilder
1364+ ->expects ($ this ->once ())
1365+ ->method ('execute ' )
1366+ ->willReturn ($ this ->createMock (Result::class));
1367+ $ this ->logger
1368+ ->expects ($ this ->once ())
1369+ ->method ('logException ' )
1370+ ->willReturnCallback (function ($ e , $ parameters ) {
1371+ $ this ->assertInstanceOf (QueryException::class, $ e );
1372+ $ this ->assertSame (
1373+ 'More than 1000 expressions in a list are not allowed on Oracle. ' ,
1374+ $ parameters ['message ' ]
1375+ );
1376+ });
1377+ $ this ->config
1378+ ->expects ($ this ->once ())
1379+ ->method ('getValue ' )
1380+ ->with ('log_query ' , false )
1381+ ->willReturn (false );
1382+
1383+ $ this ->invokePrivate ($ this ->queryBuilder , 'queryBuilder ' , [$ queryBuilder ]);
1384+ $ this ->queryBuilder ->execute ();
1385+ }
1386+
1387+ public function testExecuteWithParametersTooMany () {
1388+ $ queryBuilder = $ this ->createMock (\Doctrine \DBAL \Query \QueryBuilder::class);
1389+ $ p = array_fill (0 , 999 , 'foo ' );
1390+ $ queryBuilder
1391+ ->expects ($ this ->any ())
1392+ ->method ('getParameters ' )
1393+ ->willReturn (array_fill (0 , 66 , $ p ));
1394+ $ queryBuilder
1395+ ->expects ($ this ->any ())
1396+ ->method ('getSQL ' )
1397+ ->willReturn ('SELECT * FROM FOO WHERE BAR IN (?) OR BAR IN (?) ' );
1398+ $ queryBuilder
1399+ ->expects ($ this ->once ())
1400+ ->method ('execute ' )
1401+ ->willReturn ($ this ->createMock (Result::class));
1402+ $ this ->logger
1403+ ->expects ($ this ->once ())
1404+ ->method ('logException ' )
1405+ ->willReturnCallback (function ($ e , $ parameters ) {
1406+ $ this ->assertInstanceOf (QueryException::class, $ e );
1407+ $ this ->assertSame (
1408+ 'The number of parameters must not exceed 65535. Restriction by PostgreSQL. ' ,
1409+ $ parameters ['message ' ]
1410+ );
1411+ });
1412+ $ this ->config
1413+ ->expects ($ this ->once ())
1414+ ->method ('getValue ' )
1415+ ->with ('log_query ' , false )
1416+ ->willReturn (false );
1417+
1418+ $ this ->invokePrivate ($ this ->queryBuilder , 'queryBuilder ' , [$ queryBuilder ]);
1419+ $ this ->queryBuilder ->execute ();
1420+ }
13451421}
0 commit comments