testing-framework icon indicating copy to clipboard operation
testing-framework copied to clipboard

Empty testcase - Database error

Open do-web opened this issue 5 years ago • 7 comments

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

do-web avatar Nov 20 '20 13:11 do-web

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.

IchHabRecht avatar Nov 20 '20 14:11 IchHabRecht

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);
    }
}

do-web avatar Nov 20 '20 14:11 do-web

Hi @do-web,

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

IchHabRecht avatar Nov 20 '20 14:11 IchHabRecht

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

do-web avatar Nov 20 '20 15:11 do-web

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.

IchHabRecht avatar Nov 20 '20 15:11 IchHabRecht

And if is use the normal UnitTestCase?

do-web avatar Nov 20 '20 15:11 do-web

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.

IchHabRecht avatar Nov 20 '20 15:11 IchHabRecht