Laravel CRUD controller test
<p>Basically I have to write tests for many Laravel Controllers most of which are CRUD (read, store, update) and most of the logic is placed inside those(Inherited code, not mine).</p>

<p>What I need to do is automate the testing from a User's perspective. So I need to hit all the endpoints and test against a real database and check if everything turns out well.</p>

<p>I have almost no experience in testing, but from what I gather controllers should be tested with integration / acceptance tests. Now I did fine with testing Read methods by extending Laravel's TestCase, here is one example :</p>

<pre><code>class SongsTest extends TestCase
{
    public function testBasicIndex()
    {   
        $arguments = [];

        $response = $this-&gt;call('GET', '/songs', $arguments);

        $this-&gt;assertResponseOk();
        $this-&gt;seeJson();
    }

    /**
        * @dataProvider providerSearchQuery
    */
    public function testSearchIndex($query)
    {
        $arguments = ['srquery' =&gt; $query];

        $response = $this-&gt;call('GET', '/songs', $arguments);

        $this-&gt;assertResponseOk();
        $this-&gt;seeJson();
    }

    public function providerSearchQuery()
    {
        return array(
            array('a'),
            array('as%+='),
            array('test?Someqsdag8hj$%$') 
            );
    }


    public function testGetSongsById()
    {   
        $id = 1;

        $response = $this-&gt;call('GET', '/songs/' . $id);

        $this-&gt;assertContains($response-&gt;getStatusCode(), [200, 404]);
        $this-&gt;seeJson();

        if($response-&gt;getStatusCode() == 404)
        {   
            $content = json_decode($response-&gt;getContent());
            $this-&gt;assertContains($content-&gt;message[0], ['Song not found', 'Item not active']);
        }
    }
}
</code></pre>

<p>These tests hit the endpoints and check if the response is 200 and the format is JSON and few other things. These work fine.</p>

<p>What I have problem with is : </p>

<p>Let's say for example we have a UserController, and a method that creates users. After that, said user should be used in TokensController to create a token that should be somehow remembered and used in future tests with token  protected requests. </p>

<p>My question :</p>

<p>How do I automate : tests of UserController's store method by creating a real user in a testing database(without mocking), tests of TokensController's store method by using that user's email, testing other controllers with the created token and deleting that once the test is done, so it can be performed once again.</p>

<p>I just cannot conceptualize all that since I haven't really done much testing.</p>