jeudi 16 avril 2015

Laravel tesing: '$this->be()' not working

I'm writing some API tests for the platform I'm developing and I'm having issues trying to test the following route:



Route::post('/user/logout', ['middleware' => ['ACL', 'auth'], 'permission' => ['is_user'], 'uses' => 'UserController@logout']);


As you can see this route is using 2 middlewares: ACL and auth.


Every time the application environment is set to testing by Laravel the ACL is automatically disabled.


This is the the controller method logout():



public function logout()
{
Auth::logout();

return $this->respondOK('User logged out.');
}


And this is the test:



use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

class PostLogoutTest extends TestCase
{
public function setUp()
{
parent::setUp();

Session::start();

$this->be(new \App\User());
}

public function tearDown()
{
Mockery::close();
}

public function testLogout()
{
Auth::shouldReceive('logout')->once()->withNoArgs()->andReturn();

$response = $this->call('POST', '/api/user/logout', [
'_token' => csrf_token()
]);

print_r($response->getContent());

$this->assertResponseStatus(200);
}
}


The problem I'm having is caused by the auth middleware and I keep receiving the following exception:



BadMethodCallException in EvalLoader.php code line 709: Method Mockery_2_Illuminate_Auth_AuthManager::driver() does not exist on this mock object


If I disable the auth everything works fine. Shouldn't $this->be() solve my issue?


Aucun commentaire:

Enregistrer un commentaire