Replies: 1 comment 1 reply
-
By following the patterns of other bundles, I did the following, but I wonder if there's documentation anywhere about testing services within a bundle. in the xml <server name="KERNEL_CLASS" value="Survos\KeyValueBundle\Tests\Fixtures\TestKernel" />
<server name="KERNEL_DIR" value="tests/Fixtures/" /> Then create the files:
<?php
// TestKernel.php
namespace Survos\KeyValueBundle\Tests\Fixtures;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
class TestKernel extends Kernel
{
public function registerBundles(): iterable
{
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Survos\KeyValueBundle\SurvosKeyValueBundle(),
];
}
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config/config.yml');
}
public function getProjectDir(): string
{
return __DIR__;
}
} # Fixtures/config/config.yml
framework:
test: true
annotations: false
survos_key_value:
directory: /home/tac/g/sites/headlines/data There's probably more and maybe a better way to do it, but now I have bundle tests that extend the TestKernel. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
phpunit testing works fine from within an application, but when trying to run the same tests within the bundle I get an error about the KERNEL_CLASS.
Since I don't have a kernel class in the bundle like I do in the application, what should it be set to?
├ LogicException: You must set the KERNEL_CLASS environment variable to the fully-qualified class name of your Kernel in phpunit.xml / phpunit.xml.dist or override the "Survos\KeyValueBundle\Tests\KeyValueTest::createKernel()" or "Survos\KeyValueBundle\Tests\KeyValueTest::getKernelClass()" method.
I'm using phpunit 10. I've had a hard time finding documentation for testing bundles, especially with newer versions of Symfony and phpunit.
Thx.
Beta Was this translation helpful? Give feedback.
All reactions