Nimut / testing-framework

TYPO3 testing framework that provides base classes and configuration for PHPUnit tests
GNU General Public License v2.0
52 stars 25 forks source link

Empty testcase - Database error #135

Open do-web opened 3 years ago

do-web commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Hi @do-web,

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

do-web commented 3 years ago

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

IchHabRecht commented 3 years ago

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 commented 3 years ago

And if is use the normal UnitTestCase?

IchHabRecht commented 3 years ago

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.