Failed Conditions
Pull Request — develop (#3348)
by Sergei
63:22
created

DropSchemaSqlCollectorTest::testGivenForeignKeyWithZeroLengthAcceptForeignKeyThrowsException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Schema\Visitor;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
7
use Doctrine\DBAL\Schema\Table;
8
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector
13
 */
14
class DropSchemaSqlCollectorTest extends TestCase
15
{
16
    public function testGetQueriesUsesAcceptedForeignKeys() : void
17
    {
18
        $tableOne = $this->createMock(Table::class);
19
        $tableTwo = $this->createMock(Table::class);
20
21
        $keyConstraintOne = $this->getStubKeyConstraint('first');
22
        $keyConstraintTwo = $this->getStubKeyConstraint('second');
23
24
        $platform = $this->getMockBuilder(AbstractPlatform::class)
25
            ->setMethods(['getDropForeignKeySQL'])
26
            ->getMockForAbstractClass();
27
28
        $collector = new DropSchemaSqlCollector($platform);
29
30
        $platform->expects($this->exactly(2))
31
            ->method('getDropForeignKeySQL');
32
33
        $platform->expects($this->at(0))
34
            ->method('getDropForeignKeySQL')
35
            ->with($keyConstraintOne, $tableOne);
36
37
        $platform->expects($this->at(1))
38
            ->method('getDropForeignKeySQL')
39
            ->with($keyConstraintTwo, $tableTwo);
40
41
        $collector->acceptForeignKey($tableOne, $keyConstraintOne);
42
        $collector->acceptForeignKey($tableTwo, $keyConstraintTwo);
43
44
        $collector->getQueries();
45
    }
46
47
    private function getStubKeyConstraint(string $name) : ForeignKeyConstraint
48
    {
49
        $constraint = $this->createMock(ForeignKeyConstraint::class);
50
51
        $constraint->expects($this->any())
52
            ->method('getName')
53
            ->will($this->returnValue($name));
54
55
        $constraint->expects($this->any())
56
            ->method('getForeignColumns')
57
            ->will($this->returnValue([]));
58
59
        $constraint->expects($this->any())
60
            ->method('getColumns')
61
            ->will($this->returnValue([]));
62
63
        return $constraint;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $constraint returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Doctrine\DBAL\Schema\ForeignKeyConstraint.
Loading history...
64
    }
65
}
66