title: Symfony 2 Service Error on unit Testing
body: <p>I make some functional test with Symfony 2 and phpunit.</p>
  
  <p>But i've some trouble with a Service.
  Let me explain.
  During my run test, i want to use some service used by the application. So i juste set my setUp function for setting the kernel :</p>
  
  <pre><code>    static::$kernel = static::createKernel();
      static::$kernel-&gt;boot();
      $this-&gt;objectFactory = static::$kernel-&gt;getContainer()-&gt;get('some.application.objectfactory');
  </code></pre>
  
  <p>So i've this  and in my function i need to used a service that return an object so i call my service like that</p>
  
  <pre><code>$var = $this-&gt;objectFactory-&gt;getObject($id);
  </code></pre>
  
  <p>and obviously in my tearDown function i just :</p>
  
  <pre><code>    protected function tearDown()
  {
      $this-&gt;client-&gt;restart();
      unset($this-&gt;client, $this-&gt;objectFactory);
  }
  </code></pre>
  
  <p>So my problem is when i run a test i've this message  :</p>
  
  <blockquote>
    <p>Symfony\Component\DependencyInjection\Exception\InactiveScopeException: You cannot create a service ("request") of an inactive scope ("request").</p>
  </blockquote>
  
  <p>And i can't find a way to solve this.
  Did someone have any idea ??</p>
  
  <p>My version of Symfony is 2.2.1 and my version of phpunit is 3.7.19</p>
  
  <p>If someone can help me, i could be very happy.</p>
  
  <p>I'm sorry if my English isn't so good. </p>
  
  <p><hr>EDIT<hr>
  <br /> Maybe it could help someone, in the service i used that : : </p>
  
  <pre><code>        $request = $this-&gt;container-&gt;get('request');
  </code></pre>
  
  <p>It seems to be the reason why it dosen't work, when i remove it, it doesn't say the error, but they still doesn't work.</p>
  
  <p><hr>EDIT<hr>
  @Cyprian
  According to you have change my code for what i want.
  So i just add to my service, in the function that i want, the client (Client web test case), and then inside the function i just add this :</p>
  
  <pre><code>if (isset($client)) {
          $request = $client-&gt;getRequest();
      } else {
          $request = $this-&gt;container-&gt;get('request');
      }
  </code></pre>
  
  <p>So in my function where i call the service i've just this :</p>
  
  <pre><code>    public function getObject($id)
  {
      //Get the service from the kernel
      $service = static::$kernel-&gt;getContainer()-&gt;get('service');
      $object = $service-&gt;getObject($id, $this-&gt;client);
  }
  </code></pre>
  
  <p>and it works fine like this</p>
  
  <p>@nifr 
  Your idea doesn't work for me, but i think your idea wasn't wrong, they just not works in my case</p>
  
  <p>However Thanks for your help, i'm happy i works now, and i expect that post could help someone else</p>