title: How to inject interfaces (not class) in symfony3?
body: <p>I have a problem with Symfony DependencyInjection Component. I want to inject interfaces into controllers, so I could only use interface methods. But, I notice I can use any public method from class that implement the interface and this is wrong. I follow the great article: <a href="http://php-and-symfony.matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager/" rel="nofollow noreferrer">http://php-and-symfony.matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager/</a></p>
  
  <p><strong>Write the test service class and interface</strong></p>
  
  <pre><code>interface ITestService
  {
      public function interfaceFunction();
  }
  
  class TestService implements ITestService
  {
      public function interfaceFunction() {/* do somenthing */}
  
      public function classFunction() {/*do somenthing*/}
  }
  </code></pre>
  
  <p><strong>Configure my application service class as a service (test_service)</strong></p>
  
  <pre><code># file: app/config/services.yml
  test_service:
      class: MyApp\Application\Services\TestService
  </code></pre>
  
  <p><strong>Configure my controller as a service:</strong></p>
  
  <pre><code># file: app/config/services.yml
  test_controller:
      class: MyApp\AppBundle\Controller\TestController
      arguments:
          - '@test_service'
  </code></pre>
  
  <p><strong>Using service in controller</strong></p>
  
  <pre><code>class TestController extends Controller
  {
      private testService;
  
      function _construct(ITestService $testService)
      {
          $this-&gt;testService = $testService;
      }
  
      public function indexAction()
      {
          // This should be inaccesible but it works :(
          $this-&gt;testService-&gt;classFunction();
  
          // This is the only function I should use.
          $this-&gt;testService-&gt;interfaceFunction();
      }
  </code></pre>