Skip to content

Commit c7aa66d

Browse files
committed
Apply suggestions from code review
1 parent b6c7d8a commit c7aa66d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Context/FeatureContext.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ private static function configure_sqlite( $dir ): void {
611611
$db_copy_contents = file_get_contents( $db_copy );
612612

613613
if ( false === $db_copy_contents ) {
614-
return;
614+
throw new RuntimeException( "Could not read db.copy file at: {$db_copy}" );
615615
}
616616

617617
/* similar to https://github.com/WordPress/sqlite-database-integration/blob/3306576c9b606bc23bbb26c15383fef08e03ab11/activate.php#L95 */
@@ -789,6 +789,8 @@ public function afterScenario( AfterScenarioScope $scope ): void {
789789
* @param int $master_pid
790790
*/
791791
private static function terminate_proc( $master_pid ): void {
792+
$master_pid = (int) $master_pid;
793+
792794
if ( Utils\is_windows() ) {
793795
shell_exec( "taskkill /F /T /PID $master_pid > NUL 2>&1" );
794796
return;
@@ -801,7 +803,7 @@ private static function terminate_proc( $master_pid ): void {
801803
$parent = $matches[1];
802804
$child = $matches[2];
803805

804-
if ( (int) $parent === (int) $master_pid ) {
806+
if ( (int) $parent === $master_pid ) {
805807
self::terminate_proc( (int) $child );
806808
}
807809
}
@@ -811,7 +813,7 @@ private static function terminate_proc( $master_pid ): void {
811813
return;
812814
}
813815

814-
if ( ! posix_kill( (int) $master_pid, 9 ) ) {
816+
if ( ! posix_kill( $master_pid, 9 ) ) {
815817
$errno = posix_get_last_error();
816818
// Ignore "No such process" error as that's what we want.
817819
if ( 3 /*ESRCH*/ !== $errno ) {
@@ -1008,7 +1010,13 @@ private function replace_invoke_wp_cli_with_php_args( $str ) {
10081010
$phar_begin_len = strlen( $phar_begin );
10091011
$bin_dir = getenv( 'WP_CLI_BIN_DIR' );
10101012
$bin = Utils\is_windows() ? 'wp.bat' : 'wp';
1011-
if ( false !== $bin_dir && file_exists( $bin_dir . DIRECTORY_SEPARATOR . $bin ) && (string) file_get_contents( $bin_dir . DIRECTORY_SEPARATOR . $bin, false, null, 0, $phar_begin_len ) === $phar_begin ) {
1013+
if (
1014+
false !== $bin_dir &&
1015+
// A .bat file will never start with a shebang.
1016+
! Utils\is_windows() &&
1017+
file_exists( $bin_dir . DIRECTORY_SEPARATOR . $bin ) &&
1018+
(string) file_get_contents( $bin_dir . DIRECTORY_SEPARATOR . $bin, false, null, 0, $phar_begin_len ) === $phar_begin
1019+
) {
10121020
$phar_path = $bin_dir . DIRECTORY_SEPARATOR . $bin;
10131021
} else {
10141022
$src_dir = dirname( __DIR__, 2 );
@@ -1623,7 +1631,7 @@ public function install_wp( $subdir = '', $version = '' ): void {
16231631
$mysqldump_binary = Utils\get_sql_dump_command();
16241632
$mysqldump_binary = Utils\force_env_on_nix_systems( $mysqldump_binary );
16251633
$help_output = shell_exec( "{$mysqldump_binary} --help" );
1626-
$support_column_statistics = false !== strpos( $help_output, 'column-statistics' );
1634+
$support_column_statistics = ( null !== $help_output && false !== strpos( $help_output, 'column-statistics' ) );
16271635
$ssl_flag = 'mariadb' === self::$db_type ? ' --ssl-verify-server-cert' : '';
16281636
$command = "{$mysqldump_binary} --no-defaults{$ssl_flag} --no-tablespaces";
16291637
if ( $support_column_statistics ) {
@@ -1735,7 +1743,7 @@ private function composer_command( $cmd ): void {
17351743
if ( ! isset( $this->variables['COMPOSER_PATH'] ) ) {
17361744
$command = Utils\is_windows() ? 'where composer' : 'which composer';
17371745
$path = exec( $command );
1738-
if ( false === $path ) {
1746+
if ( false === $path || empty( $path ) ) {
17391747
throw new RuntimeException( 'Could not find composer.' );
17401748
}
17411749
// In case of multiple paths, pick the first one.

src/Context/ThenStepDefinitions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public function then_stdout_stderr_should_be_a_specific_version_string( $stream,
455455
public function then_a_specific_file_folder_should_exist( $path, $type, $strictly, $action, $expected = null ): void {
456456
$path = $this->replace_variables( $path );
457457

458-
$is_absolute = preg_match( '#^[a-zA-Z]:\\\\#', $path ) || ( '/' === $path[0] || '\\' === $path[0] );
458+
$is_absolute = preg_match( '#^[a-zA-Z]:\\\\#', $path ) || ( strlen( $path ) > 0 && ( '/' === $path[0] || '\\' === $path[0] ) );
459459

460460
// If it's a relative path, make it relative to the current test dir.
461461
if ( ! $is_absolute ) {

0 commit comments

Comments
 (0)