|
14 | 14 | use App\ConfigManager; |
15 | 15 | use App\Exceptions\RuntimeException; |
16 | 16 | use App\Exceptions\UnsupportedConfigActionException; |
17 | | -use Symfony\Component\Process\Exception\RuntimeException as SymfonyRuntimeException; |
18 | | -use Symfony\Component\Process\Process; |
| 17 | +use Symfony\Component\Process\Exception\ProcessFailedException; |
| 18 | +use Symfony\Component\Process\ExecutableFinder; |
19 | 19 |
|
20 | 20 | it('can set config', function (): void { |
21 | 21 | $this->getFunctionMock(class_namespace(ConfigCommand::class), 'file_exists') |
|
104 | 104 | ])->assertSuccessful(); |
105 | 105 | })->group(__DIR__, __FILE__); |
106 | 106 |
|
107 | | -it('will throw RuntimeException for edit config on Windows', function (): void { |
108 | | - $this->artisan(ConfigCommand::class, [ |
109 | | - 'action' => 'edit', |
110 | | - ]); |
111 | | -}) |
112 | | - ->group(__DIR__, __FILE__) |
113 | | - ->skip(! windows_os()) |
114 | | - ->throws(RuntimeException::class, 'The edit config command is not supported on Windows.'); |
115 | | - |
116 | | -it('will throw RuntimeException for edit config', function (): void { |
117 | | - $this->getFunctionMock(class_namespace(ConfigCommand::class), 'exec') |
118 | | - ->expects($this->exactly(6)) |
119 | | - ->willReturn(''); |
120 | | - |
| 107 | +it('will throw `Command not found` ProcessFailedException for edit config', function (): void { |
121 | 108 | $this->artisan(ConfigCommand::class, [ |
122 | 109 | 'action' => 'edit', |
| 110 | + '--editor' => 'foo', |
123 | 111 | ]); |
124 | 112 | }) |
125 | 113 | ->group(__DIR__, __FILE__) |
126 | | - ->skip(windows_os()) |
127 | | - ->throws(RuntimeException::class, 'No editor found or specified.'); |
| 114 | + ->throws(ProcessFailedException::class); |
128 | 115 |
|
129 | | -it('will throw \SymfonyRuntimeException for edit config', function (): void { |
130 | | - $this->getFunctionMock(class_namespace(Process::class), 'proc_open') |
131 | | - ->expects($this->once()) |
132 | | - ->willReturn(false); |
| 116 | +it('will throw another `Command not found` ProcessFailedException for edit config', function (): void { |
| 117 | + app()->singleton(ExecutableFinder::class, static function () { |
| 118 | + return new class() extends ExecutableFinder { |
| 119 | + public function find(string $name, ?string $default = null, array $extraDirs = []): string |
| 120 | + { |
| 121 | + return 'foo'; |
| 122 | + } |
| 123 | + }; |
| 124 | + }); |
133 | 125 |
|
134 | 126 | $this->artisan(ConfigCommand::class, [ |
135 | 127 | 'action' => 'edit', |
136 | | - '--editor' => 'foo', |
137 | 128 | ]); |
138 | 129 | }) |
139 | 130 | ->group(__DIR__, __FILE__) |
140 | | - ->skip() |
141 | | - ->throws(SymfonyRuntimeException::class, 'TTY mode requires /dev/tty to be read/writable.'); |
| 131 | + ->throws(ProcessFailedException::class); |
142 | 132 |
|
143 | | -it('will throw SymfonyRuntimeException for edit config', function (): void { |
144 | | - $this->getFunctionMock(class_namespace(ConfigCommand::class), 'exec') |
145 | | - ->expects($this->once()) |
146 | | - ->willReturn('/usr/local/bin/vim'); |
147 | | - |
148 | | - $this->getFunctionMock(class_namespace(Process::class), 'proc_open') |
149 | | - ->expects($this->any()) |
150 | | - ->willReturn(false); |
| 133 | +it('will throw RuntimeException for edit config', function (): void { |
| 134 | + app()->singleton(ExecutableFinder::class, static function () { |
| 135 | + return new class() extends ExecutableFinder { |
| 136 | + public function find(string $name, ?string $default = null, array $extraDirs = []): void |
| 137 | + { |
| 138 | + } |
| 139 | + }; |
| 140 | + }); |
151 | 141 |
|
152 | 142 | $this->artisan(ConfigCommand::class, [ |
153 | 143 | 'action' => 'edit', |
154 | 144 | ]); |
155 | 145 | }) |
156 | 146 | ->group(__DIR__, __FILE__) |
157 | | - ->skip(windows_os()) |
158 | | - ->throws(SymfonyRuntimeException::class, 'TTY mode requires /dev/tty to be read/writable.'); |
| 147 | + ->throws(RuntimeException::class, 'Unable to find a default editor or specify the editor.'); |
159 | 148 |
|
160 | 149 | it('will throw UnsupportedConfigActionException', function (): void { |
161 | 150 | $this->artisan(ConfigCommand::class, [ |
|
0 commit comments