Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion php/class-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ public static function get_config( $key = null ) {
return self::get_runner()->config;
}

if ( ! isset( self::get_runner()->config[ $key ] ) ) {
if ( ! self::has_config( $key ) ) {
self::warning( "Unknown config option '$key'." );
return null;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/test-configurator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use WP_CLI\Configurator;
use WP_CLI\Loggers;
use WP_CLI\Tests\TestCase;

class ConfiguratorTest extends TestCase {
Expand Down Expand Up @@ -58,4 +59,29 @@ public function testExtractAssocDoubleDashInValue() {
$this->assertEquals( 'test', $args[1][0][0] );
$this->assertEquals( 'text--text', $args[1][0][1] );
}

/**
* WP_CLI::get_config does not show warnings for null values.
*/
public function testNullGetConfig() {
// Init config so there is a config to check.
$runner = WP_CLI::get_runner();
$runner->init_config();

// Previous
$prev_logger = WP_CLI::get_logger();

$logger = new Loggers\Execution();
WP_CLI::set_logger( $logger );

$has_config = WP_CLI::has_config( 'url' );
$get_config = WP_CLI::get_config( 'url' );

$this->assertTrue( $has_config, 'has_config() is not true' );
$this->assertTrue( false === strpos( $logger->stderr, 'Warning' ), 'Logger contains a "Warning"' );
$this->assertNull( $get_config, 'get_config() is not null' );

// Restore
WP_CLI::set_logger( $prev_logger );
}
}