• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RonasIT / laravel-helpers / 13928362316

18 Mar 2025 04:24PM UTC coverage: 76.951% (-2.1%) from 79.092%
13928362316

push

github

web-flow
Merge pull request #197 from RonasIT/eparusov/refactor-test-case

refactor: namespaces

2 of 40 new or added lines in 1 file covered. (5.0%)

1065 of 1384 relevant lines covered (76.95%)

12.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.0
/src/Testing/TestCase.php
1
<?php
2

3
namespace RonasIT\Support\Testing;
4

5
use Carbon\Carbon;
6
use Illuminate\Foundation\Testing\TestCase as BaseTest;
7
use Illuminate\Support\Facades\DB;
8
use Illuminate\Support\Facades\Mail;
9
use Illuminate\Testing\TestResponse;
10
use RonasIT\Support\Traits\MailsMockTrait;
11

12
abstract class TestCase extends BaseTest
13
{
14
    use MailsMockTrait;
15

16
    protected $auth;
17

18
    protected string $testNow = '2018-11-11 11:11:11';
19

20
    protected static string $startedTestSuite = '';
21
    protected static bool $isWrappedIntoTransaction = true;
22

23
    protected function setUp(): void
24
    {
NEW
25
        parent::setUp();
×
26

NEW
27
        $this->artisan('cache:clear');
×
28

NEW
29
        if ((static::$startedTestSuite !== static::class) || !self::$isWrappedIntoTransaction) {
×
NEW
30
            $this->artisan('migrate');
×
31

NEW
32
            $this->loadTestDump();
×
33

NEW
34
            static::$startedTestSuite = static::class;
×
35
        }
36

NEW
37
        if (config('database.default') === 'pgsql') {
×
NEW
38
            $this->prepareSequences();
×
39
        }
40

NEW
41
        Carbon::setTestNow(Carbon::parse($this->testNow));
×
42

NEW
43
        Mail::fake();
×
44

NEW
45
        $this->beginDatabaseTransaction();
×
46
    }
47

48
    public function tearDown(): void
49
    {
NEW
50
        $this->beforeApplicationDestroyed(function () {
×
NEW
51
            DB::disconnect();
×
NEW
52
        });
×
53

NEW
54
        parent::tearDown();
×
55
    }
56

57
    public function callRawRequest(string $method, string $uri, $content, array $headers = []): TestResponse
58
    {
NEW
59
        $server = $this->transformHeadersToServerVars($headers);
×
60

NEW
61
        return $this->call($method, $uri, [], [], [], $server, $content);
×
62
    }
63

64
    protected function dontWrapIntoTransaction(): void
65
    {
NEW
66
        $this->rollbackTransaction();
×
67

NEW
68
        self::$isWrappedIntoTransaction = false;
×
69
    }
70

71
    protected function beginDatabaseTransaction(): void
72
    {
NEW
73
        $database = $this->app->make('db');
×
74

NEW
75
        foreach ($this->connectionsToTransact() as $name) {
×
NEW
76
            $connection = $database->connection($name);
×
NEW
77
            $dispatcher = $connection->getEventDispatcher();
×
78

NEW
79
            $connection->unsetEventDispatcher();
×
NEW
80
            $connection->beginTransaction();
×
NEW
81
            $connection->setEventDispatcher($dispatcher);
×
82
        }
83

NEW
84
        $this->beforeApplicationDestroyed(function () {
×
NEW
85
            $this->rollbackTransaction();
×
NEW
86
        });
×
87
    }
88

89
    protected function connectionsToTransact(): array
90
    {
NEW
91
        return property_exists($this, 'connectionsToTransact') ? $this->connectionsToTransact : [null];
×
92
    }
93

94
    protected function rollbackTransaction(): void
95
    {
NEW
96
        $database = $this->app->make('db');
×
97

NEW
98
        foreach ($this->connectionsToTransact() as $name) {
×
NEW
99
            $connection = $database->connection($name);
×
NEW
100
            $dispatcher = $connection->getEventDispatcher();
×
101

NEW
102
            $connection->unsetEventDispatcher();
×
NEW
103
            $connection->rollback();
×
NEW
104
            $connection->setEventDispatcher($dispatcher);
×
NEW
105
            $connection->disconnect();
×
106
        }
107
    }
108

109
    protected function prepareModelTestState(string $modelClassName): ModelTestState
110
    {
111
        return (new ModelTestState($modelClassName))->setGlobalExportMode($this->globalExportMode);
2✔
112
    }
113

114
    protected function prepareTableTestState(string $tableName, array $jsonFields = [], ?string $connectionName = null): TableTestState
115
    {
116
        return (new TableTestState($tableName, $jsonFields, $connectionName))->setGlobalExportMode($this->globalExportMode);
2✔
117
    }
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc