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

orchestral / testbench-core / 11997703869

24 Nov 2024 04:17PM UTC coverage: 91.265% (-0.008%) from 91.273%
11997703869

push

github

web-flow
Update UserFactoryTest.php

1421 of 1557 relevant lines covered (91.27%)

71.0 hits per line

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

91.67
/src/Bootstrap/LoadConfigurationWithWorkbench.php
1
<?php
2

3
namespace Orchestra\Testbench\Bootstrap;
4

5
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Foundation\Auth\User as Authenticatable;
7
use Illuminate\Support\Collection;
8
use Illuminate\Support\LazyCollection;
9
use Orchestra\Testbench\Foundation\Env;
10
use Orchestra\Testbench\Workbench\Workbench;
11
use Symfony\Component\Finder\Finder;
12
use Workbench\App\Models\User;
13

14
use function Orchestra\Testbench\workbench_path;
15

16
/**
17
 * @internal
18
 */
19
class LoadConfigurationWithWorkbench extends LoadConfiguration
20
{
21
    /**
22
     * Determine if workbench config file should be loaded.
23
     *
24
     * @var bool
25
     */
26
    protected readonly bool $usesWorkbenchConfigFile;
27

28
    /**
29
     * Construct a new bootstrap class.
30
     */
31
    public function __construct()
32
    {
33
        $this->usesWorkbenchConfigFile = (Workbench::configuration()->getWorkbenchDiscoversAttributes()['config'] ?? false)
46✔
34
            && is_dir(workbench_path('config'));
46✔
35
    }
36

37
    /** {@inheritDoc} */
38
    #[\Override]
39
    public function bootstrap(Application $app): void
40
    {
41
        parent::bootstrap($app);
46✔
42

43
        /** @var class-string<\Illuminate\Foundation\Auth\User>|false $userModel */
44
        $userModel = match (true) {
46✔
45
            Env::has('AUTH_MODEL') => Env::get('AUTH_MODEL'),
46✔
46
            class_exists(User::class) => User::class,
46✔
47
            default => false,
×
48
        };
46✔
49

50
        if ($userModel !== false && is_a($userModel, Authenticatable::class, true)) {
46✔
51
            $app->make('config')->set('auth.providers.users.model', $userModel);
46✔
52
        }
53
    }
54

55
    /**
56
     * Resolve the configuration file.
57
     *
58
     * @param  string  $path
59
     * @param  string  $key
60
     * @return string
61
     */
62
    #[\Override]
63
    protected function resolveConfigurationFile(string $path, string $key): string
64
    {
65
        $config = workbench_path('config', "{$key}.php");
46✔
66

67
        return $this->usesWorkbenchConfigFile === true && is_file($config) ? $config : $path;
46✔
68
    }
69

70
    /**
71
     * Extend the loaded configuration.
72
     *
73
     * @param  \Illuminate\Support\Collection  $configurations
74
     * @return \Illuminate\Support\Collection
75
     */
76
    #[\Override]
77
    protected function extendsLoadedConfiguration(Collection $configurations): Collection
78
    {
79
        if ($this->usesWorkbenchConfigFile === false) {
46✔
80
            return $configurations;
×
81
        }
82

83
        LazyCollection::make(function () {
46✔
84
            $path = workbench_path('config');
46✔
85

86
            foreach (Finder::create()->files()->name('*.php')->in($path) as $file) {
46✔
87
                $directory = $this->getNestedDirectory($file, $path);
46✔
88

89
                yield $directory.basename($file->getRealPath(), '.php') => $file->getRealPath();
46✔
90
            }
91
        })->reject(static fn ($path, $key) => $configurations->has($key))
46✔
92
            ->each(static function ($path, $key) use ($configurations) {
46✔
93
                $configurations->put($key, $path);
46✔
94
            });
46✔
95

96
        return $configurations;
46✔
97
    }
98
}
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