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

orchestral / testbench-core / 12324437332

13 Dec 2024 11:13PM UTC coverage: 91.777% (-0.5%) from 92.296%
12324437332

Pull #278

github

web-flow
Merge 82ecf708a into b1b7dd073
Pull Request #278: [7.x] Fixes database seeding using `WithWorkbench` and `RefreshDatabase`

6 of 14 new or added lines in 1 file covered. (42.86%)

25 existing lines in 8 files now uncovered.

1250 of 1362 relevant lines covered (91.78%)

64.18 hits per line

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

65.22
/src/Concerns/WithWorkbench.php
1
<?php
2

3
namespace Orchestra\Testbench\Concerns;
4

5
use Illuminate\Foundation\Testing\Traits\CanConfigureMigrationCommands;
6
use Orchestra\Testbench\Contracts\Config as ConfigContract;
7
use Orchestra\Testbench\Foundation\Bootstrap\LoadMigrationsFromArray;
8
use Orchestra\Testbench\Workbench\Workbench;
9

10
/**
11
 * @api
12
 */
13
trait WithWorkbench
14
{
15
    use InteractsWithPHPUnit;
16
    use InteractsWithWorkbench;
17

18
    /**
19
     * Bootstrap with Workbench.
20
     *
21
     * @return void
22
     */
23
    protected function setUpWithWorkbench(): void
24
    {
25
        /** @var \Illuminate\Contracts\Foundation\Application $app */
26
        $app = $this->app;
25✔
27

28
        /** @var \Orchestra\Testbench\Contracts\Config $config */
29
        $config = static::cachedConfigurationForWorkbench();
25✔
30

31
        Workbench::start($app, $config);
25✔
32

33
        $seeders = $config['seeders'] ?? false;
25✔
34

35
        $seeders = static::usesTestingConcern(CanConfigureMigrationCommands::class)
25✔
36
            ? $this->mergeSeedersForWorkbench($config)
5✔
37
            : ($config['seeders'] ?? false);
20✔
38

39
        (new LoadMigrationsFromArray(
25✔
40
            $config['migrations'] ?? [], $seeders,
25✔
41
        ))->bootstrap($app);
25✔
42
    }
43

44
    /**
45
     * Bootstrap discover routes.
46
     *
47
     * @param  \Illuminate\Contracts\Foundation\Application  $app
48
     * @return void
49
     */
50
    protected function bootDiscoverRoutesForWorkbench($app): void
51
    {
52
        /** @var \Orchestra\Testbench\Contracts\Config $config */
53
        $config = static::cachedConfigurationForWorkbench();
25✔
54

55
        Workbench::discoverRoutes($app, $config);
25✔
56
    }
57

58
    /**
59
     * Merge seeders for Workbench.
60
     *
61
     * @param  \Orchestra\Testbench\Contracts\Config  $config
62
     * @return array|false
63
     */
64
    protected function mergeSeedersForWorkbench(ConfigContract $config): array|false
65
    {
66
        $seeders = $config['seeders'] ?? false;
5✔
67

68
        if ($this->shouldSeed() === false || $seeders === false) {
5✔
69
            return false;
5✔
70
        }
71

NEW
72
        $testCaseSeeder = $this->seeder();
×
73

NEW
74
        $testCaseSeeder = $testCaseSeeder !== false
×
NEW
75
            ? $testCaseSeeder
×
NEW
76
            : \Database\Seeders\DatabaseSeeder::class;
×
77

NEW
78
        return Collection::make($seeders)
×
NEW
79
            ->reject(static fn ($seeder) => $seeder == $testCaseSeeder)
×
NEW
80
            ->values()
×
NEW
81
            ->all();
×
82
    }
83
}
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

© 2025 Coveralls, Inc