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

orchestral / testbench-core / 18178100089

01 Oct 2025 11:04PM UTC coverage: 91.993% (+0.06%) from 91.929%
18178100089

push

github

crynobone
Merge branch '8.x' into 9.x

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

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

1 existing line in 1 file now uncovered.

1551 of 1686 relevant lines covered (91.99%)

76.98 hits per line

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

86.84
/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

10
use function Orchestra\Sidekick\working_path;
11

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

24
    /**
25
     * List of required packages.
26
     *
27
     * @var array<int, string>
28
     */
29
    protected array $requiredPackages = [
30
        'laravel/dusk',
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);
194✔
42

43
        $this->setTestbench($testbench);
194✔
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): void
54
    {
55
        /** @var \Illuminate\Foundation\PackageManifest $base */
56
        $base = $app->make(IlluminatePackageManifest::class);
194✔
57

58
        $app->instance(
194✔
59
            IlluminatePackageManifest::class,
194✔
60
            new static(
194✔
61
                $base->files, $base->basePath, $base->manifestPath, $testbench
194✔
62
            )
194✔
63
        );
194✔
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;
194✔
75
    }
76

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

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')
194✔
95
                ? ($this->testbench->ignorePackageDiscoveriesFrom() ?? [])
194✔
96
                : [];
×
97

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

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

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

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

115
    /** {@inheritDoc} */
116
    #[\Override]
117
    protected function packagesToIgnore()
118
    {
119
        return [];
10✔
120
    }
121

122
    /**
123
     * Get all of the package names from root.
124
     *
125
     * @return array
126
     */
127
    protected function providersFromRoot(): array
128
    {
129
        $package = $this->providersFromTestbenchOrLaravel();
10✔
130

131
        return \is_array($package) ? [
10✔
132
            $this->format($package['name']) => $package['extra']['laravel'] ?? [],
10✔
133
        ] : [];
10✔
134
    }
135

136
    /**
137
     * Get testbench root composer file.
138
     *
139
     * @return array{name: string, extra?: array{laravel?: array}}|null
140
     */
141
    protected function providersFromTestbenchOrLaravel(): ?array
142
    {
143
        $composerFile = working_path('composer.json');
10✔
144

145
        if (is_file($composerFile)) {
10✔
146
            /** @var array{name: string, extra?: array{laravel?: array}} $composer */
147
            $composer = $this->files->json($composerFile);
10✔
148

149
            return $composer;
10✔
150
        }
151

UNCOV
152
        return null;
×
153
    }
154

155
    /** {@inheritDoc} */
156
    #[\Override]
157
    protected function write(array $manifest)
158
    {
159
        parent::write(
10✔
160
            (new Collection($manifest))->merge($this->providersFromRoot())->filter()->all()
10✔
161
        );
10✔
162
    }
163
}
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