wiki.techinc.nl/tests/phpunit/unit/includes/shell/CommandFactoryTest.php
Kunal Mehta b3f54db14c shell: Fix autodetection of firejail in findFirejail()
Fixes a regression from 3f94708eff. ExecutableFinder returns false if
the executable isn't found, but CommandFactory was expecting a null response,
This caused autodetection to always think firejail was present.

Adjust CommandFactoryTest to ensure we're always passing a string to
FirejailCommand. We need to switch findFirejail to protected so it can
be mocked.

Bug: T257282
Change-Id: Ie73418ebef6dce2bd5ec18fa38e29219d5bb2fd6
2020-07-07 03:18:34 -07:00

51 lines
1.4 KiB
PHP

<?php
use MediaWiki\Shell\Command;
use MediaWiki\Shell\CommandFactory;
use MediaWiki\Shell\FirejailCommand;
use Psr\Log\NullLogger;
use Wikimedia\TestingAccessWrapper;
/**
* @group Shell
*/
class CommandFactoryTest extends MediaWikiUnitTestCase {
/**
* @covers MediaWiki\Shell\CommandFactory::create
*/
public function testCreate() {
$logger = new NullLogger();
$cgroup = '/sys/fs/cgroup/memory/mygroup';
$limits = [
'filesize' => 1000,
'memory' => 1000,
'time' => 30,
'walltime' => 40,
];
$factory = new CommandFactory( $limits, $cgroup, false );
$factory->setLogger( $logger );
$factory->logStderr();
$command = $factory->create();
$this->assertInstanceOf( Command::class, $command );
$wrapper = TestingAccessWrapper::newFromObject( $command );
$this->assertSame( $logger, $wrapper->logger );
$this->assertSame( $cgroup, $wrapper->cgroup );
$this->assertSame( $limits, $wrapper->limits );
$this->assertTrue( $wrapper->doLogStderr );
}
/**
* @covers MediaWiki\Shell\CommandFactory::create
*/
public function testFirejailCreate() {
$mock = $this->getMockBuilder( CommandFactory::class )
->setConstructorArgs( [ [], false, 'firejail' ] )
->setMethods( [ 'findFirejail' ] )
->getMock();
$mock->method( 'findFirejail' )->willReturn( '/usr/bin/firejail' );
$this->assertInstanceOf( FirejailCommand::class, $mock->create() );
}
}