Common issues that you may run into when configuring or running Laravel Doctrine.

The DatabaseTransactions trait is not working for tests

You will need to use a new trait instead of the default Laravel trait. Here is an example of an implementation:


namespace Tests;

use LaravelDoctrine\ORM\Facades\EntityManager;

trait DoctrineDatabaseTransactions
    public function setUpDoctrineDatabaseTransactions(): void

    public function tearDownDoctrineDatabaseTransactions(): void

If you would like to also use assertDatabaseHas in your tests, you need to tell Laravel to use the same connection as Doctrine is using so that it can find rows that have not been committed in a transaction:

$pdo = app()->make(\Doctrine\ORM\EntityManagerInterface::class)->getConnection()


ErrorException: require(.../storage/proxies/CGEntity.php): Failed to open stream: No such file or directory

Proxies need to be generated before they can be used. You can generate the proxies manually using the php artisan doctrine:generate:proxies command, or you can enable proxy auto generation in your doctrine.php config file. By default, you can set the DOCTRINE_PROXY_AUTOGENERATE environment value to true to enable auto generation.

Note: Proxy auto generation should always be disabled in production for performance reasons.