Code Duplication    Length = 34-35 lines in 3 locations

tests/Doctrine/Tests/DBAL/ConnectionTest.php 3 locations

@@ 502-536 (lines=35) @@
499
        );
500
    }
501
502
    public function testFetchAssoc() : void
503
    {
504
        $statement = 'SELECT * FROM foo WHERE bar = ?';
505
        $params    = [666];
506
        $types     = [ParameterType::INTEGER];
507
        $result    = [];
508
509
        $driverMock = $this->createMock(Driver::class);
510
511
        $driverMock->expects($this->any())
512
            ->method('connect')
513
            ->will($this->returnValue(
514
                $this->createMock(DriverConnection::class)
515
            ));
516
517
        $driverStatementMock = $this->createMock(Statement::class);
518
519
        $driverStatementMock->expects($this->once())
520
            ->method('fetch')
521
            ->with(FetchMode::ASSOCIATIVE)
522
            ->will($this->returnValue($result));
523
524
        /** @var Connection|MockObject $conn */
525
        $conn = $this->getMockBuilder(Connection::class)
526
            ->onlyMethods(['executeQuery'])
527
            ->setConstructorArgs([[], $driverMock])
528
            ->getMock();
529
530
        $conn->expects($this->once())
531
            ->method('executeQuery')
532
            ->with($statement, $params, $types)
533
            ->will($this->returnValue($driverStatementMock));
534
535
        self::assertSame($result, $conn->fetchAssoc($statement, $params, $types));
536
    }
537
538
    public function testFetchArray() : void
539
    {
@@ 538-572 (lines=35) @@
535
        self::assertSame($result, $conn->fetchAssoc($statement, $params, $types));
536
    }
537
538
    public function testFetchArray() : void
539
    {
540
        $statement = 'SELECT * FROM foo WHERE bar = ?';
541
        $params    = [666];
542
        $types     = [ParameterType::INTEGER];
543
        $result    = [];
544
545
        $driverMock = $this->createMock(Driver::class);
546
547
        $driverMock->expects($this->any())
548
            ->method('connect')
549
            ->will($this->returnValue(
550
                $this->createMock(DriverConnection::class)
551
            ));
552
553
        $driverStatementMock = $this->createMock(Statement::class);
554
555
        $driverStatementMock->expects($this->once())
556
            ->method('fetch')
557
            ->with(FetchMode::NUMERIC)
558
            ->will($this->returnValue($result));
559
560
        /** @var Connection|MockObject $conn */
561
        $conn = $this->getMockBuilder(Connection::class)
562
            ->onlyMethods(['executeQuery'])
563
            ->setConstructorArgs([[], $driverMock])
564
            ->getMock();
565
566
        $conn->expects($this->once())
567
            ->method('executeQuery')
568
            ->with($statement, $params, $types)
569
            ->will($this->returnValue($driverStatementMock));
570
571
        self::assertSame($result, $conn->fetchArray($statement, $params, $types));
572
    }
573
574
    public function testFetchColumn() : void
575
    {
@@ 611-644 (lines=34) @@
608
        self::assertSame($result, $conn->fetchColumn($statement, $params, $column, $types));
609
    }
610
611
    public function testFetchAll() : void
612
    {
613
        $statement = 'SELECT * FROM foo WHERE bar = ?';
614
        $params    = [666];
615
        $types     = [ParameterType::INTEGER];
616
        $result    = [];
617
618
        $driverMock = $this->createMock(Driver::class);
619
620
        $driverMock->expects($this->any())
621
            ->method('connect')
622
            ->will($this->returnValue(
623
                $this->createMock(DriverConnection::class)
624
            ));
625
626
        $driverStatementMock = $this->createMock(Statement::class);
627
628
        $driverStatementMock->expects($this->once())
629
            ->method('fetchAll')
630
            ->will($this->returnValue($result));
631
632
        /** @var Connection|MockObject $conn */
633
        $conn = $this->getMockBuilder(Connection::class)
634
            ->onlyMethods(['executeQuery'])
635
            ->setConstructorArgs([[], $driverMock])
636
            ->getMock();
637
638
        $conn->expects($this->once())
639
            ->method('executeQuery')
640
            ->with($statement, $params, $types)
641
            ->will($this->returnValue($driverStatementMock));
642
643
        self::assertSame($result, $conn->fetchAll($statement, $params, $types));
644
    }
645
646
    public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() : void
647
    {