title: How to mock service with symfony 4 in functional tests?
body: <p>I have an commandbus handler, which injects some service:</p>
  
  <pre><code>class SomeHandler
  {
      private $service;
  
      public function __construct(SomeService $service)
      {
          $this-&gt;service = $service;
      }
  
      public test(CommandTest $command)
      {
          $this-&gt;service-&gt;doSomeStuff();
      }
  }
  </code></pre>
  
  <p>SomeService has method doSomeStuff with external calls, which I want not to use during testing.</p>
  
  <pre><code>class SomeService
  {
      private $someBindedVariable;
  
      public function __construct($someBindedVariable)
      {
          $this-&gt;someBindedVariable = $someBindedVariable;
      }
  
      public function doSomeStuff()
      {
          //TODO: some stuff
      }
  }
  </code></pre>
  
  <p>There is in the test I try to replace service with mock object</p>
  
  <pre><code>public function testTest()
  {
      $someService = $this-&gt;getMockBuilder(SomeService::class)-&gt;getMock();
      $this-&gt;getContainer()-&gt;set(SomeService::class, $someService);
  
      //TODO: functional test for the route, which uses SomeHandler
  }
  </code></pre>
  
  <p>The first problem is this code will throws exception "The "App\Service\SomeService" service is private, you cannot replace it."</p>
  
  <p>Ok, let's try to make it public:</p>
  
  <p>services.yaml:</p>
  
  <pre><code>App\Service\SomeService:
      public: true
      arguments:
          $someBindedVariable: 200
  </code></pre>
  
  <p>But it doesn't help. I get response from native SomeService. Let's try with aliases:</p>
  
  <pre><code>some_service:
      class: App\Service\SomeService
      public: true
      arguments:
          $someBindedVariable: 200
  
  App\Service\SomeService:
      alias: some_service
  </code></pre>
  
  <p>And again the mock object does not use by test. I see response from native SomeService.</p>
  
  <p>I tried to append autowire option, but it did not help.</p>
  
  <p>What should I do to replace my SomeService with some mock object all over the project during test?</p>