Maintenance: Don't modify mOptions in getOption
This makes hasOption stable and usable even after getOption. Also getOption can now be called twice with different defaults. Strictly speaking this is a breaking change, but the actual behaviour is now closer to the expected/documented behaviour. Bug: T275619 Change-Id: I65e32a7e1bc253f4b29378be6980c42e43f93032
This commit is contained in:
parent
781d5c10d6
commit
070f94de80
3 changed files with 28 additions and 5 deletions
|
|
@ -390,6 +390,8 @@ because of Phabricator reports.
|
|||
in public MediaWiki-related git, was removed.
|
||||
* Passing Title as a second parameter to RevisionStore::getPreviousRevision and
|
||||
getNextRevision, hard deprecated since 1.31, was prohibited.
|
||||
* (T275619) Maintenance::hasOption and Maintenance::getOption now behave as
|
||||
documented and are not altered by previous calls to these methods.
|
||||
* The internal class FirejailCommand was removed.
|
||||
* Command::execute() now returns a Shellbox\Command\UnboxedResult instead of a
|
||||
MediaWiki\Shell\Result. Any type hints should be updated.
|
||||
|
|
|
|||
|
|
@ -259,7 +259,8 @@ abstract class Maintenance {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a particular option exists.
|
||||
* Checks to see if a particular option was set.
|
||||
*
|
||||
* @param string $name The name of the option
|
||||
* @return bool
|
||||
*/
|
||||
|
|
@ -282,10 +283,7 @@ abstract class Maintenance {
|
|||
if ( $this->hasOption( $name ) ) {
|
||||
return $this->mOptions[$name];
|
||||
} else {
|
||||
// Set it so we don't have to provide the default again
|
||||
$this->mOptions[$name] = $default;
|
||||
|
||||
return $this->mOptions[$name];
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -526,4 +526,27 @@ class MaintenanceTest extends MaintenanceBaseTestCase {
|
|||
$this->assertEquals( 'yo', $this->maintenance->getOption( 'multi' ) );
|
||||
$this->assertEquals( [ [ 'multi', 'yo' ] ], $this->maintenance->orderedOptions );
|
||||
}
|
||||
|
||||
public function testOptionGetters() {
|
||||
$this->assertSame(
|
||||
false,
|
||||
$this->maintenance->hasOption( 'somearg' ),
|
||||
'Non existent option not found'
|
||||
);
|
||||
$this->assertSame(
|
||||
'default',
|
||||
$this->maintenance->getOption( 'somearg', 'default' ),
|
||||
'Non existent option falls back to default'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$this->maintenance->hasOption( 'somearg' ),
|
||||
'Non existent option not found after getting'
|
||||
);
|
||||
$this->assertSame(
|
||||
'newdefault',
|
||||
$this->maintenance->getOption( 'somearg', 'newdefault' ),
|
||||
'Non existent option falls back to a new default'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue