00001 <?php
00008 class UTShellCmd extends foUnitTestBase
00009 {
00010 public function doTest()
00011 {
00012 $this->testExec();
00013
00014
00015 }
00016
00017 function testExec()
00018 {
00019 $this->setSectionLabel('exec');
00020
00021 try
00022 {
00023 eval($this->needEqual('ShellCmd::exec("uname")', '"Linux\n"'));
00024 eval($this->needEqual('ShellCmd::exec("uptime | wc -l")', '"1\n"'));
00025 eval($this->needEqual('ShellCmd::exec("wc", "I may be synthetic, but I\'m not stupid.\n\n")', '" 2 8 41\n"'));
00026 }
00027 catch (Exception $e)
00028 {
00029 eval($this->needEmpty('$e->getMessage()'));
00030 }
00031
00032 try
00033 {
00034 ShellCmd::exec("ls -2");
00035 }
00036 catch (Exception $e)
00037 {
00038 eval($this->needEqual('$e->getMessage()', '"ls: invalid option -- \'2\'\nTry `ls --help\' for more information.\n Exit code: 2"'));
00039 }
00040 }
00041
00042 function testSshExec()
00043 {
00044 $this->setSectionLabel('sshExec');
00045
00046 try
00047 {
00048 eval($this->needEqual('ShellCmd::sshExec("arlukin@localhost", "uname")', '"Linux\n"'));
00049 eval($this->needEqual('ShellCmd::sshExec("arlukin@localhost", "uptime | wc -l")', '"1\n"'));
00050 eval($this->needEqual('ShellCmd::sshExec("arlukin@localhost", "wc", "I may be synthetic, but I\'m not stupid.\n\n")', '" 2 8 41\n"'));
00051 }
00052 catch (Exception $e)
00053 {
00054 eval($this->needEmpty('$e->getMessage()'));
00055 }
00056
00057 try
00058 {
00059 ShellCmd::sshExec("arlukin@localhost", "ls -2");
00060 }
00061 catch (Exception $e)
00062 {
00063 eval($this->needEqual('$e->getMessage()', '"ls: invalid option -- \'2\'\nTry `ls --help\' for more information.\n Exit code: 2"'));
00064 }
00065 }
00066 }
00067
00068 ?>