Skip to content

Commit

Permalink
dev: Enable DAMA DoctrineTestBundle in tests
Browse files Browse the repository at this point in the history
This package drastically improves performance of the tests by rolling
back changes in database after each test.
  • Loading branch information
marien-probesys committed Mar 13, 2024
1 parent f8036d9 commit 15eca8a
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 1 deletion.
1 change: 1 addition & 0 deletions .phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
</source>

<extensions>
<bootstrap class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
</extensions>
</phpunit>
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
}
},
"require-dev": {
"dama/doctrine-test-bundle": "^8.0",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^10.5",
"rector/rector": "^0.19.5",
Expand Down
70 changes: 69 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Expand Down
3 changes: 3 additions & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ doctrine:
#server_version: '15'

profiling_collect_backtrace: '%kernel.debug%'

use_savepoints: true

orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
Expand Down
9 changes: 9 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"dama/doctrine-test-bundle": {
"version": "8.0",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "7.2",
"ref": "896306d79d4ee143af9eadf9b09fd34a8c391b70"
}
},
"doctrine/doctrine-bundle": {
"version": "2.11",
"recipe": {
Expand Down
14 changes: 14 additions & 0 deletions tests/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace App\Tests;

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Command\Command;
use Zenstruck\Foundry\Test\ResetDatabase;
Expand All @@ -15,6 +16,19 @@ class MigrationsTest extends KernelTestCase
use CommandTestsHelper;
use ResetDatabase;

public static function setUpBeforeClass(): void
{
// We need to disable DoctrineTestBundle for this test, or it fails
// when using MariaDB, with "Exception in third-party event subscriber:
// There is no active transaction".
StaticDriver::setKeepStaticConnections(false);
}

public static function tearDownAfterClass(): void
{
StaticDriver::setKeepStaticConnections(true);
}

public function testMigrationsUpWork(): void
{
// erase the database structure
Expand Down

0 comments on commit 15eca8a

Please sign in to comment.