I'm new to autonomous bundle creation and follow this tutorial of symfonyCast. I'd like to test my bundle (which is also new for me) and I'm blocked at the service testing.
One of my service has the @translator
as an argument. Usually this translator is enabled in the App\Package\framework.yaml
file as such:
framework:
translator:
enable: true
But here i'm in testing mode of a bundle so I'm not sure I need to add a Package/framework.yaml
file. Is possible to just inject this information in my config ?
you'll find here my test file:
namespace Btba\ChatBundle\Tests;
use Btba\ChatBundle\BtbaChatBundle;
use Btba\ChatBundle\Controller\ChatController;
use Btba\ChatBundle\Form\ChatMessageType;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
class ChatTest extends TestCase
{
public function testServiceWiringWithConfiguration()
{
$kernel = new BtbaChatTestingKernel([
'update_interval' => 1000,
'message_class' => 'App\Entity\Message.php',
'author_class' => 'App\Entity\Author.php'
]);
$kernel->boot();
$container = $kernel->getContainer();
//test services
$type = $container->get('btba_chat.type');
$this->assertInstanceOf(ChatMessageType::class, $type);
$controller = $container->get('btba_chat.controller');
$this->assertInstanceOf(ChatController::class, $controller);
}
}
class BtbaChatTestingKernel extends Kernel
{
private $btbaChatConfig;
public function __construct(array $btbaChatConfig = [])
{
$this->btbaChatConfig = $btbaChatConfig;
parent::__construct('test', true);
}
public function registerBundles()
{
return [
new BtbaChatBundle()
];
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container) {
$container->loadFromExtension('btba_chat', $this->btbaChatConfig);
});
}
}