TestWithTransactionAndUser::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Traits;
6
7
use Application\Model\User;
8
use Ecodev\Felix\Testing\Traits\TestWithTransaction;
9
10
/**
11
 * Allow to run test within a database transaction, so database will be unchanged after test.
12
 */
13
trait TestWithTransactionAndUser
14
{
15
    use TestWithTransaction {
16
        setUp as traitSetupWithTransaction;
17
        tearDown as traitTearDownWithTransaction;
18
    }
19
20
    /**
21
     * Start transaction.
22
     */
23
    protected function setUp(): void
24
    {
25
        $this->traitSetupWithTransaction();
26
        User::setCurrent(null);
27
    }
28
29
    /**
30
     * Cancel transaction, to undo all changes made.
31
     */
32
    protected function tearDown(): void
33
    {
34
        User::setCurrent(null);
35
        $this->traitTearDownWithTransaction();
36
    }
37
}
38