Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError : Return value of DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver::getDatabase() must be of the type string, null returned #114

Closed
klodoma opened this issue Mar 2, 2020 · 3 comments · Fixed by #115

Comments

@klodoma
Copy link

klodoma commented Mar 2, 2020

<?php

namespace DAMA\DoctrineTestBundle\Doctrine\DBAL;

class StaticDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver

    /**
     * {@inheritdoc}
     */
    public function getDatabase(\Doctrine\DBAL\Connection $conn): string
    {
        return $this->underlyingDriver->getDatabase($conn);
    }

If you use an in-memory database
<env name="DATABASE_URL" value="sqlite:///:memory:"/>

then this leads to a type error:

TypeError : Return value of DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver::getDatabase() must be of the type string, null returned

A in memory sqlite goes in here and returns NULL and not string(has no path)


    /**
     * {@inheritdoc}
     */
    public function getDatabase(Connection $conn)
    {
        $params = $conn->getParams();

        return $params['path'] ?? null;
    }

Just changing

public function getDatabase(\Doctrine\DBAL\Connection $conn): ?string

fixes the issue.

@dmaicher
Copy link
Owner

dmaicher commented Mar 2, 2020

See #115

Indeed the AbstractSQLiteDriver may return null although the phpdoc annotates the method with return type string on the Driver interface 😕

https://github.com/doctrine/dbal/blob/2.11.x/lib/Doctrine/DBAL/Driver.php#L56

@dmaicher
Copy link
Owner

dmaicher commented Mar 2, 2020

new release 6.3.2 tagged 😉

@klodoma
Copy link
Author

klodoma commented Mar 2, 2020

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants