I'm trying to introduce functional testing into an old codebase using various tools, one of which is Codeception (2.2.0). Acceptance tests pass a basic log in scenario:
public function login($name, $password)
{
$I = $this;
$I->amOnPage('/login');
$I->submitForm('.loginform', array(
'_username' => $name,
'_password' => $password
));
$I->see('User', '.navbar');
}
however when I try to run a functional test of the same scenario, it fails
[Exception] environment instance is already set
Looking at the stack trace, it originates from the listener that is registering the instance:
public function onKernelRequest() {
$this->getContainer()->get('environment');
}
which leads to the service in config.yml:
environment:
class: MyApp\Environment
calls:
- [ setContainer, [ @service_container ] ]
pointing to the class:
class Environment {
public function __construct() {
self::setInstance($this);
}
public static function setInstance(Environment $environment) {
if (null !== self::$instance) {
throw new \Exception('environment instance is already set');
}
self::$instance = $environment;
}
How best can I understand how to remove the error with the functional testing? Is the code an anti-pattern and in need of refactoring? Or is it a problem with my Codeception configuration?
class_name: FunctionalTester
modules:
enabled:
- Symfony2:
app_path: 'app'
var_path: 'app'
- Doctrine2:
depends: Symfony2
- \Helper\Functional
- Asserts
- Sequence
If you need me to add more information here, let me know.
Update
I found this answer and by switching from Symfony module to PhpBrowser, the tests passed. However, the original question - of how to run the functional test using the Symfony module - persists.