Skip to content

Commit

Permalink
refactor: rename SoarPath -> SoarBinary
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Jan 15, 2024
1 parent 307697b commit 434846c
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
## Installation

```shell
composer require guanguans/soar-php -vvv
composer require guanguans/soar-php -v
```

## Usage
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
## 安装

```shell
composer require guanguans/soar-php -vvv
composer require guanguans/soar-php -v
```

## 使用
Expand Down Expand Up @@ -690,4 +690,4 @@ This project follows the [all-contributors](https://github.com/all-contributors/

## 协议

MIT 许可证(MIT)。有关更多信息,请参见[协议文件](LICENSE)
MIT 许可证(MIT)。有关更多信息,请参见[协议文件](LICENSE)
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
"@lint",
"@style-lint",
"@test",
"@psalm"
"@psalm",
"@rector-dry-run"
],
"composer-bin-all-update": "@composer bin all update --ansi -v",
"composer-check-platform-reqs": "@composer check-platform-reqs --lock --ansi -v",
Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
define('MHASH_XXH32', 2 << 1);
define('MHASH_XXH64', 2 << 2);
define('MHASH_XXH128', 2 << 3);
$rectorConfig->importNames(true, false);
$rectorConfig->importNames(false, false);
$rectorConfig->importShortClasses(false);
// $rectorConfig->disableParallel();
$rectorConfig->parallel(240);
Expand Down
8 changes: 4 additions & 4 deletions src/Concerns/ConcreteMagic.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait ConcreteMagic
{
public function __sleep()
{
return ['options', 'soarPath'];
return ['options', 'soarBinary'];
}

public function __wakeup(): void
Expand All @@ -36,7 +36,7 @@ public function __wakeup(): void
// {
// return [
// 'options' => $this->options,
// 'soarPath' => $this->soarPath,
// 'soarBinary' => $this->soarBinary,
// ];
// }
//
Expand All @@ -46,7 +46,7 @@ public function __wakeup(): void
// public function __unserialize(array $data): void
// {
// $this->setOptions($data['options']);
// $this->setSoarPath($data['soarPath']);
// $this->setSoarBinary($data['soarBinary']);
// }

public function __debugInfo()
Expand All @@ -56,7 +56,7 @@ public function __debugInfo()

public static function __set_state(array $properties)
{
return new static($properties['options'], $properties['soarPath']);
return new static($properties['options'], $properties['soarBinary']);
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/Concerns/HasSoarPath.php → src/Concerns/HasSoarBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@
/**
* @mixin \Guanguans\SoarPHP\Soar
*/
trait HasSoarPath
trait HasSoarBinary
{
/** @var string */
protected $soarPath;
protected $soarBinary;

public function getSoarPath(): string
public function getSoarBinary(): string
{
return $this->soarPath;
return $this->soarBinary;
}

public function setSoarPath(string $soarPath): self
public function setSoarBinary(string $soarBinary): self
{
if (! file_exists($soarPath) || ! is_executable($soarPath)) {
throw new InvalidArgumentException("The file($soarPath) does not exist or cannot executable.");
if (! file_exists($soarBinary) || ! is_executable($soarBinary)) {
throw new InvalidArgumentException("The file($soarBinary) does not exist or cannot executable.");
}

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

return $this;
}

protected function getEscapedSoarPath(): string
protected function getEscapedSoarBinary(): string
{
return escape_argument($this->soarPath);
return escape_argument($this->soarBinary);
}

private function getDefaultSoarPath(): string
private function getDefaultSoarBinary(): string
{
if (OS::isWindows()) {
return __DIR__.'/../../bin/soar.windows-amd64'; // @codeCoverageIgnore
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/WithRunable.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function run($withOptions = [], ?callable $callback = null): string
private function createProcess($withOptions = []): Process
{
$process = \is_string($withOptions)
? Process::fromShellCommandline("{$this->getEscapedSoarPath()} {$this->getHydratedEscapedNormalizedOptions()} $withOptions")
: new Process(array_merge([$this->soarPath], $this->clone()->mergeOptions($withOptions)->getNormalizedOptions()));
? Process::fromShellCommandline("{$this->getEscapedSoarBinary()} {$this->getHydratedEscapedNormalizedOptions()} $withOptions")
: new Process(array_merge([$this->soarBinary], $this->clone()->mergeOptions($withOptions)->getNormalizedOptions()));

if ($this->shouldApplySudoPassword()) {
$process = Process::fromShellCommandline(sprintf(
Expand Down
12 changes: 6 additions & 6 deletions src/Soar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Guanguans\SoarPHP\Concerns\ConcreteMagic;
use Guanguans\SoarPHP\Concerns\ConcreteScores;
use Guanguans\SoarPHP\Concerns\HasOptions;
use Guanguans\SoarPHP\Concerns\HasSoarPath;
use Guanguans\SoarPHP\Concerns\HasSoarBinary;
use Guanguans\SoarPHP\Concerns\HasSudoPassword;
use Guanguans\SoarPHP\Concerns\WithDumpable;
use Guanguans\SoarPHP\Concerns\WithRunable;
Expand All @@ -26,20 +26,20 @@ class Soar implements Contracts\Soar
use ConcreteMagic;
use ConcreteScores;
use HasOptions;
use HasSoarPath;
use HasSoarBinary;
use HasSudoPassword;
use WithDumpable;
use WithRunable;

public function __construct(array $options = [], ?string $soarPath = null)
public function __construct(array $options = [], ?string $soarBinary = null)
{
$this->setOptions($options);
$this->setSoarPath($soarPath ?? $this->getDefaultSoarPath());
$this->setSoarBinary($soarBinary ?? $this->getDefaultSoarBinary());
}

public static function create(array $options = [], ?string $soarPath = null): self
public static function create(array $options = [], ?string $soarBinary = null): self
{
return new static($options, $soarPath);
return new static($options, $soarBinary);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Concerns/ConcreteMagicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testSleep(): void
$unserializedSoar = unserialize($serializedSoar);

$this->assertInstanceOf(Soar::class, $unserializedSoar);
$this->assertNotEmpty($unserializedSoar->getSoarPath());
$this->assertNotEmpty($unserializedSoar->getSoarBinary());
$this->assertNotEmpty($unserializedSoar->getOptions());
}

Expand All @@ -44,7 +44,7 @@ public function testSetState(): void
eval("\$exportedSoar = $exportedSoarStr;");

$this->assertInstanceOf(Soar::class, $exportedSoar);
$this->assertNotEmpty($exportedSoar->getSoarPath());
$this->assertNotEmpty($exportedSoar->getSoarBinary());
$this->assertNotEmpty($exportedSoar->getOptions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
*
* @small
*/
class HasSoarPathTest extends TestCase
class HasSoarBinaryTest extends TestCase
{
/**
* @noinspection PhpUnreachableStatementInspection
* @noinspection PhpUnitTestFailedLineInspection
*/
public function testGetSoarPath(): void
public function testGetSoarBinary(): void
{
// $mock = \Mockery::mock('alias:'.OS::class)->makePartial();
// $mock->allows('isWindows')->andReturnTrue();
// $soar = Soar::create();
// $this->assertFileExists($soar->getSoarPath());
// $this->assertStringContainsString('windows', $soar->getSoarPath());
// $this->assertFileExists($soar->getSoarBinary());
// $this->assertStringContainsString('windows', $soar->getSoarBinary());

$soar = Soar::create();
$this->assertFileExists($soar->getSoarPath());
$this->assertFileExists($soar->getSoarBinary());

$this->markTestSkipped(__METHOD__.' is skipped.');

Expand All @@ -47,28 +47,28 @@ public function testGetSoarPath(): void

test::double(OS::class, ['isWindows' => true, 'isMacOS' => false]);
$soar = Soar::create();
$this->assertFileExists($soar->getSoarPath());
$this->assertStringContainsString('windows', $soar->getSoarPath());
$this->assertFileExists($soar->getSoarBinary());
$this->assertStringContainsString('windows', $soar->getSoarBinary());

test::double(OS::class, ['isWindows' => false, 'isMacOS' => true]);
$soar = Soar::create();
$this->assertFileExists($soar->getSoarPath());
$this->assertStringContainsString('darwin', $soar->getSoarPath());
$this->assertFileExists($soar->getSoarBinary());
$this->assertStringContainsString('darwin', $soar->getSoarBinary());

test::double(OS::class, ['isWindows' => false, 'isMacOS' => false]);
$soar = Soar::create();
$this->assertFileExists($soar->getSoarPath());
$this->assertStringContainsString('linux', $soar->getSoarPath());
$this->assertFileExists($soar->getSoarBinary());
$this->assertStringContainsString('linux', $soar->getSoarBinary());

// 恢复
test::double(OS::class, $originals);
}

public function testInvalidArgumentExceptionForSetSoarPath(): void
public function testInvalidArgumentExceptionForSetSoarBinary(): void
{
$soar = Soar::create();

$this->expectException(InvalidArgumentException::class);
$soar->setSoarPath('soar.path');
$soar->setSoarBinary('soar.path');
}
}

0 comments on commit 434846c

Please sign in to comment.