Failed Conditions
Pull Request — develop (#3581)
by Jonathan
12:44
created

DropSchemaSqlCollectorTest::testGivenForeignKeyWithZeroLengthAcceptForeignKeyThrowsException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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