title: Error: Cannot instantiate interface symfony when unit testing
body: <p>I'm trying to do a unit test for a signup method and im following this <a href="https://symfony.com/doc/master/testing/database.html#mocking-the-repository-in-a-unit-test" rel="nofollow noreferrer">guide</a>. I'm fairly new to unit testing. </p>
  
  <p>i keep getting </p>
  
  <blockquote>
    <p>1) App\Tests\Controller\SignUpControllerTest::testSignUp Error: Cannot
    instantiate interface
    Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface</p>
    
    <p>/Applications/MAMP/htdocs/my_project/tests/Controller/SignUpControllerTest.php:19</p>
  </blockquote>
  
  <p>I just don't think im doing this unit test right. Here is what i have. I'm not sure on what im doing. All i want to do is test the signup method. </p>
  
  <p><strong>UserController.php</strong></p>
  
  <pre><code>public function signup(Request $request, UserPasswordEncoderInterface $passwordEncoder )
  {
      $user = new User();
  
      $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
  
      $user-&gt;setEmail($request-&gt;get('email'));
      $user-&gt;setPlainPassword($request-&gt;get('password'));
      $user-&gt;setUsername($request-&gt;get('username'));
      $password = $passwordEncoder-&gt;encodePassword($user, $user-&gt;getPlainPassword());
      $user-&gt;setPassword($password);
  
      $entityManager-&gt;persist($user);
      $entityManager-&gt;flush();
  
      return $this-&gt;redirectToRoute('login');
  
  
  
  }
  </code></pre>
  
  <p><strong>SignUpControllerTest.php</strong> </p>
  
  <pre><code>namespace App\Tests\Controller;
  
  use App\Entity\Product;
  use App\Controller\UserController;
  use App\Entity\User;
  use Doctrine\Common\Persistence\ObjectManager;
  use Doctrine\Common\Persistence\ObjectRepository;
  use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
  
  class SignUpControllerTest extends WebTestCase
  {
  
      public function testSignUp()
      {   
          $passwordEncoder = new UserPasswordEncoderInterface();
          $user = new User();
          $user-&gt;setEmail('janedoe123@aol.com');
          $user-&gt;setPlainPassword('owlhunter');
          $user-&gt;setUsername('BarnMan');
          $password = $passwordEncoder-&gt;encodePassword($user, $user-&gt;getPlainPassword());
          $user-&gt;setPassword($password);
  
          $userRepository = $this-&gt;createMock(ObjectRepository::class);
          $userRepository-&gt;expects($this-&gt;any())
              -&gt;method('find')
              -&gt;willReturn($user);
  
  
          $objectManager = $this-&gt;createMock(ObjectManager::class);
          // use getMock() on PHPUnit 5.3 or below
          // $objectManager = $this-&gt;getMock(ObjectManager::class);
          $objectManager-&gt;expects($this-&gt;any())
              -&gt;method('getRepository')
              -&gt;willReturn($userRepository);
  
          $userController = new UserController($objectManager);
          $this-&gt;assertEquals(2100, $userController-&gt;signupTest());
  
      }
  
  
  }
  </code></pre>