Skip to content

Commit

Permalink
Revert "chore: remove last references to database cache"
Browse files Browse the repository at this point in the history
This reverts commit 208fe5f.
  • Loading branch information
alexislefebvre committed Jul 2, 2024
1 parent 2ca04d2 commit ebe5cce
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ Methods

It also give access to other helpers:

- `setDatabaseCacheEnabled()` accept `true` or `false` to disable the cache
- you can call `$this->databaseTool->withDatabaseCacheEnabled(false)->loadFixtures(…)` to disable the cache on-demand

- `setPurgeMode()` accept `true` or `false` to disable purging the database
- you can call `$this->databaseTool->withPurgeMode(false)->loadFixtures(…)` to disable the purging on-demand

Expand Down
1 change: 1 addition & 0 deletions doc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare(strict_types=1);

namespace Liip\Acme\Tests\AppConfigEvents\EventListener;

use Liip\TestFixturesBundle\Event\PreFixtureBackupRestoreEvent;
use Liip\TestFixturesBundle\LiipTestFixturesEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand Down
9 changes: 9 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode
->children()
->arrayNode('cache_db')
->addDefaultsIfNotSet()
->ignoreExtraKeys(false)
->children()
->scalarNode('sqlite')
->defaultNull()
->end()
->end()
->end()
->booleanNode('keep_database_and_schema')->defaultFalse()->end()
->booleanNode('cache_metadata')->defaultTrue()->end()
;
Expand Down
15 changes: 14 additions & 1 deletion src/DependencyInjection/LiipTestFixturesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('database_tools.xml');

foreach ($config as $key => $value) {
$container->setParameter($this->getAlias().'.'.$key, $value);
// If the node is an array,
// e.g. "liip_test_fixtures.cache_db.mysql",
// set the value as
// "liip_test_fixtures.cache_db.mysql"
// instead of an array "liip_test_fixtures.cache_db"
// with a "mysql" key.
if (\is_array($value)) {
foreach ($value as $key2 => $value2) {
$container->setParameter($this->getAlias().'.'.$key.
'.'.$key2, $value2);
}
} else {
$container->setParameter($this->getAlias().'.'.$key, $value);
}
}
}
}
15 changes: 15 additions & 0 deletions src/Resources/config/database_tools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
<argument type="service" id="doctrine_mongodb.odm.symfony.fixtures.loader" on-invalid="null"/>
</service>

<service id="Liip\TestFixturesBundle\Services\DatabaseBackup\SqliteDatabaseBackup" public="true">
<argument type="service" id="service_container" />
<argument type="service" id="Liip\TestFixturesBundle\Services\FixturesLoaderFactory" />
</service>

<service id="Liip\TestFixturesBundle\Services\DatabaseBackup\MysqlDatabaseBackup" public="true">
<argument type="service" id="service_container" />
<argument type="service" id="Liip\TestFixturesBundle\Services\FixturesLoaderFactory" />
</service>

<service id="Liip\TestFixturesBundle\Services\DatabaseBackup\MongodbDatabaseBackup" public="true">
<argument type="service" id="service_container" />
<argument type="service" id="Liip\TestFixturesBundle\Services\MongoDBFixturesLoaderFactory" />
</service>

<service id="Liip\TestFixturesBundle\Services\DatabaseTools\ORMDatabaseTool" public="false">
<argument type="service" id="service_container" />
<argument type="service" id="Liip\TestFixturesBundle\Services\FixturesLoaderFactory" />
Expand Down
4 changes: 4 additions & 0 deletions tests/AppConfig/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ framework:
liip_test_fixtures:
keep_database_and_schema: false
cache_metadata: true
cache_db:
sqlite: 'Liip\TestFixturesBundle\Services\DatabaseBackup\SqliteDatabaseBackup'
mysql: 'Liip\TestFixturesBundle\Services\DatabaseBackup\MysqlDatabaseBackup'
mongodb: 'Liip\TestFixturesBundle\Services\DatabaseBackup\MongodbDatabaseBackup'

services:
# HautelookAliceBundle: custom Faker provider
Expand Down

0 comments on commit ebe5cce

Please sign in to comment.