samedi 24 janvier 2015

PHPUnit: mock non-existing classes

Is it possible to create a mock of non-existing class in PHPUnit?

Let's assume I have some class that creates instance of another class, for example:



class TaskRunner
{
public function runTasks()
{
// Run through some loop to get tasks and store each in $taskName
// Get task instance by given task name
$task = $this->getTaskInstance($taskName);
if ($task instanceof AbstractTask) {
$task->run();
}
}

protected function getTaskInstance($taskName)
{
// Just an example
return new $taskName();
}
}


I would like to run unit test for runTasks method to check if created task instace extends some abstract class.

Is there any possibility to NOT to create sample class in a filesystem to check the inheritance constraint?

Thanks for all!


Aucun commentaire:

Enregistrer un commentaire