title: test a repository in symfony
body: <p>I have the following method in my repository and I want to test it</p>
  
  <pre><code>public function myFindOne($id)
  {
  // On passe par le QueryBuilder vide de l'EntityManager pour l'exemple
    $qb = $this-&gt;_em-&gt;createQueryBuilder();
  
    $qb-&gt;select('a')
       -&gt;from('xxxBundle:entity', 'a')
       -&gt;where('a.id = :id')
       -&gt;setParameter('id', $id);
  
      return $qb-&gt;getQuery()
                -&gt;getResult();}
  </code></pre>
  
  <p>I found the following code in the documentation, but I could not understand it</p>
  
  <pre><code>// src/Acme/StoreBundle/Tests/Entity/ProductRepositoryFunctionalTest.php
  namespace Acme\StoreBundle\Tests\Entity;
  
  use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  
  class ProductRepositoryFunctionalTest extends WebTestCase
  {
      /**
       * @var \Doctrine\ORM\EntityManager
       */
      private $em;
  
      /**
       * {@inheritDoc}
       */
      public function setUp()
      {
          static::$kernel = static::createKernel();
          static::$kernel-&gt;boot();
          $this-&gt;em = static::$kernel-&gt;getContainer()
              -&gt;get('doctrine')
              -&gt;getManager()
          ;
      }
  
      public function testSearchByCategoryName()
      {
          $products = $this-&gt;em
              -&gt;getRepository('AcmeStoreBundle:Product')
              -&gt;searchByCategoryName('foo')
          ;
  
          $this-&gt;assertCount(1, $products);
      }
  
      /**
       * {@inheritDoc}
       */
      protected function tearDown()
      {
          parent::tearDown();
          $this-&gt;em-&gt;close();
      }
  }
  </code></pre>