I found that DatabaseTransactions.php functionality is implemented in vendor/laravel/framework/src/Illuminate/Foundation/Testing/DatabaseTransactions.php file. Seems there is a way of coping this file into my project under /app/ and modifing it with comdition code, but I am not sure in which subdirecory that file must be copied?
Sep 14, 2019
5
Level 5
How in testing switch DatabaseTransactions off/on on condition?
Hello, In laravel 5.8 application I use test with DatabaseTransactions option, so inserted data in testing db are cleared after testing, like:
<?php
namespace Tests\Feature;
use Tests\TestCase;
use DB;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\User;
use App\UserGroup;
use App\Http\Traits\funcsTrait;
class ProfilePageTest extends TestCase // vendor/bin/phpunit tests/Feature/ProfilepageTest.php
{
use funcsTrait;
use DatabaseTransactions; // TO COMMENT THESE LINE IF WE NEED TO CHECK CREATED DATA IN BD
public function testProfilePage()
{
...
and that works ok, but I need in some case to switch off DatabaseTransactions option without modifing php testing files. But to change some option when relative key test_without_database_transactions in db.setting_table is set to true. If there is a way to make it, like condition :
if ( check value in in db.setting_table.test_without_database_transactions ) {
use Illuminate\Foundation\Testing\DatabaseTransactions;
}
use App\User;
use App\UserGroup;
use App\Http\Traits\funcsTrait;
class ProfilePageTest extends TestCase // vendor/bin/phpunit tests/Feature/ProfilepageTest.php
{
use funcsTrait;
if ( check value in in db.setting_table.test_without_database_transactions ) {
use DatabaseTransactions; // TO COMMENT THESE LINE IF WE NEED TO CHECK CREATED DATA IN BD
}
Can it be done in someway?
Thanks!
Please or to participate in this conversation.