Symfony3 Unitests fails with the following error Undefined index: kernel
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.0/phpunit.xsd"
backupGlobals="false"
colors="true"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="app/autoload.php">
<php>
<ini name="error_reporting" value="-1" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
<env name="SHELL_VERBOSITY" value="-1" />
<env name="KERNEL_CLASS" value="AppKernel" />
<env name="DEFAULT_DB_DRIVER" value="pdo_mysql" />
<env name="DEFAULT_DB_HOST" value="mysql" />
<env name="DEFAULT_DB_NAME" value="db" />
<env name="DEFAULT_DB_USER" value="db" />
<env name="DEFAULT_DB_PASSWORD" value="db" />
<env name="MAIL_ENCRYPTION" value="ssl" />
<env name="MAIL_PORT" value="587" />
<env name="MAIL_SERVER" value="localhost" />
<env name="MAIL_USER" value="root" />
<env name="MAIL_PASSWORD" value="root" />
<env name="DEFAULT_DB_PORT" value="3306" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
<server name="KERNEL_DIR" value="app/" />
<server name="KERNEL_CLASS" value="AppKernel" />
<!-- define your env variables for the test env here -->
</php>
<testsuites>
<testsuite name="AmazonAPI Tests">
<directory>src/ProductInterfaceBundle/Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*Bundle/Resources</directory>
<directory>../src/*Bundle/Tests</directory>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\CoverageListener">
<arguments>
<null/>
<boolean>true</boolean>
</arguments>
</listener>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
</array>
</arguments>
</listener>
</listeners>
</phpunit>
and hier is my test class
use Namespace\ProductInterfaceBundle\Command\AmazonCommand;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
class AmazonCommandTest extends KernelTestCase
{
public function testExecute()
{
self::bootKernel();
$application = new Application(self::$kernel);
$application->add(new AmazonCommand());
$command = $application->find('vendor:amazon:submit
');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'command' => $command->getName(),
// pass arguments to the helper
'username' => 'Wouter',
));
$output = $commandTester->getDisplay();
$this->assertContains('Username: Wouter', $output);
}
}
What I'm missing in this case?
I guess you need to share more of you code: Where exactly is this errormessage thrown and what happens at this line?
Seems like there is an uninitialized array with the "kernel" key missing. But without code: I have no idea. So I guess: More code needed :-)
btw: You shall update your Symfony (I think 6.0 is latest) and PHPUnit (I think version 9.5 is latest)