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

orchestral / testbench-core / 11968182539

22 Nov 2024 07:16AM UTC coverage: 91.991% (+0.7%) from 91.321%
11968182539

Pull #265

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #265: [7.x] Allow to configure `tty` via `Orchestra\Testbench\remote()` function

3 of 4 new or added lines in 1 file covered. (75.0%)

93 existing lines in 25 files now uncovered.

1206 of 1311 relevant lines covered (91.99%)

61.99 hits per line

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

93.94
/src/Concerns/HandlesDatabases.php
1
<?php
2

3
namespace Orchestra\Testbench\Concerns;
4

5
use Closure;
6
use Illuminate\Database\Events\DatabaseRefreshed;
7
use Orchestra\Testbench\Attributes\DefineDatabase;
8
use Orchestra\Testbench\Attributes\WithMigration;
9
use Orchestra\Testbench\Exceptions\ApplicationNotAvailableException;
10
use Orchestra\Testbench\Features\TestingFeature;
11

12
/**
13
 * @internal
14
 */
15
trait HandlesDatabases
16
{
17
    /**
18
     * Setup database requirements.
19
     *
20
     * @param  \Closure():void  $callback
21
     */
22
    protected function setUpDatabaseRequirements(Closure $callback): void
23
    {
24
        if (\is_null($app = $this->app)) {
151✔
UNCOV
25
            throw ApplicationNotAvailableException::make(__METHOD__);
×
26
        }
27

28
        $app['events']->listen(DatabaseRefreshed::class, function () {
151✔
29
            $this->defineDatabaseMigrationsAfterDatabaseRefreshed();
9✔
30
        });
151✔
31

32
        if (static::usesTestingConcern(WithLaravelMigrations::class)) {
151✔
33
            $this->setUpWithLaravelMigrations(); /** @phpstan-ignore method.notFound */
7✔
34
        }
35

36
        TestingFeature::run(
151✔
37
            testCase: $this,
151✔
38
            attribute: fn () => $this->parseTestMethodAttributes($app, WithMigration::class),
151✔
39
        );
151✔
40

41
        $attributeCallbacks = TestingFeature::run(
151✔
42
            testCase: $this,
151✔
43
            default: function () {
151✔
44
                $this->defineDatabaseMigrations();
151✔
45
                $this->beforeApplicationDestroyed(fn () => $this->destroyDatabaseMigrations());
151✔
46
            },
151✔
47
            annotation: fn () => $this->parseTestMethodAnnotations($app, 'define-db'),
151✔
48
            attribute: fn () => $this->parseTestMethodAttributes($app, DefineDatabase::class)
151✔
49
        )->get('attribute');
151✔
50

51
        $callback();
151✔
52

53
        $attributeCallbacks->handle();
151✔
54

55
        $this->defineDatabaseSeeders();
151✔
56
    }
57

58
    /**
59
     * Determine if using in-memory SQLite database connection
60
     *
61
     * @param  string|null  $connection
62
     * @return bool
63
     */
64
    protected function usesSqliteInMemoryDatabaseConnection(?string $connection = null): bool
65
    {
66
        if (\is_null($app = $this->app)) {
151✔
UNCOV
67
            throw ApplicationNotAvailableException::make(__METHOD__);
×
68
        }
69

70
        /** @var \Illuminate\Contracts\Config\Repository $config */
71
        $config = $app->make('config');
151✔
72

73
        /** @var string $connection */
74
        $connection ??= $config->get('database.default');
151✔
75

76
        /** @var array{driver: string, database: string}|null $database */
77
        $database = $config->get("database.connections.{$connection}");
151✔
78

79
        return ! \is_null($database) && $database['driver'] === 'sqlite' && $database['database'] == ':memory:';
151✔
80
    }
81

82
    /**
83
     * Define database migrations.
84
     *
85
     * @return void
86
     */
87
    protected function defineDatabaseMigrations()
88
    {
89
        // Define database migrations.
90
    }
147✔
91

92
    /**
93
     * Define database migrations after database refreshed.
94
     *
95
     * @return void
96
     */
97
    protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
98
    {
99
        // Define database migrations after database refreshed.
100
    }
9✔
101

102
    /**
103
     * Destroy database migrations.
104
     *
105
     * @return void
106
     */
107
    protected function destroyDatabaseMigrations()
108
    {
109
        // Destroy database migrations.
110
    }
151✔
111

112
    /**
113
     * Define database seeders.
114
     *
115
     * @return void
116
     */
117
    protected function defineDatabaseSeeders()
118
    {
119
        // Define database seeders.
120
    }
151✔
121
}
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