jeudi 12 septembre 2019

How in testing switch DatabaseTransactions off/on on condition?

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?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Q62ccH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire