title: How to preserve session through all tests on phpunit?
body: <p>I'm working on testing a shopping cart, checkout, payment process on Zend Framework with phpunit. I'm testing <code>ShoppingCartController</code> by adding products to cart, a <code>ShoppingCart</code> Model handles product additions by storing product id's in a Zend Session Namespace, and then in another test I want to test that the products were added. The same <code>ShoppingCart</code> Model retrieves a list of added products from the same Zend Session namespace variable.</p>
  
  <p>The add product test looks like this and works well, and the <code>var_dump($_SESSION)</code> was added to debug and shows the products correctly:</p>
  
  <pre><code>public function testCanAddProductsToShoppingCart() {
  
      $testProducts = array(
          array(
              "product_id" =&gt; "1",
              "product_quantity" =&gt; "5"
          ),
          array(
              "product_id" =&gt; "1",
              "product_quantity" =&gt; "3"
          ),
          array(
              "product_id" =&gt; "2",
              "product_quantity" =&gt; "1"
          )
      );
  
      Ecommerce_Model_Shoppingcart::clean();
  
      foreach ($testProducts as $product) {
          $this-&gt;request-&gt;setMethod('POST')
                  -&gt;setPost(array(
                      'product_id' =&gt; $product["product_id"],
                      'quantity' =&gt; $product["product_quantity"]
                  ));
  
          $this-&gt;dispatch($this-&gt;getRouteUrl("add_to_shopping_cart"));
          $this-&gt;assertResponseCode('200');
      }
  
      $products = Ecommerce_Model_Shoppingcart::getData();
      $this-&gt;assertTrue($products[2][0]["product"] instanceof Ecommerce_Model_Product);
      $this-&gt;assertEquals($products[2][0]["quantity"],
              "8");
  
      $this-&gt;assertTrue($products[2][1]["product"] instanceof Ecommerce_Model_Product);
      $this-&gt;assertEquals($products[2][1]["quantity"],
              "1");
  
      var_dump($_SESSION);
  }
  </code></pre>
  
  <p>The second test attempts to retrieve the products by asking the model to do so, the <code>var_dump($_SESSION)</code> is null already at the beginning of the test. <strong>The session variables were reset, I want to find a way to preserve them, can anyone help?</strong></p>
  
  <pre><code>public function testCanDisplayShoppingCartWidget()  {
      var_dump($_SESSION);
      $this-&gt;dispatch($this-&gt;getRouteUrl("view_shopping_mini_cart"));
      $this-&gt;assertResponseCode('200');
  }
  </code></pre>