Gergő Tisza has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/338312 )
Change subject: Add tests for Shell/ShellCommand
......................................................................
Add tests for Shell/ShellCommand
Change-Id: I89cc40d3414486707f911516bd1045504dfad83f
---
A tests/phpunit/includes/shell/ShellCommandTest.php
A tests/phpunit/includes/shell/ShellTest.php
2 files changed, 64 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/12/338312/1
diff --git a/tests/phpunit/includes/shell/ShellCommandTest.php
b/tests/phpunit/includes/shell/ShellCommandTest.php
new file mode 100644
index 0000000..636822a
--- /dev/null
+++ b/tests/phpunit/includes/shell/ShellCommandTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use MediaWiki\ShellCommand;
+
+/**
+ * Class ShellCommandTest
+ */
+class ShellCommandTest extends PHPUnit_Framework_TestCase {
+ /**
+ * @expectedException PHPUnit_Framework_Error_Notice
+ */
+ public function testDestruct() {
+ $command = new ShellCommand( 'true' );
+ }
+
+ /**
+ * @dataProvider provideExecute
+ */
+ public function testExecute( $command, $expectedExitCode,
$expectedOutput ) {
+ if ( wfIsWindows() ) {
+ $this->markTestSkipped( 'This test requires a POSIX
environment.' );
+ }
+
+ $command = new ShellCommand( $command );
+ $command->execute();
+ $this->assertSame( $expectedExitCode, $command->getExitCode() );
+ $this->assertSame( $expectedOutput, $command->getOutput() );
+ }
+
+ public function provideExecute() {
+ return [
+ 'success status' => [ 'true', 0, '' ],
+ 'failure status' => [ 'false', 1, '' ],
+ 'output' => [ [ 'echo', '-n', 'x' ], 0, 'x' ],
+ ];
+ }
+}
diff --git a/tests/phpunit/includes/shell/ShellTest.php
b/tests/phpunit/includes/shell/ShellTest.php
new file mode 100644
index 0000000..1c7113a
--- /dev/null
+++ b/tests/phpunit/includes/shell/ShellTest.php
@@ -0,0 +1,27 @@
+<?php
+
+use MediaWiki\Shell;
+
+class ShellTest extends \PHPUnit_Framework_TestCase {
+ public function testIsDisabled() {
+ $this->assertInternalType( 'bool', Shell::isDisabled() ); //
sanity
+ }
+
+ /**
+ * @dataProvider provideEscape
+ */
+ public function testEscape( $args, $expected ) {
+ if ( wfIsWindows() ) {
+ $this->markTestSkipped( 'This test requires a POSIX
environment.' );
+ }
+ $this->assertSame( $expected, call_user_func_array( [
Shell::class, 'escape' ], $args ) );
+ }
+
+ public function provideEscape() {
+ return [
+ 'simple' => [ [ 'true' ], "'true'" ],
+ 'with args' => [ [ 'convert', '-font', 'font name' ],
"'convert' '-font' 'font name'" ],
+ 'array' => [ [ [ 'convert', '-font', 'font name' ] ],
"'convert' '-font' 'font name'" ],
+ ];
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/338312
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I89cc40d3414486707f911516bd1045504dfad83f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits