Issues (201)

tests/Functional/Driver/AbstractDriverTest.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Tests\Functional\Driver;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\DBAL\Driver;
9
use Doctrine\DBAL\Tests\FunctionalTestCase;
10
11
abstract class AbstractDriverTest extends FunctionalTestCase
12
{
13
    /**
14
     * The driver instance under test.
15
     *
16
     * @var Driver
17
     */
18
    protected $driver;
19
20
    protected function setUp() : void
21
    {
22
        parent::setUp();
23
24
        $this->driver = $this->createDriver();
25
    }
26
27
    /**
28
     * @group DBAL-1215
29
     */
30
    public function testConnectsWithoutDatabaseNameParameter() : void
31
    {
32
        $params = $this->connection->getParams();
33
        unset($params['dbname']);
34
35
        $user     = $params['user'] ?? '';
36
        $password = $params['password'] ?? '';
37
38
        $this->expectNotToPerformAssertions();
39
        $this->driver->connect($params, $user, $password);
40
    }
41
42
    /**
43
     * @group DBAL-1215
44
     */
45
    public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void
46
    {
47
        $params = $this->connection->getParams();
48
        unset($params['dbname']);
49
50
        $connection = new Connection(
51
            $params,
52
            $this->connection->getDriver(),
53
            $this->connection->getConfiguration(),
54
            $this->connection->getEventManager()
55
        );
56
57
        self::assertSame(
58
            static::getDatabaseNameForConnectionWithoutDatabaseNameParameter(),
0 ignored issues
show
Are you sure the usage of static::getDatabaseNameF...DatabaseNameParameter() targeting Doctrine\DBAL\Tests\Func...DatabaseNameParameter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
59
            $connection->getDatabase()
60
        );
61
    }
62
63
    abstract protected function createDriver() : Driver;
64
65
    protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
66
    {
67
        return null;
68
    }
69
}
70