« Introduction au test logiciel/Tests unitaires/PHPUnit » : différence entre les versions

Contenu supprimé Contenu ajouté
Ligne 206 :
 
Avec Symfony, il existe aussi Panther<ref>https://github.com/symfony/panther</ref>.
 
== Symfony ==
Pour récupérer une variable d'environnement ou un service dans un test unitaire Symfony, il faut passer par <code>setUpBeforeClass()</code> pour booter le kernel du framework :
 
<source lang=php>
/** @var string */
private static $maVariableYaml;
/** @var Translator */
private static $translator;
 
public static function setUpBeforeClass(): void
{
$kernel = static::createKernel();
$kernel->boot();
 
self::$maVariableYaml = $kernel->getContainer()->getParameter('ma_variable');
self::$translator = $kernel->getContainer()->get('translator');
}
</source>
 
== Références ==