-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Phive Install > Add support for phive.
- Loading branch information
Mihai Stancu
committed
Mar 7, 2021
1 parent
d7cefb1
commit 811322d
Showing
10 changed files
with
218 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Zalas\Toolbox\Json\Factory; | ||
|
||
use Zalas\Toolbox\Tool\Command; | ||
use Zalas\Toolbox\Tool\Command\PhiveInstallCommand; | ||
|
||
final class PhiveInstallCommandFactory | ||
{ | ||
public static function import(array $command): Command | ||
{ | ||
Assert::requireFields(['alias', 'bin'], $command, 'PhiveInstallCommand'); | ||
|
||
return new PhiveInstallCommand($command['alias'], $command['bin'], $command['trust'] ?? false, $command['unsigned'] ?? false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Zalas\Toolbox\Tool\Command; | ||
|
||
use Zalas\Toolbox\Tool\Command; | ||
|
||
final class PhiveInstallCommand implements Command | ||
{ | ||
private $alias; | ||
private $bin; | ||
private $trust; | ||
private $unsigned; | ||
|
||
public function __construct(string $alias, string $bin, bool $trust = true, bool $unsigned = false) | ||
{ | ||
$this->alias = $alias; | ||
$this->bin = $bin; | ||
$this->trust = $trust; | ||
$this->unsigned = $unsigned; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return \sprintf( | ||
'phive install %s %s %s -t %s', | ||
$this->trust ? '--trust-gpg-keys' : '', | ||
$this->unsigned ? '--force-accept-unsigned' : '', | ||
$this->alias, | ||
$this->bin | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Zalas\Toolbox\Tests\Json\Factory; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Zalas\Toolbox\Json\Factory\PhiveInstallCommandFactory; | ||
use Zalas\Toolbox\Tool\Command\PhiveInstallCommand; | ||
|
||
class PhiveInstallCommandFactoryTest extends TestCase | ||
{ | ||
private const ALIAS = 'example/foo'; | ||
private const BIN = '/usr/local/bin/foo'; | ||
|
||
public function test_it_creates_a_command() | ||
{ | ||
$command = PhiveInstallCommandFactory::import([ | ||
'alias' => self::ALIAS, | ||
'bin' => self::BIN, | ||
]); | ||
|
||
$this->assertInstanceOf(PhiveInstallCommand::class, $command); | ||
} | ||
|
||
/** | ||
* @dataProvider provideRequiredProperties | ||
*/ | ||
public function test_it_complains_if_any_of_required_properties_is_missing(string $property) | ||
{ | ||
$this->expectException(\InvalidArgumentException::class); | ||
|
||
$properties = [ | ||
'alias' => self::ALIAS, | ||
'bin' => self::BIN, | ||
]; | ||
|
||
unset($properties[$property]); | ||
|
||
PhiveInstallCommandFactory::import($properties); | ||
} | ||
|
||
public function test_it_accepts_signed_trusted_phars() | ||
{ | ||
$properties = [ | ||
'alias' => self::ALIAS, | ||
'bin' => self::BIN, | ||
]; | ||
|
||
$command = PhiveInstallCommandFactory::import($properties); | ||
$this->assertStringNotContainsString('trust', (string)$command); | ||
$this->assertStringNotContainsString('unsigned', (string)$command); | ||
} | ||
|
||
public function test_it_accepts_signed_untrusted_phars() | ||
{ | ||
$properties = [ | ||
'alias' => self::ALIAS, | ||
'bin' => self::BIN, | ||
'trust' => true, | ||
]; | ||
|
||
$command = PhiveInstallCommandFactory::import($properties); | ||
$this->assertStringContainsString('trust', (string)$command); | ||
} | ||
|
||
public function test_it_accepts_unsigned_phars() | ||
{ | ||
$properties = [ | ||
'alias' => self::ALIAS, | ||
'bin' => self::BIN, | ||
'unsigned' => true, | ||
]; | ||
|
||
$command = PhiveInstallCommandFactory::import($properties); | ||
$this->assertStringContainsString('unsigned', (string)$command); | ||
} | ||
|
||
public function provideRequiredProperties(): \Generator | ||
{ | ||
yield ['alias']; | ||
yield ['bin']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Zalas\Toolbox\Tests\Tool\Command; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Zalas\Toolbox\Tool\Command; | ||
use Zalas\Toolbox\Tool\Command\PhiveInstallCommand; | ||
|
||
class PhiveInstallCommandTest extends TestCase | ||
{ | ||
private const ALIAS = 'example/foo'; | ||
private const BIN = '/usr/local/bin/foo'; | ||
|
||
private $command; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->command = new PhiveInstallCommand(self::ALIAS, self::BIN); | ||
} | ||
|
||
public function test_it_is_a_command() | ||
{ | ||
$this->assertInstanceOf(Command::class, $this->command); | ||
} | ||
|
||
public function test_it_generates_the_installation_command() | ||
{ | ||
$this->assertMatchesRegularExpression(\sprintf('#phive install(\s++)--trust-gpg-keys(\s++)%s -t %s#', self::ALIAS, self::BIN), (string) $this->command); | ||
} | ||
|
||
public function test_it_trusts_gpg_keys_command() | ||
{ | ||
$command = new PhiveInstallCommand(self::ALIAS, self::BIN, false); | ||
$this->assertMatchesRegularExpression(\sprintf('#phive install(\s++)%s -t %s#', self::ALIAS, self::BIN), (string) $command); | ||
} | ||
|
||
public function test_it_accepts_unsigned_phar_command() | ||
{ | ||
$command = new PhiveInstallCommand(self::ALIAS, self::BIN, false, true); | ||
$this->assertMatchesRegularExpression(\sprintf('#phive install(\s++)--force-accept-unsigned(\s++)%s -t %s#', self::ALIAS, self::BIN), (string) $command); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters