Writing Codeception CLI test; want to throw exception but not have it fail the test -
i forked codeception/codeception , added command module check throws exception. when testing, exception causes test fail i'm running test force exception , failure, make sure catches it.
here's edit src/codeception/command/generatesuite.php
if ($this->containsinvalidcharacters ($suite)) { throw new \exception("suite name '{$suite}' contains invalid characters. ([a-za-z0-9_])."); }
when updating tests/cli/generatesuitecept.php when run command $i->executecommand('generate:suite invalid-suite');
fails because i'm throwing exception in src/codeception/command/generatesuite.php in first place.
here addition tests/cli/generatesuitecept.php:
$i->executecommand('generate:suite invalid-dash-suite');
when run it, says failed. however, want pass because i'm deliberately adding dash verify catches invalid characters. best way that? i'm wary of try/catch block in these tests. i'm not sure if best way that.
after looking @ other codeception tests, found better way throwing exception:
if ($this->containsinvalidcharacters ($suite)) { $output->writeln("<error>suite name '{$suite}' contains invalid characters. ([a-za-z0-9_]).</error>"); return; }
so modified test to:
$i->expect ('suite not created due dashes'); $i->executecommand('generate:suite invalid-dash-suite'); $i->seeinshelloutput('contains invalid characters');
Comments
Post a Comment