Open 99hops opened 4 years ago
Have you got it working?
Dependencies were messed up in that configuration. Doctrine2 module must depend on framework module, but Laravel5 module (and Laravel module now) does not implement DoctrineProvider interface, so you have to implement helper module which implements DoctrineProvider interface and retrieves the instance of Doctrine Entity Manager from Laravel module.
@TavoNiievez Would it be possible to implement DoctrineProvider interface in Laravel module?
Would it be possible to implement the DoctrineProvider interface in the Laravel module?
Absolutely yes.
However, by far, that's not the biggest challenge.
The most popular way to integrate the Doctrine ORM into Laravel is with the lavarel-doctrine project. There are complete but somewhat outdated guides with which you can achieve this in the test project, updating some things like the validation.
To implement this method, we should also check that the integration of the Doctrine and Laravel modules works in their entirety.
I can gladly guide the process if anyone is interested in forking the test project and integrating Doctrine for the two Laravel versions that are currently being tested (6.x
LTS and the most recent 8.x main
).
From there the implementation of _getEntityManager()
can be carried out, and tests could be written to verify the integration, as well as update create the corresponding documentation.
What's wrong with this issue is that, for some reason, the _before
hook of the Doctrine module executes before the one of the Laravel module, while the _after
hook of the Doctrine module never executes.
Adding the following makes both the Doctrine integration and the cleanup: true
option work:
public function _getEntityManager()
{
if (!$this->client) {
$this->client = new LaravelConnector($this);
}
return $this->app['em'];
}
and...
public function _before(TestInterface $test)
{
$this->client = new LaravelConnector($this);
$this->getModule('Doctrine2')->_before($test);
}
public function _after(TestInterface $test)
{
$this->getModule('Doctrine2')->_after($test);
}
Of course, this is not the best solution... It is still necessary to check details such as that the memory is cleaned correctly.
But now that there is where to do tests ( https://github.com/TavoNiievez/laravel-module-tests/tree/doctrine ) it should be easier to solve these problems.
What are you trying to achieve?
Rollback transactions between each test
What do you get instead?
Database changes not reverted
Details
Codeception version:
PHP Version: 4.1.4
Operating System: Unbuntu 20.04
Installation type: Composer
List of installed packages (
composer show
)Suite configuration:
At the end the first test passed but the second one which is trying to insert the same db record fails and the previous one is not removed.
What's specific in this project is that is uses Laravel (6.18.13) with Doctrine (1.5 provided by laravel-doctrine/orm). I tried everything possible I could find without success.
What's obvious is [Database] Transaction started / [Database] Transaction cancelled; all changes reverted.
Could it be that the Laravel5 module only supports Eloquent?
Refering here https://codeception.com/for/laravel#functional-tests it is stated: "Codeception will also use Eloquent to cleanup changes to database by wrapping tests into transaction and rolling it back in the end of a test. This makes tests isolated and fast. Laravel5 module allows to access services from DIC container, user authentication methods, fixture generators, check form validations and more."
If so what options do I have to make this work with Doctrine?