I have the following test file in my Laravel application:
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ApiAuthControllerTest extends TestCase{
use DatabaseTransactions;
private $token;
public function testLogin(){
// Test login success
$response = $this->json('POST', '/login', array(
'email' => 'hello@yahoo.com',
'password' => 'sometext'
))->decodeResponseJson();
$this->token = $response['token'];
}
public function testLogout(){
// Test logout success
$this->json('DELETE', '/logout', array(
'token' => $this->token
))->assertReponseStatus(200);
}
}
I am using the DatabaseTransactions
class to wrap my tests as transactions so they don't write to my database. I noticed that using this class will wrap every individual test within my class as a transaction.
I would like to wrap the entire class as a transaction. In my example above, I need for the token that was generated from my login request to be persistent in the database as I test the logout request.
How would I do this with Laravel?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire