Completed
Pull Request — master (#3666)
by
unknown
61:37
created

AbstractOracleDriverTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
eloc 62
c 1
b 0
f 1
dl 0
loc 112
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testReturnsDatabaseName() 0 15 1
A testReturnsDatabaseNameWithConnectDescriptor() 0 17 1
A createDriver() 0 3 1
A getDatabasePlatformsForVersions() 0 17 1
A getExceptionConversionData() 0 33 1
A createSchemaManager() 0 3 1
A createPlatform() 0 3 1
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Driver;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Driver;
7
use Doctrine\DBAL\Driver\AbstractOracleDriver;
8
use Doctrine\DBAL\Platforms\AbstractPlatform;
9
use Doctrine\DBAL\Platforms\Oracle122Platform;
10
use Doctrine\DBAL\Platforms\OraclePlatform;
11
use Doctrine\DBAL\Schema\AbstractSchemaManager;
12
use Doctrine\DBAL\Schema\OracleSchemaManager;
13
14
class AbstractOracleDriverTest extends AbstractDriverTest
15
{
16
    public function testReturnsDatabaseName() : void
17
    {
18
        $params = [
19
            'user'     => 'foo',
20
            'password' => 'bar',
21
            'dbname'   => 'baz',
22
        ];
23
24
        $connection = $this->getConnectionMock();
25
26
        $connection->expects($this->once())
27
            ->method('getParams')
28
            ->will($this->returnValue($params));
29
30
        self::assertSame($params['user'], $this->driver->getDatabase($connection));
31
    }
32
33
    public function testReturnsDatabaseNameWithConnectDescriptor() : void
34
    {
35
        $params = [
36
            'user'             => 'foo',
37
            'password'         => 'bar',
38
            'connectionstring' => '(DESCRIPTION=' .
39
                '(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' .
40
                '(CONNECT_DATA=(SERVICE_NAME=baz)))',
41
        ];
42
43
        $connection = $this->getConnectionMock();
44
45
        $connection->expects($this->once())
46
            ->method('getParams')
47
            ->will($this->returnValue($params));
48
49
        self::assertSame($params['user'], $this->driver->getDatabase($connection));
50
    }
51
52
    protected function createDriver() : Driver
53
    {
54
        return $this->getMockForAbstractClass(AbstractOracleDriver::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockFor...actOracleDriver::class) returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Doctrine\DBAL\Driver.
Loading history...
55
    }
56
57
    protected function createPlatform() : AbstractPlatform
58
    {
59
        return new OraclePlatform();
60
    }
61
62
    protected function createSchemaManager(Connection $connection) : AbstractSchemaManager
63
    {
64
        return new OracleSchemaManager($connection);
65
    }
66
67
/**
68
     * {@inheritDoc}
69
     */
70
    protected function getDatabasePlatformsForVersions() : array
71
    {
72
        return [
73
            ['9', OraclePlatform::class],
74
            ['9.0.1.0', OraclePlatform::class],
75
            ['9.2.0.1', OraclePlatform::class],
76
            ['10', OraclePlatform::class],
77
            ['10.1.0.2', OraclePlatform::class],
78
            ['10.2.0.1', OraclePlatform::class],
79
            ['11', OraclePlatform::class],
80
            ['11.1.0.6', OraclePlatform::class],
81
            ['11.2.0.1', OraclePlatform::class],
82
            ['12.1', OraclePlatform::class],
83
            ['12.1.0.1', OraclePlatform::class],
84
            ['12.2', Oracle122Platform::class],
85
            ['12.2.0.1', Oracle122Platform::class],
86
            ['18.1.0', Oracle122Platform::class],
87
        ];
88
    }
89
    
90
    /**
91
     * {@inheritDoc}
92
     */
93
    protected static function getExceptionConversionData() : array
94
    {
95
        return [
96
            self::EXCEPTION_CONNECTION => [
97
                ['1017', null, null],
98
                ['12545', null, null],
99
            ],
100
            self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [
101
                ['2292', null, null],
102
            ],
103
            self::EXCEPTION_INVALID_FIELD_NAME => [
104
                ['904', null, null],
105
            ],
106
            self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [
107
                ['918', null, null],
108
                ['960', null, null],
109
            ],
110
            self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [
111
                ['1400', null, null],
112
            ],
113
            self::EXCEPTION_SYNTAX_ERROR => [
114
                ['923', null, null],
115
            ],
116
            self::EXCEPTION_TABLE_EXISTS => [
117
                ['955', null, null],
118
            ],
119
            self::EXCEPTION_TABLE_NOT_FOUND => [
120
                ['942', null, null],
121
            ],
122
            self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [
123
                ['1', null, null],
124
                ['2299', null, null],
125
                ['38911', null, null],
126
            ],
127
        ];
128
    }
129
}
130