Failed Conditions
Push — master ( a2450f...eb80fc )
by Sergei
138:46 queued 138:40
created

DropSchemaSqlCollectorTest::getTableMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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