Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Empty testcase - Database error #135

Open
do-web opened this issue Nov 20, 2020 · 7 comments
Open

Empty testcase - Database error #135

do-web opened this issue Nov 20, 2020 · 7 comments

Comments

@do-web
Copy link

do-web commented Nov 20, 2020

I have create a empty test case with typo3 9.x with composer and ddev and iam getting an error:

Maybe the .env is not loaded here with the database config?

There was 1 error:

1) MyExt\MyExt\Controller\FunctionalTest::testCheck
Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: No such file or directory

/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:93
/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169
/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:157
/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php:18
@IchHabRecht
Copy link
Contributor

Hi @do-web,

Thank you for your issue. As you don't tell anything about how you run your functional test, I fear it is quite difficult to help here. But the testing-framework doesn't know anything about your .env file by default.

@do-web
Copy link
Author

do-web commented Nov 20, 2020

ok, but why does it try to establish a database connection?

class FunctionalTest extends FunctionalTestCase
{
    /**
     * @var array
     */
    protected $testExtensionsToLoad = [
        'typo3conf/ext/my_ext',
    ];

    protected function setUp()
    {
        parent::setUp();
    }

    public function testCheck()
    {
        $this->assertFalse(false);
    }
}

@IchHabRecht
Copy link
Contributor

Hi @do-web,

Because database connection is needed to be set up for functional testing.

@do-web
Copy link
Author

do-web commented Nov 20, 2020

How can i load the real db instance from typo3 in the test?

@IchHabRecht
Copy link
Contributor

IchHabRecht commented Nov 20, 2020

This isn't possible due to functional testing is designed in TYPO3. The functional tests are always executed in an own instance with an own database being set up. You need to provide the data your tests expect to find in the database by using ->importDataSet() within your setUp method.

@do-web
Copy link
Author

do-web commented Nov 20, 2020

And if is use the normal UnitTestCase?

@IchHabRecht
Copy link
Contributor

Maybe you want to share what you want to test so I can help you? Not sure what you need to do so it's hard to tell which approach to choose.

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

No branches or pull requests

2 participants