Passed
Push — drop-deprecated ( db0b1f )
by Michael
27:00
created

DB2SchemaManagerTest::testSettingNullExpressionWillResetCallable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 35
rs 9.6
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;
6
7
use Doctrine\Common\EventManager;
8
use Doctrine\DBAL\Configuration;
9
use Doctrine\DBAL\Connection;
10
use Doctrine\DBAL\Driver;
11
use Doctrine\DBAL\Platforms\DB2Platform;
12
use Doctrine\DBAL\Schema\DB2SchemaManager;
13
use PHPUnit\Framework\MockObject\MockObject;
14
use PHPUnit\Framework\TestCase;
15
use function in_array;
16
use function preg_match;
17
18
/**
19
 * @covers \Doctrine\DBAL\Schema\DB2SchemaManager
20
 */
21
final class DB2SchemaManagerTest extends TestCase
22
{
23
    /** @var Connection|MockObject */
24
    private $conn;
25
26
    /** @var DB2SchemaManager */
27
    private $manager;
28
29
    protected function setUp() : void
30
    {
31
        $eventManager = new EventManager();
32
        $driverMock   = $this->createMock(Driver::class);
33
        $platform     = $this->createMock(DB2Platform::class);
34
        $this->conn   = $this
35
            ->getMockBuilder(Connection::class)
36
            ->setMethods(['fetchAll', 'getUsername'])
37
            ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager])
38
            ->getMock();
39
40
        $this->conn->expects($this->any())
41
            ->method('getUsername')
42
            ->willReturn('db2inst1');
43
44
        $this->manager = new DB2SchemaManager($this->conn);
45
    }
46
47
    /**
48
     * @see https://github.com/doctrine/dbal/issues/2701
49
     *
50
     * @return void
51
     *
52
     * @group DBAL-2701
53
     */
54
    public function testListTableNamesFiltersAssetNamesCorrectly()
55
    {
56
        $this->conn->getConfiguration()->setSchemaAssetsFilter(static function (string $name) : bool {
0 ignored issues
show
Bug introduced by
The method getConfiguration() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $this->conn->/** @scrutinizer ignore-call */ 
57
                     getConfiguration()->setSchemaAssetsFilter(static function (string $name) : bool {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
            return preg_match('/^(?!T_)/', $name) === 1;
58
        });
59
        $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Doctrine\DBAL\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        $this->conn->/** @scrutinizer ignore-call */ 
60
                     expects($this->once())->method('fetchAll')->will($this->returnValue([

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
            ['name' => 'FOO'],
61
            ['name' => 'T_FOO'],
62
            ['name' => 'BAR'],
63
            ['name' => 'T_BAR'],
64
        ]));
65
66
        self::assertSame(
67
            [
68
                'FOO',
69
                'BAR',
70
            ],
71
            $this->manager->listTableNames()
72
        );
73
    }
74
75
    /**
76
     * @return void
77
     */
78
    public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable()
79
    {
80
        $accepted = ['T_FOO', 'T_BAR'];
81
        $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) {
82
            return in_array($assetName, $accepted);
83
        });
84
85
        $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([
86
            ['name' => 'FOO'],
87
            ['name' => 'T_FOO'],
88
            ['name' => 'BAR'],
89
            ['name' => 'T_BAR'],
90
        ]));
91
92
        self::assertSame(
93
            [
94
                'T_FOO',
95
                'T_BAR',
96
            ],
97
            $this->manager->listTableNames()
98
        );
99
    }
100
}
101