title: max connection MySql reached during tests
body: <p>When i launch my PHPUnit test suite i reached the max connection limit (200) for MySQL.</p>
  
  <p>The hot fix was to set max_connection to 500, but i'm looking for a better solution in Zend Framework 2 context.</p>
  
  <p>I tried to put some tearDown method, but no luck it seems to be useless or imcomplete solution.</p>
  
  <p>This is a sample of code :</p>
  
  <pre><code>protected function tearDown()
  {
      // i have two entitymanager
      $this-&gt;getObjectManager()-&gt;get('doctrine.connection.orm_alternate')-&gt;close();
      $this-&gt;getObjectManager()-&gt;get('doctrine.connection.orm_default')-&gt;close();
      $this-&gt;application = null;
      gc_collect_cycles();
      parent::tearDown();
  }
  </code></pre>
  
  <p>I also tried to use processIsolation turn to true but some test are so long that i assumed that my console has froze or something like that....</p>
  
  <p><strong>With doctrine2 connection, and Zend Framework, how can I prevent this "Too many connection" during PHPunit tests ?</strong></p>
  
  <p>so far with tips of @awons i tried to modify
  <code>$this-&gt;getObjectManager()-&gt;get('doctrine.connection.orm_alternate')-&gt;close();</code></p>
  
  <p>to 
  <code>$this-&gt;getObjectManager()-&gt;get('doctrine.entitymanager.orm_alternate')-&gt;close();</code></p>
  
  <p>I checked if teardown was called, yes.</p>
  
  <p>Something i don't understand is : on each test, a new instance of my connections are created, why this is not the same instance ? (like singleton or Registry) ?
  But this instance is never closed even it's not used after the test passed.</p>
  
  <p>I misse something but don't know what.</p>