Skip to content

Commit 565fdb8

Browse files
committed
perf(Concerns): improve error handling in setSoarBinary
- Refactor error handling in setSoarBinary method - Combine file existence and executability checks - Throw exception when file does not exist or is not executable
1 parent cb13eec commit 565fdb8

File tree

4 files changed

+7
-22
lines changed

4 files changed

+7
-22
lines changed

src/Concerns/HasSoarBinary.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public function getSoarBinary(): string
3030

3131
public function setSoarBinary(string $soarBinary): self
3232
{
33-
if (!file_exists($soarBinary)) {
34-
throw new InvalidArgumentException("The file [$soarBinary] does not exist.");
35-
}
36-
37-
if (!is_executable($soarBinary)) {
38-
throw new InvalidArgumentException("The file [$soarBinary] is not executable.");
33+
if (
34+
!is_file($soarBinary)
35+
// || !file_exists($soarBinary)
36+
|| !is_executable($soarBinary)
37+
) {
38+
throw new InvalidArgumentException("The file [$soarBinary] does not exist or is not executable.");
3939
}
4040

4141
$this->soarBinary = realpath($soarBinary);

tests/Concerns/ConcreteScoresTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
* @see https://github.com/guanguans/soar-php
2121
*/
2222

23-
use Guanguans\SoarPHP\Exceptions\InvalidArgumentException;
2423
use Guanguans\SoarPHP\Soar;
2524
use Guanguans\SoarPHP\Support\OS;
2625

@@ -111,13 +110,6 @@
111110
});
112111
});
113112

114-
it('will throw InvalidArgumentException when sqls is boolean', function (): void {
115-
Soar::create()->scores(true);
116-
})
117-
->group(__DIR__, __FILE__)
118-
->throws(InvalidArgumentException::class, \gettype(true))
119-
->skip();
120-
121113
it('can get scores', function (): void {
122114
expect(Soar::create())
123115
->scores('select * from users;')

tests/Concerns/HasSoarBinaryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
->skip('This test is skipped. Because is not supported in github actions.');
4747

4848
it('will throw InvalidArgumentException when set invalid binary', function (): void {
49+
Soar::create()->setSoarBinary('/');
4950
Soar::create()->setSoarBinary('soar.path');
5051
})
5152
->group(__DIR__, __FILE__)

tests/Concerns/WithRunableTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,10 @@
1818

1919
namespace Guanguans\SoarPHPTests\Concerns;
2020

21-
use Guanguans\SoarPHP\Exceptions\InvalidArgumentException;
2221
use Guanguans\SoarPHP\Exceptions\ProcessFailedException;
2322
use Guanguans\SoarPHP\Soar;
2423
use Symfony\Component\Process\Process;
2524

26-
it('will throw InvalidArgumentException when with-options is boolean', function (): void {
27-
Soar::create()->run(true);
28-
})
29-
->group(__DIR__, __FILE__)
30-
->throws(InvalidArgumentException::class, \gettype(true))
31-
->skip();
32-
3325
it('will throw ProcessFailedException when sqls is invalid sql', function (): void {
3426
Soar::create()->setOnlySyntaxCheck(true)->setQuery('invalid sql')->run();
3527
})

0 commit comments

Comments
 (0)