atoum/atoum — pull request #310 by jubianchi (2013-11-13 22:01:45+00:00)
Title: Add a test factory to atoum's runner

With this patch, tests are not anymore directly instanciated in runner.

It now uses a tiny factory in the form of a simple closure which has to return the test instance.
This allows us to be a bit more flexible when extending atoum.

For example, in the AtoumBundle, to resolve the atoum/AtoumBundle#46, we have to inject a parameter coming from the command line or the Symfony configuration to the test instance.

To do that, I overrode atoum's runner, adding the method require in my own runner class to store the parameter. But then, I could not pass it to the tests without copying much code from the original runner.

Here is a quick example on how it is implemented:

```php
setTestFactory();
}

public function setTestFactory(\Closure $factory = null)
{
$this->runner->setTestFactory($factory ?: $this->getDefaultTestFactory());

return $this;
}

public function getDefaultTestFactory()
{
return function($testClass) use ($self) {
$test = new $testClass();

if ($test instanceof WebTestCase) {
$test->setKernelEnvironment($self->getEnvironment());
}

return $test;
};
}

//...
}
```

_See atoum/AtoumBundle#46 on atoum/AtoumBundle for the full implementation_

With this implementation, I can easily make my own initialization on tests instances.