I can’t do it right, the exception error message just prints out, which makes it difficult to read the command prompt window. The following is the procedure for structuring my code and test code.
public function availableFruits($fruit)
{
switch($fruit) {
case 'foo':
break;
case 'bar':
break;
default:
throw new Exception($fruit.' not available!');
break;
}
}
public function chooseFruit($fruit)
{
try {
availableFruits($fruit);
} catch (Exception $e) {
echo $e->getMessage();
}
}
public function testAvailableFruits()
{
$this->setExpectedException('Exception');
chooseFruit('Kiwi');
}
An error message will be printed on the command line window, as shown below. I tried all the methods shown in phpunit.de, but the same results.
..Error on line 13 in c:\file\path\fruits.php: Kiwi not available!.F
The error line prints, how can I suppress it, am I doing it right?
source
share