-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Module/WPCLI) support custom bin
This adds support and tests for the `bin` configuration parameter in the `WPCLI` module. Fixes #764
- Loading branch information
Showing
7 changed files
with
235 additions
and
6 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
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,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "This binary was never modded to be executable" | ||
exit 0 |
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,4 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
echo "Hello from wp-cli custom binary"; | ||
exit(0); |
94 changes: 94 additions & 0 deletions
94
tests/unit/lucatume/WPBrowser/Module/WPCLICustomBinaryTest.php
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,94 @@ | ||
<?php | ||
|
||
namespace unit\lucatume\WPBrowser\Module; | ||
|
||
use Codeception\Exception\ModuleConfigException; | ||
use Codeception\Lib\Di; | ||
use Codeception\Lib\ModuleContainer; | ||
use Codeception\Test\Unit; | ||
use lucatume\WPBrowser\Module\WPCLI; | ||
use lucatume\WPBrowser\Utils\Filesystem; | ||
|
||
class WPCLICustomBinaryTest extends Unit | ||
{ | ||
private ?string $homeBackup = null; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
if (isset($_SERVER['HOME'])) { | ||
$this->homeBackup = $_SERVER['HOME']; | ||
} | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
if ($this->homeBackup !== null) { | ||
$_SERVER['HOME'] = $this->homeBackup; | ||
} | ||
} | ||
|
||
public function test_configuration_allows_custom_binary(): void | ||
{ | ||
$binary = codecept_data_dir('bins/wp-cli-custom-bin'); | ||
$moduleContainer = new ModuleContainer(new Di(), []); | ||
|
||
$module = new WPCLI($moduleContainer, [ | ||
'path' => 'var/wordpress', | ||
'bin' => $binary, | ||
]); | ||
$module->cli(['core', 'version']); | ||
|
||
$this->assertEquals( | ||
'Hello from wp-cli custom binary', | ||
$module->grabLastShellOutput() | ||
); | ||
} | ||
|
||
public function test_configuration_supports_tilde_for_home_in_custom_binary():void{ | ||
$_SERVER['HOME'] = codecept_data_dir(); | ||
$binary = '~/bins/wp-cli-custom-bin'; | ||
$binaryPath = codecept_data_dir('bins/wp-cli-custom-bin'); | ||
$moduleContainer = new ModuleContainer(new Di(), []); | ||
// Sanity check. | ||
$this->assertEquals(rtrim(codecept_data_dir(),'\\/'),Filesystem::homeDir()); | ||
|
||
$module = new WPCLI($moduleContainer, [ | ||
'path' => 'var/wordpress', | ||
'bin' => $binary, | ||
]); | ||
$module->cli(['core', 'version']); | ||
|
||
$this->assertEquals( | ||
'Hello from wp-cli custom binary', | ||
$module->grabLastShellOutput() | ||
); | ||
} | ||
|
||
public function test_throws_if_custom_binary_does_not_exist(): void{ | ||
$binary = codecept_data_dir('bins/not-a-bin'); | ||
$moduleContainer = new ModuleContainer(new Di(), []); | ||
|
||
$this->expectException(ModuleConfigException::class); | ||
|
||
$module = new WPCLI($moduleContainer, [ | ||
'path' => 'var/wordpress', | ||
'bin' => $binary, | ||
]); | ||
$module->cli(['core', 'version']); | ||
} | ||
|
||
public function test_throws_if_custom_binary_is_not_executable(): void{ | ||
$binary = codecept_data_dir('bins/not-executable'); | ||
$moduleContainer = new ModuleContainer(new Di(), []); | ||
|
||
$this->expectException(ModuleConfigException::class); | ||
|
||
$module = new WPCLI($moduleContainer, [ | ||
'path' => 'var/wordpress', | ||
'bin' => $binary, | ||
]); | ||
$module->cli(['core', 'version']); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
tests/unit/lucatume/WPBrowser/WordPress/CliProcessTest.php
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,75 @@ | ||
<?php | ||
|
||
|
||
namespace Unit\lucatume\WPBrowser\WordPress; | ||
|
||
use lucatume\WPBrowser\Exceptions\InvalidArgumentException; | ||
use lucatume\WPBrowser\Utils\Filesystem; | ||
use lucatume\WPBrowser\WordPress\CliProcess; | ||
|
||
class CliProcessTest extends \Codeception\Test\Unit | ||
{ | ||
private ?string $homeBackup = null; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
if (isset($_SERVER['HOME'])) { | ||
$this->homeBackup = $_SERVER['HOME']; | ||
} | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
if ($this->homeBackup !== null) { | ||
$_SERVER['HOME'] = $this->homeBackup; | ||
} | ||
} | ||
|
||
public function test_construct_with_custom_binary(): void | ||
{ | ||
$binary = codecept_data_dir('bins/wp-cli-custom-bin'); | ||
|
||
$cliProcess = new CliProcess(['core', 'version'], null, null, null, null, $binary); | ||
|
||
$this->assertEquals( | ||
escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($binary) . " 'core' 'version'", | ||
$cliProcess->getCommandLine() | ||
); | ||
} | ||
|
||
public function test_throws_if_custom_binary_does_not_exist(): void | ||
{ | ||
$binary = codecept_data_dir('bins/not-a-bin'); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
|
||
$cliProcess = new CliProcess(['core', 'version'], null, null, null, null, $binary); | ||
} | ||
|
||
public function test_throws_if_custom_binary_is_not_executable(): void | ||
{ | ||
$binary = codecept_data_dir('bins/not-executable'); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
|
||
$cliProcess = new CliProcess(['core', 'version'], null, null, null, null, $binary); | ||
} | ||
|
||
public function test_tilde_for_home_dir_is_supported_in_custom_binary_path(): void | ||
{ | ||
$_SERVER['HOME'] = codecept_data_dir(); | ||
$binary = '~/bins/wp-cli-custom-bin'; | ||
$binaryAbsolutePath = codecept_data_dir('bins/wp-cli-custom-bin'); | ||
// Sanity check. | ||
$this->assertEquals(rtrim(codecept_data_dir(), '\\/'), Filesystem::homeDir()); | ||
|
||
$cliProcess = new CliProcess(['core', 'version'], null, null, null, null, $binary); | ||
|
||
$this->assertEquals( | ||
escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($binaryAbsolutePath) . " 'core' 'version'", | ||
$cliProcess->getCommandLine() | ||
); | ||
} | ||
} |