Code Duplication    Length = 17-20 lines in 5 locations

tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php 5 locations

@@ 327-346 (lines=20) @@
324
    /**
325
     * @group DBAL-713
326
     */
327
    public function testModifyLimitQueryWithSubSelectInSelectList()
328
    {
329
        $querySql = "SELECT " .
330
            "u.id, " .
331
            "(u.foo/2) foodiv, " .
332
            "CONCAT(u.bar, u.baz) barbaz, " .
333
            "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " .
334
            "FROM user u " .
335
            "WHERE u.status = 'disabled'";
336
        $alteredSql = "SELECT TOP 10 " .
337
            "u.id, " .
338
            "(u.foo/2) foodiv, " .
339
            "CONCAT(u.bar, u.baz) barbaz, " .
340
            "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " .
341
            "FROM user u " .
342
            "WHERE u.status = 'disabled'";
343
        $sql = $this->_platform->modifyLimitQuery($querySql, 10);
344
345
        self::assertEquals(sprintf(self::$selectFromCtePattern, $alteredSql, 1, 10), $sql);
346
    }
347
348
    /**
349
     * @group DBAL-713
@@ 380-396 (lines=17) @@
377
    /**
378
     * @group DBAL-834
379
     */
380
    public function testModifyLimitQueryWithAggregateFunctionInOrderByClause()
381
    {
382
        $querySql = "SELECT " .
383
            "MAX(heading_id) aliased, " .
384
            "code " .
385
            "FROM operator_model_operator " .
386
            "GROUP BY code " .
387
            "ORDER BY MAX(heading_id) DESC";
388
        $alteredSql = "SELECT TOP 1 " .
389
            "MAX(heading_id) aliased, " .
390
            "code " .
391
            "FROM operator_model_operator " .
392
            "GROUP BY code " .
393
            "ORDER BY MAX(heading_id) DESC";
394
        $sql = $this->_platform->modifyLimitQuery($querySql, 1, 0);
395
        self::assertEquals(sprintf(self::$selectFromCtePattern, $alteredSql, 1, 1), $sql);
396
    }
397
398
    /**
399
     * @throws \Doctrine\DBAL\DBALException
@@ 401-420 (lines=20) @@
398
    /**
399
     * @throws \Doctrine\DBAL\DBALException
400
     */
401
    public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable()
402
    {
403
        $querySql = "SELECT DISTINCT id_0, name_1 "
404
            . "FROM ("
405
            . "SELECT t1.id AS id_0, t2.name AS name_1 "
406
            . "FROM table_parent t1 "
407
            . "LEFT JOIN join_table t2 ON t1.id = t2.table_id "
408
            . "ORDER BY t1.id ASC"
409
            . ") dctrn_result "
410
            . "ORDER BY id_0 ASC";
411
        $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1 "
412
            . "FROM ("
413
            . "SELECT t1.id AS id_0, t2.name AS name_1 "
414
            . "FROM table_parent t1 "
415
            . "LEFT JOIN join_table t2 ON t1.id = t2.table_id"
416
            . ") dctrn_result "
417
            . "ORDER BY id_0 ASC";
418
        $sql = $this->_platform->modifyLimitQuery($querySql, 5);
419
        self::assertEquals(sprintf(self::$selectFromCtePattern, $alteredSql, 1, 5), $sql);
420
    }
421
422
423
    /**
@@ 426-445 (lines=20) @@
423
    /**
424
     * @throws \Doctrine\DBAL\DBALException
425
     */
426
    public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable()
427
    {
428
        $querySql = "SELECT DISTINCT id_0, name_1 "
429
            . "FROM ("
430
            . "SELECT t1.id AS id_0, t2.name AS name_1 "
431
            . "FROM table_parent t1 "
432
            . "LEFT JOIN join_table t2 ON t1.id = t2.table_id "
433
            . "ORDER BY t2.name ASC"
434
            . ") dctrn_result "
435
            . "ORDER BY name_1 ASC";
436
        $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1 "
437
            . "FROM ("
438
            . "SELECT t1.id AS id_0, t2.name AS name_1 "
439
            . "FROM table_parent t1 "
440
            . "LEFT JOIN join_table t2 ON t1.id = t2.table_id"
441
            . ") dctrn_result "
442
            . "ORDER BY name_1 ASC";
443
        $sql = $this->_platform->modifyLimitQuery($querySql, 5);
444
        self::assertEquals(sprintf(self::$selectFromCtePattern, $alteredSql, 1, 5), $sql);
445
    }
446
447
    /**
448
     * @throws \Doctrine\DBAL\DBALException
@@ 450-469 (lines=20) @@
447
    /**
448
     * @throws \Doctrine\DBAL\DBALException
449
     */
450
    public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables()
451
    {
452
        $querySql = "SELECT DISTINCT id_0, name_1, foo_2 "
453
            . "FROM ("
454
            . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 "
455
            . "FROM table_parent t1 "
456
            . "LEFT JOIN join_table t2 ON t1.id = t2.table_id "
457
            . "ORDER BY t2.name ASC, t2.foo DESC"
458
            . ") dctrn_result "
459
            . "ORDER BY name_1 ASC, foo_2 DESC";
460
        $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1, foo_2 "
461
            . "FROM ("
462
            . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 "
463
            . "FROM table_parent t1 "
464
            . "LEFT JOIN join_table t2 ON t1.id = t2.table_id"
465
            . ") dctrn_result "
466
            . "ORDER BY name_1 ASC, foo_2 DESC";
467
        $sql = $this->_platform->modifyLimitQuery($querySql, 5);
468
        self::assertEquals(sprintf(self::$selectFromCtePattern, $alteredSql, 1, 5), $sql);
469
    }
470
471
    public function testModifyLimitSubquerySimple()
472
    {