Skip to content

Instantly share code, notes, and snippets.

@RajithaKumara
Last active November 15, 2018 10:26
Show Gist options
  • Save RajithaKumara/cb2c52b0ad93fb90f7f757159211b4e4 to your computer and use it in GitHub Desktop.
Save RajithaKumara/cb2c52b0ad93fb90f7f757159211b4e4 to your computer and use it in GitHub Desktop.
Repository testing for DAO layer. Boot the kernel is required to get a valid database connection.
<?php
namespace App\Tests\Repository;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class UserRepositoryTest extends KernelTestCase
{
/**
* @var \Doctrine\ORM\EntityManager
*/
private $entityManager;
protected function setUp()
{
$kernel = self::bootKernel();
$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
}
public function testUserFindAll()
{
$users = $this->entityManager
->getRepository(User::class)
->findAll()
;
// compare asserts
//$this->assertCount(10, $users);
$this->assertTrue(true);
}
protected function tearDown()
{
parent::tearDown();
$this->entityManager->close();
$this->entityManager = null; // avoid memory leaks
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment