• 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

70.0
/src/Foundation/PackageManifest.php
1
<?php
2

3
namespace Orchestra\Testbench\Foundation;
4

5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Foundation\PackageManifest as IlluminatePackageManifest;
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\Collection;
9
use RuntimeException;
10

11
use function Orchestra\Testbench\package_path;
12

13
/**
14
 * @api
15
 */
16
class PackageManifest extends IlluminatePackageManifest
17
{
18
    /**
19
     * Testbench Class.
20
     *
21
     * @var \Orchestra\Testbench\Contracts\TestCase|object|null
22
     */
23
    protected $testbench;
24

25
    /**
26
     * List of required packages.
27
     *
28
     * @var array<int, string>
29
     */
30
    protected $requiredPackages = [
31
        'spatie/laravel-ray',
32
    ];
33

34
    /**
35
     * {@inheritDoc}
36
     *
37
     * @param  \Orchestra\Testbench\Contracts\TestCase|object|null  $testbench
38
     */
39
    public function __construct(Filesystem $files, $basePath, $manifestPath, $testbench = null)
40
    {
41
        parent::__construct($files, $basePath, $manifestPath);
164✔
42

43
        $this->setTestbench($testbench);
164✔
44
    }
45

46
    /**
47
     * Create a new package manifest instance from base.
48
     *
49
     * @param  \Illuminate\Foundation\Application  $app
50
     * @param  object|null  $testbench
51
     * @return void
52
     */
53
    public static function swap($app, $testbench = null)
54
    {
55
        /** @var \Illuminate\Foundation\PackageManifest $base */
56
        $base = $app->make(IlluminatePackageManifest::class);
164✔
57

58
        $app->instance(
164✔
59
            IlluminatePackageManifest::class,
164✔
60
            new static(
164✔
61
                $base->files, $base->basePath, $base->manifestPath, $testbench
164✔
62
            )
164✔
63
        );
164✔
64
    }
65

66
    /**
67
     * Set Testbench instance.
68
     *
69
     * @param  object|null  $testbench
70
     * @return void
71
     */
72
    public function setTestbench($testbench): void
73
    {
74
        $this->testbench = \is_object($testbench) ? $testbench : null;
164✔
75
    }
76

77
    /**
78
     * Requires packages.
79
     *
80
     * @param  string[]  $packages
81
     * @return $this
82
     */
83
    public function requires(...$packages)
84
    {
UNCOV
85
        $this->requiredPackages = array_merge($this->requiredPackages, Arr::wrap($packages));
×
86

UNCOV
87
        return $this;
×
88
    }
89

90
    /** {@inheritDoc} */
91
    #[\Override]
92
    protected function getManifest()
93
    {
94
        $ignore = ! \is_null($this->testbench) && method_exists($this->testbench, 'ignorePackageDiscoveriesFrom')
164✔
95
                ? ($this->testbench->ignorePackageDiscoveriesFrom() ?? [])
164✔
UNCOV
96
                : [];
×
97

98
        $ignoreAll = \in_array('*', $ignore);
164✔
99

100
        $requires = $this->requiredPackages;
164✔
101

102
        return Collection::make(parent::getManifest())
164✔
103
            ->reject(static fn ($configuration, $package) => ($ignoreAll && ! \in_array($package, $requires)) || \in_array($package, $ignore))
164✔
104
            ->map(static function ($configuration, $package) {
164✔
105
                foreach ($configuration['providers'] ?? [] as $provider) {
159✔
106
                    if (! class_exists($provider)) {
159✔
UNCOV
107
                        return null;
×
108
                    }
109
                }
110

111
                return $configuration;
159✔
112
            })->filter()->all();
164✔
113
    }
114

115
    /**
116
     * Get all of the package names that should be ignored.
117
     *
118
     * @return array
119
     */
120
    protected function packagesToIgnore()
121
    {
122
        return [];
2✔
123
    }
124

125
    /**
126
     * Get all of the package names from root.
127
     *
128
     * @return array
129
     */
130
    protected function providersFromRoot()
131
    {
132
        $composerFile = package_path('composer.json');
2✔
133

134
        if (! \defined('TESTBENCH_CORE') || ! is_file($composerFile)) {
2✔
135
            return [];
2✔
136
        }
137

UNCOV
138
        $package = transform(file_get_contents($composerFile), static function ($json) use ($composerFile) {
×
UNCOV
139
            if (json_validate($json) === false) {
×
UNCOV
140
                throw new RuntimeException("Unable to parse [{$composerFile}] file");
×
141
            }
142

143
            return json_decode($json, true);
×
UNCOV
144
        });
×
145

146
        return [
×
147
            $this->format($package['name']) => $package['extra']['laravel'] ?? [],
×
UNCOV
148
        ];
×
149
    }
150

151
    /** {@inheritDoc} */
152
    #[\Override]
153
    protected function write(array $manifest)
154
    {
155
        parent::write(
2✔
156
            Collection::make($manifest)->merge($this->providersFromRoot())->filter()->all()
2✔
157
        );
2✔
158
    }
159
}
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