<?php
use MediaWiki\Shell\Command;
+use Wikimedia\TestingAccessWrapper;
/**
+ * @covers \MediaWiki\Shell\Command
* @group Shell
*/
class CommandTest extends PHPUnit_Framework_TestCase {
- /**
- * @expectedException PHPUnit_Framework_Error_Notice
- */
- public function testDestruct() {
- if ( defined( 'HHVM_VERSION' ) ) {
- $this->markTestSkipped( 'destructors are unreliable in HHVM' );
- }
- $command = new Command();
- $command->params( 'true' );
- }
-
private function requirePosix() {
if ( wfIsWindows() ) {
$this->markTestSkipped( 'This test requires a POSIX environment.' );
$this->assertRegExp( '/^.+no-such-file.*$/m', $result->getStderr() );
}
+ /**
+ * Test that null values are skipped by params() and unsafeParams()
+ */
+ public function testNullsAreSkipped() {
+ $command = TestingAccessWrapper::newFromObject( new Command );
+ $command->params( 'echo', 'a', null, 'b' );
+ $command->unsafeParams( 'c', null, 'd' );
+ $this->assertEquals( "'echo' 'a' 'b' c d", $command->command );
+ }
+
public function testT69870() {
$commandLine = wfIsWindows()
// 333 = 331 + CRLF
$this->assertEquals( 333333, strlen( $output ) );
}
}
+
+ public function testLogStderr() {
+ $this->requirePosix();
+
+ $logger = new TestLogger( true, function ( $message, $level, $context ) {
+ return $level === Psr\Log\LogLevel::ERROR ? '1' : null;
+ }, true );
+ $command = new Command();
+ $command->setLogger( $logger );
+ $command->params( 'bash', '-c', 'echo ThisIsStderr 1>&2' );
+ $command->execute();
+ $this->assertEmpty( $logger->getBuffer() );
+
+ $command = new Command();
+ $command->setLogger( $logger );
+ $command->logStderr();
+ $command->params( 'bash', '-c', 'echo ThisIsStderr 1>&2' );
+ $command->execute();
+ $this->assertSame( 1, count( $logger->getBuffer() ) );
+ $this->assertSame( trim( $logger->getBuffer()[0][2]['error'] ), 'ThisIsStderr' );
+ }
}