title: Test Dependencies between PHP unit tests in Laravel 5.7
body: <p>I am working on <code>Laravel 5.7</code> and i'd like to ask you a question regarding the PHPUnit testing.</p>
  
  <p>I have a test class, let's say <code>ProductControllerTest.php</code>, with two methods <code>testProductSoftDelete()</code> and <code>testProductPermanentlyDelete()</code>. I want to use the annotation <code>@depends</code> in the testProductPermanentlyDelete() in order to soft-delete first a product and then get the product id and proceed to permanently deletion test. The problem here is that the <code>DatabaseTransaction</code> trait runs the transactions in every test (method) execution. I need to start the transaction before all the tests of my ProductControllerTest class and then rollback the transaction at the end of all tests. Do you have any ideas? From what i have searched from the web nothing worked properly.</p>
  
  <pre><code>public function testProductSoftDelete()
  {
     some code
  
     return $product_id;
  }
  
  /**
  * @depends testProductSoftDelete
  */
  public function testProductPermanentlyDelete($product_id)
  {
     code to test permanently deletion of the product with id $product_id.
     There is a business logic behind that needs to soft delete first a 
     product before you permanently delete it.
  
  }
  </code></pre>
  
  <p>Does the following make sense?</p>
  
  <pre><code>    namespace Tests\App\Controllers\Product;
  
      use Tests\DatabaseTestCase;
      use Tests\TestRequestsTrait;
  
      /**
       * @group Coverage
       * @group App.Controllers
       * @group App.Controllers.Product
       *
       * Class ProductControllerTest
       *
       * @package Tests\App\Controllers\Product
       */
  
      class ProductControllerTest extends DatabaseTestCase
      {
          use TestRequestsTrait;
  
          public function testSoftDelete()
          {
              $response = $this-&gt;doProductSoftDelete('9171448');
              $response
                  -&gt;assertStatus(200)
                  -&gt;assertSeeText('Product sof-deleted successfully');
          }
  
  
          public function testUnlink()
          {
              $this-&gt;doProductSoftDelete('9171448');
              $response = $this-&gt;actingAsSuperAdmin()-&gt;delete('/pages/admin/management/product/unlink/9171448');
  
              $response
                  -&gt;assertStatus(200)
                  -&gt;assertSeeText('Product unlinked successfully');
          }
      }
  
  
      namespace Tests;
  
      trait TestRequestsTrait
      {
          /**
           * Returns the response
           *
           * @param $product_id
           * @return \Illuminate\Foundation\Testing\TestResponse
           */
          protected function doProductSoftDelete($product_id)
          {
              $response = $this-&gt;actingAsSuperAdmin()-&gt;delete('/pages/admin/management/product/soft-delete/'.$product_id);
              return $response;
          }
  
      }
  
      namespace Tests;
  
      use Illuminate\Foundation\Testing\DatabaseTransactions;
  
      abstract class DatabaseTestCase extends TestCase
      {
  
          use CreatesApplication;
          use DatabaseTransactions;
      }
  </code></pre>