aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/shell/ShellTest.php
diff options
context:
space:
mode:
authorMax Semenik <maxsem.wiki@gmail.com>2016-11-02 17:27:15 -0700
committerMax Semenik <maxsem.wiki@gmail.com>2017-09-08 21:49:49 -0700
commit77ce3b98a0193b674232e972e7c6993a585412d7 (patch)
tree394dbc0788977649fd62b3cc976ea1209220aed0 /tests/phpunit/includes/shell/ShellTest.php
parent104d86442554b466c282834c780eed3580a146d7 (diff)
downloadmediawikicore-77ce3b98a0193b674232e972e7c6993a585412d7.tar.gz
mediawikicore-77ce3b98a0193b674232e972e7c6993a585412d7.zip
Replace wfShellExec() with a class
This function has gotten so unwieldy that a helper was introduced. Instead, here's this class that makes shelling out easier and more readable. Example usage: $result = Shell::command( 'shell command' ) ->environment( [ 'ENVIRONMENT_VARIABLE' => 'VALUE' ] ) ->limits( [ 'time' => 300 ] ) ->execute(); $exitCode = $result->getExitCode(); $output = $result->getStdout(); This is a minimal change, so lots of stuff remains unrefactored - I'd rather limit the scope of this commit. A future improvement could be an ability to get stderr separately from stdout. Caveat: execution errors (proc_open is disabled/returned error) now throw errors instead of returning a status code. wfShellExec() still emulates this behavior though. Competing commit: I7dccb2b67a4173a8a89b035e444fbda9102e4d0f <legoktm> MaxSem: so you should continue working on your patch and I'll probably refactor on top of it later after its merged :P Change-Id: I8ac9858b80d7908cf7e7981d7e19d0fc9c2265c0
Diffstat (limited to 'tests/phpunit/includes/shell/ShellTest.php')
-rw-r--r--tests/phpunit/includes/shell/ShellTest.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/phpunit/includes/shell/ShellTest.php b/tests/phpunit/includes/shell/ShellTest.php
new file mode 100644
index 000000000000..1e91074fd400
--- /dev/null
+++ b/tests/phpunit/includes/shell/ShellTest.php
@@ -0,0 +1,30 @@
+<?php
+
+use MediaWiki\Shell\Shell;
+
+/**
+ * @group 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'" ],
+ ];
+ }
+}