I have a project that relies heavily on config file configurations. I want to be able to test several different configurations, but this is turning into a massive headache. Right now, for each test I'm moving the standard config file to a temp file, copying the test config file to the right place, running the test, then moving the temp file back. All this file system work is starting to create problems and is difficult to maintain.
This is an example test that I have now
class MysqlExceptionTest extends TestCase
{
/**
*
*/
public static function tearDownAfterClass()
{
copy(getcwd() . '/tests/files/config.php', getcwd() . '/config.php');
unlink(getcwd() . '/temp.php');
}
/**
* Wrong config info
* @expectedException Exception
*/
public function test_wrong_config_info_throws_exception()
{
rename(getcwd() . '/config.php', getcwd() . '/temp.php');
copy(getcwd() . '/tests/files/wrong_config.php', getcwd() . '/config.php');
$mysql = new MysqlDatabase(new ConsoleOutput(), false);
$handle = $mysql->getHandle();
}
}
I have dozens of test like this, which means I have to maintain way too many different config files. Also, Travis CI doesnt seem to like this and gives me a lot more trouble than I think it should. I looked into mocking, but couldn't find a good way to mock a file/class and feed various outputs to other classes. Is there a better way to do this?
Aucun commentaire:
Enregistrer un commentaire