I'm trying to launch all my tests (unit + api) in Symfony3.1. When I separately launch them, everything goes well, but if I launch /vendor/bin/codecept run, unit tests are properly launched and are successful, but the api test always fails and are not lauched.
class_name: ApiTester
modules:
enabled:
- \AppBundle\Helper\Api
- REST:
url: /v1
depends: Symfony
- Doctrine2:
depends: Symfony
- Symfony:
app_path: '../../app'
var_path: '../../var'
Here's my codeception.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
include:
- src/AppBundle
coverage:
enabled: true
whitelist:
include:
- src/*
exclude:
- src/AppBundle/Entity/*
- src/AppBundle/tests/*
- src/AppBundle/codeception.yml
Any idea how I could do? I have the following call stack:
Call Stack:
0.0003 366728 1. {main}() /var/www/metadata/vendor/codeception/codeception/codecept:0
0.0491 4670576 2. Codeception\Application->run() /var/www/metadata/vendor/codeception/codeception/codecept:33
0.0491 4670576 3. Symfony\Component\Console\Application->run() /var/www/metadata/vendor/codeception/codeception/src/Codeception/Application.php:103
0.0507 4815576 4. Symfony\Component\Console\Application->doRun() /var/www/metadata/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
0.0508 4815576 5. Symfony\Component\Console\Application->doRunCommand() /var/www/metadata/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:186
0.0508 4815576 6. Symfony\Component\Console\Command\Command->run() /var/www/metadata/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:815
0.0512 4818056 7. Codeception\Command\Run->execute() /var/www/metadata/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256
0.1006 6650440 8. Codeception\Command\Run->runIncludedSuites() /var/www/metadata/vendor/codeception/codeception/src/Codeception/Command/Run.php:261
0.1042 6657592 9. Codeception\Command\Run->runSuites() /var/www/metadata/vendor/codeception/codeception/src/Codeception/Command/Run.php:298
0.1660 9802776 10. Codeception\Codecept->run() /var/www/metadata/vendor/codeception/codeception/src/Codeception/Command/Run.php:329
0.1676 9807696 11. Codeception\Codecept->runSuite() /var/www/metadata/vendor/codeception/codeception/src/Codeception/Codecept.php:178
0.1693 10023184 12. Codeception\SuiteManager->initialize() /var/www/metadata/vendor/codeception/codeception/src/Codeception/Codecept.php:207
0.1693 10023184 13. Codeception\Module\Symfony->_initialize() /var/www/metadata/vendor/codeception/codeception/src/Codeception/SuiteManager.php:81
I followed it but the problem comes from the SuiteManager, when it calls the _initialize method of my AppBundle\Helper\Api which is quite simple:
<?php
namespace AppBundle\Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Api extends \Codeception\Module
{
/**
* Checks over the given HTTP header and (optionally)
* its value, asserting that are there
*
* @param $header
* @param $value
*/
public function seeHttpHeaderLike($header, $value)
{
$header = $this->getModule('REST')->grabHttpHeader($header);
$this->assertRegExp($value, $header);
}
}
I always have the same error:
Fatal error: Cannot declare class Symfony\Component\HttpFoundation\FileBag, because the name is already in use in [...]/var/bootstrap.php.cache on line 308
If I removed some code calling the FileBag (request attributes), I have the same error but with Symfony\Component\HttpFoundation\Request
Thanks in advance
I have the same error and it comes from the require_once here: https://github.com/Codeception/Codeception/blob/2.2/src/Codeception/Module/Symfony.php#L149
It seems like the _initialize function from this class is not compatible with Symfony 3.1. If i remove the lines below, my problem is solved:
$cache = Configuration::projectDir() . $this->config['var_path'] . DIRECTORY_SEPARATOR . 'bootstrap.php.cache';
if (!file_exists($cache)) {
throw new ModuleRequireException(__CLASS__,
"Symfony bootstrap file not found in $cache\n \n" .
"Please specify path to bootstrap file using `var_path` config option\n \n" .
"If you are trying to load bootstrap from a Bundle provide path like:\n \n" .
"modules:\n enabled:\n" .
" - Symfony:\n" .
" var_path: '../../app'\n" .
" app_path: '../../app'"
);
}
require_once $cache;
All vendors are already loaded here: https://github.com/Codeception/Codeception/blob/2.2/autoload.php#L6
And if i want to use the Symfony autoload located in app/, i can do it in my codeception _bootstrap file.
Are we doing something wrong or is it a bug?
Thank you @linconnu! You made my day :-D
<3 <3 <3 <3
You can fix your issue without editing the vendor, you just have to enable the Symfony module in all your suite yml (unit and functional).
All credits goes to this post : http://phptest.club/t/symfony-redeclare-class-bootstrap-php-cache-issue-with-codception-2-1-3-on-circle-ci/656
(Here is the quote in case the post disappear):
We create unit tests separately with phpunit but use codeception to execute them (which it does seamlessly) but since we were using phpunit when writing the tests we never cared to include Symfony2 as a module in the yml file which meant that the symfony modules were getting loaded separately before the functional test module was called which was using symfony2 module.
Since Symfony2 module uses bootstrap.php.cache file, this lead to redeclaring the classes which were already directly called by phpunit when unit testing.
Somehow this issue didn't occur on local systems as the order of the tests called was interchanged and unit tests were called after functional tests.
So, all we had to do to fix this issue was to include Symfony2 module in the unit tests yml file and that fixed the issue.
So just enable the Symfony module in all your suite yml configuration like describe here : http://codeception.com/docs/modules/Symfony
[Codeception\Exception\ModuleConflictException]
Symfony module conflicts with PhpBrowser
--
This usually happens when you enable two modules with the same actions but with different backends.
For instance, you can't run PhpBrowser, WebDriver, Laravel5 modules in one suite,
as they implement similar methods but use different drivers to execute them.
You can load a part of module (like: ORM) to avoid conflict.
Hello everybody, I have fixed it with that:
class_name: FunctionalTester
modules:
enabled:
- Symfony2:
app_path: '../../app'
var_path: '../../var'
- Doctrine2:
depends: Symfony2
- \BackendBundle\Helper\Functional
- Asserts
- Sequence
Most helpful comment
I have the same error and it comes from the
require_oncehere: https://github.com/Codeception/Codeception/blob/2.2/src/Codeception/Module/Symfony.php#L149It seems like the _initialize function from this class is not compatible with Symfony 3.1. If i remove the lines below, my problem is solved:
All vendors are already loaded here: https://github.com/Codeception/Codeception/blob/2.2/autoload.php#L6
And if i want to use the Symfony autoload located in app/, i can do it in my codeception _bootstrap file.
Are we doing something wrong or is it a bug?