for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace AppBundle\Tests;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
abstract class KernelDbTestCase extends KernelTestCase
{
protected $entityManager;
protected $application;
protected function setUp()
self::bootKernel();
$this->application = new Application(self::$kernel);
$this->application->setAutoExit(false);
$this->execute('doctrine:database:drop --force --no-interaction');
$this->execute('doctrine:database:create --no-interaction');
$this->execute('doctrine:schema:create --no-interaction');
$this->execute('doctrine:fixtures:load --no-interaction');
$this->container = static::$kernel->getContainer();
container
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->entityManager = $this->container->get('doctrine')->getManager();
}
protected function execute($command)
$input = new StringInput($command);
$output = new NullOutput();
$this->application->run($input, $output);
protected function tearDown()
parent::tearDown();
$this->entityManager->close();
$this->entityManager = null; // avoid memory leaks
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: