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

orchestral / testbench-core / 11474242678

23 Oct 2024 06:22AM UTC coverage: 92.256% (-0.06%) from 92.313%
11474242678

push

github

crynobone
wip

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

1382 of 1498 relevant lines covered (92.26%)

72.56 hits per line

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

92.0
/src/Foundation/Console/Actions/GeneratesFile.php
1
<?php
2

3
namespace Orchestra\Testbench\Foundation\Console\Actions;
4

5
use Illuminate\Console\View\Components\Factory as ComponentsFactory;
6
use Illuminate\Filesystem\Filesystem;
7

8
use function Laravel\Prompts\confirm;
9
use function Orchestra\Testbench\join_paths;
10

11
class GeneratesFile extends Action
12
{
13
    /**
14
     * Construct a new action instance.
15
     *
16
     * @param  \Illuminate\Filesystem\Filesystem  $filesystem
17
     * @param  \Illuminate\Console\View\Components\Factory|null  $components
18
     * @param  bool  $force
19
     * @param  string|null  $workingPath
20
     * @param  bool  $confirmation
21
     */
22
    public function __construct(
23
        public readonly Filesystem $filesystem,
24
        public readonly ?ComponentsFactory $components = null,
25
        public readonly bool $force = false,
26
        ?string $workingPath = null,
27
        public readonly bool $confirmation = false
28
    ) {
29
        $this->workingPath = $workingPath;
6✔
30
    }
31

32
    /**
33
     * Handle the action.
34
     *
35
     * @param  string|false|null  $from
36
     * @param  string|false|null  $to
37
     * @return void
38
     */
39
    public function handle(string|false|null $from, string|false|null $to): void
40
    {
41
        if (! \is_string($from) || ! \is_string($to)) {
6✔
42
            return;
×
43
        }
44

45
        if (! $this->filesystem->exists($from)) {
6✔
46
            $this->components?->twoColumnDetail(
1✔
47
                \sprintf('Source file [%s] doesn\'t exists', $this->pathLocation($from)),
1✔
48
                '<fg=yellow;options=bold>SKIPPED</>'
1✔
49
            );
1✔
50

51
            return;
1✔
52
        }
53

54
        $location = $this->pathLocation($to);
5✔
55

56
        if (! $this->force && $this->filesystem->exists($to)) {
5✔
57
            $this->components?->twoColumnDetail(
2✔
58
                \sprintf('File [%s] already exists', $location),
2✔
59
                '<fg=yellow;options=bold>SKIPPED</>'
2✔
60
            );
2✔
61

62
            return;
2✔
63
        }
64

65
        if ($this->confirmation === true && confirm(\sprintf('Generate [%s] file?', $location)) === false) {
3✔
66
            return;
×
67
        }
68

69
        $this->filesystem->copy($from, $to);
3✔
70

71
        $gitKeepFile = join_paths(\dirname($to), '.gitkeep');
3✔
72

73
        if ($this->filesystem->exists($gitKeepFile)) {
3✔
74
            $this->filesystem->delete($gitKeepFile);
2✔
75
        }
76

77
        $this->components?->task(
3✔
78
            \sprintf('File [%s] generated', $location)
3✔
79
        );
3✔
80
    }
81
}
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