Mockey/Laravel with static call of Authorizer::getResourceOwnerId
<p>I am attempting to use Mockery to fully test some features of a Laravel 5.1 codebase.</p>

<p>I've not done a huge amount of unit testing in Mockery, and certainly not a huge amount with static calls... of which Laravel uses plenty. </p>

<p>I am aware that testing static calls is horrible.. but it can be done. In what I consider good practice (please feel free to correct me), I am attempting to mock these classes to increase separation of tested components.</p>

<p>I am using the <code>\Mockery::mock('alias:{classname}')</code> feature in order to catch these static calls.</p>

<p>For example, to check the current logged in user, the id is found using:</p>

<p><code>$user_id = (int)Authorizer::getResourceOwnerId();</code></p>

<p>However, the testing features seem to have some limitations, and I could be using them wrong - the exact question follows below:</p>

<h2>Testing structure</h2>

<p>My current situation is as follows:</p>

<pre><code>class AuthRoutesTest extends TestCase {

// ...

protected $mock_authorizer;

// ...

public function setUp()
{
    parent::setUp();

    // ...

    $this-&gt;mock_authorizer
        -&gt;shouldReceive('getResourceOwnerId')
        -&gt;andReturnValues(
            [null, 3, 3, 3]
        );
}

public function tearDown()
{
    \Mockery::close();
}
</code></pre>

<p>Now the tests - all of these require <code>$user_id = (int)Authorizer::getResourceOwnerId();</code> to return values.</p>

<pre><code>public function testFirst() {
    // $user_id is null, then 3, 3 finally 3
}
</code></pre>

<p>And here's the problem:</p>

<p>I want to have.. lets say <code>testSecond()</code> with a separate set of values: say <code>[1,2,null,4]</code>. </p>

<p>Each test seems to reset the array (go back to the beginning).</p>

<p>Note: -</p>

<ul>
<li>I have tried to call <code>-&gt;shouldReceive('getResourceOwnerId')</code> again - this does not help</li>
<li>I have tried to append the next values to the array, but it starts again at key 0</li>
</ul>

<p>Is this possible, and if so, how is this done?</p>

<p>(I am aware there are other ways of coding a site.. this is more about testing existing code and avoiding the re-write - at least for now)</p>