Failed Conditions
Pull Request — master (#3033)
by Aleksey
15:03
created

AbstractSQLServerDriverTest::getDriver()   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\Driver;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
7
use Doctrine\DBAL\Driver\Connection as DriverConnection;
8
use Doctrine\DBAL\Platforms\SQLServer2008Platform;
9
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
10
11
class AbstractSQLServerDriverTest extends AbstractDriverTest
12
{
13
    protected function createDriver()
14
    {
15
        return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractSQLServerDriver');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockFor...stractSQLServerDriver') returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the return type mandated by Doctrine\Tests\DBAL\Driv...verTest::createDriver() of Doctrine\DBAL\Driver.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
16
    }
17
18
    protected function createPlatform()
19
    {
20
        return new SQLServer2008Platform();
21
    }
22
23
    protected function createSchemaManager(Connection $connection)
24
    {
25
        return new SQLServerSchemaManager($connection);
26
    }
27
28
    protected function getDatabasePlatformsForVersions()
29
    {
30
        return array(
31
            array('9', 'Doctrine\DBAL\Platforms\SQLServerPlatform'),
32
            array('9.00', 'Doctrine\DBAL\Platforms\SQLServerPlatform'),
33
            array('9.00.0', 'Doctrine\DBAL\Platforms\SQLServerPlatform'),
34
            array('9.00.1398', 'Doctrine\DBAL\Platforms\SQLServerPlatform'),
35
            array('9.00.1398.99', 'Doctrine\DBAL\Platforms\SQLServerPlatform'),
36
            array('9.00.1399', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'),
37
            array('9.00.1399.0', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'),
38
            array('9.00.1399.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'),
39
            array('9.00.1400', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'),
40
            array('9.10', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'),
41
            array('9.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'),
42
            array('10.00.1599', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'),
43
            array('10.00.1599.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'),
44
            array('10.00.1600', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'),
45
            array('10.00.1600.0', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'),
46
            array('10.00.1600.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'),
47
            array('10.00.1601', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'),
48
            array('10.10', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'),
49
            array('10.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'),
50
            array('11.00.2099', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'),
51
            array('11.00.2099.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'),
52
            array('11.00.2100', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'),
53
            array('11.00.2100.0', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'),
54
            array('11.00.2100.99', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'),
55
            array('11.00.2101', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'),
56
            array('12', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'),
57
        );
58
    }
59
60
    protected function getDriver() : AbstractSQLServerDriver
61
    {
62
        return static::createDriver();
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::createDriver() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Doctrine\DBAL\Driver\AbstractSQLServerDriver.
Loading history...
Bug Best Practice introduced by
The method Doctrine\Tests\DBAL\Driv...verTest::createDriver() is not static, but was called statically. ( Ignorable by Annotation )

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

62
        return static::/** @scrutinizer ignore-call */ createDriver();
Loading history...
63
    }
64
65
    protected function checkForSkippingTest(AbstractSQLServerDriver $driver) : void
66
    {
67
        $this->markTestSkipped('The test is only for the sqlsrv and the pdo_sqlsrv drivers');
68
    }
69
70
    /**
71
     * @param mixed[] $driverOptions
72
     */
73
    protected function getConnection(AbstractSQLServerDriver $driver, array $driverOptions) : DriverConnection
74
    {
75
        return $driver->connect(
76
            [
77
                'host' => $GLOBALS['db_host'],
78
                'port' => $GLOBALS['db_port'],
79
            ],
80
            $GLOBALS['db_username'],
81
            $GLOBALS['db_password'],
82
            $driverOptions
83
        );
84
    }
85
86
    public function testConnectionOptions() : void
87
    {
88
        $driver = $this->getDriver();
89
        $this->checkForSkippingTest($driver);
90
        $connection = $this->getConnection($driver, ['APP' => 'APP_NAME']);
91
        $result     = $connection->query('select APP_NAME() as app')->fetch();
92
93
        self::assertSame('APP_NAME', $result['app']);
94
    }
95
}
96