Skip to content

Commit

Permalink
chore: remove backup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Mar 10, 2024
1 parent c93e6a9 commit 28a9703
Show file tree
Hide file tree
Showing 25 changed files with 17 additions and 1,249 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
tests:
name: Symfony ${{ matrix.symfony-version }} - PHP ${{ matrix.php-version }} - flags ${{ matrix.composer-flags }} - mysqldump ${{ matrix.mysql-client }}
name: Symfony ${{ matrix.symfony-version }} - PHP ${{ matrix.php-version }} - flags ${{ matrix.composer-flags }}
runs-on: ubuntu-latest

strategy:
Expand All @@ -13,18 +13,13 @@ jobs:
php-version: ['']
composer-flags: ['']
symfony-version: ['']
mysql-client: [ "default-mysql-client" ]
include:
- php-version: 8.1
# Use "update" instead of "install" since it allows using the "--prefer-lowest" option
composer-flags: "update --prefer-lowest"
- php-version: 8.1
# add a specific job to test ^5.4 for all Symfony packages
symfony-version: "^5.4"
- php-version: 8.1
symfony-version: "^5.4"
# add a specific job to test mysqldump from MariaDB
mysql-client: "mariadb-client"
- php-version: 8.2
# add a specific job to test ^6.4 for all Symfony packages
symfony-version: "^6.4"
Expand Down Expand Up @@ -61,12 +56,6 @@ jobs:
- 27017:27017

steps:
- name: Install mysqldump
run: |
sudo apt update
sudo apt install -y -q ${{ matrix.mysql-client }}
mysqldump --version
- name: Install mongodb database tools
run: |
wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.3.1.deb
Expand Down
5 changes: 0 additions & 5 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ Here is the full configuration with default values:
liip_test_fixtures:
keep_database_and_schema: false
cache_metadata: true
cache_db: ~
```
- `keep_database_and_schema`: pass it to `true` to avoid deleting and creating the database and schema before each test, you'll have to create the database schema before running your tests:
1. create database with `bin/console --env=test doctrine:database:create`:
2. create schema with `bin/console --env=test doctrine:schema:update --force` or `bin/console --env=test doctrine:migrations:migrate --no-interaction`
- `cache_metadata`: using the cache slightly improve the performance
- `cache_db`: an array with a storage as key and a service as value, examples :
- `sqlite: 'Liip\TestFixturesBundle\Services\DatabaseBackup\SqliteDatabaseBackup'`
- `mysql: 'Liip\TestFixturesBundle\Services\DatabaseBackup\MysqlDatabaseBackup'`
- `mongodb: 'Liip\TestFixturesBundle\Services\DatabaseBackup\MongodbDatabaseBackup'`

« [Installation](./installation.md) • [Database](./database.md) »
34 changes: 0 additions & 34 deletions doc/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,40 +109,6 @@ Tips for Fixture Loading Tests

NB: If you have an existing Doctrine configuration which uses slaves be sure to separate out the configuration for the slaves. Further detail is provided at the bottom of this README.

2. In order to run your tests even faster, use LiipFunctionalBundle cached database.
This will create backups of the initial databases (with all fixtures loaded)
and re-load them when required.

**Attention: you need Doctrine >= 2.2 to use this feature.**

```yaml
# sf4: config/packages/test/framework.yaml
liip_test_fixtures:
cache_db:
sqlite: 'Liip\TestFixturesBundle\Services\DatabaseBackup\SqliteDatabaseBackup'
```

### Custom database cache services ([↑](#methods))

To create custom database cache service:

Create cache class, implement `\Liip\TestFixturesBundle\Services\DatabaseBackup\DatabaseBackupInterface` and add it to config

For example:
```yaml
# app/config/config_test.yml
liip_test_fixtures:
cache_db:
mysql: 'Liip\TestFixturesBundle\Services\DatabaseBackup\MysqlDatabaseBackup'
mongodb: 'Liip\TestFixturesBundle\Services\DatabaseBackup\MongodbDatabaseBackup'
db2: ...
[Other \Doctrine\DBAL\Platforms\AbstractPlatform name]: ...
```

**Attention: `Liip\TestFixturesBundle\Services\DatabaseBackup\MysqlDatabaseBackup` requires `mysql-client` installed on server.**

**Attention: `Liip\TestFixturesBundle\Services\DatabaseBackup\MongodbDatabaseBackup` requires `mongodb-clients` installed on server.**

### Load fixtures ([↑](#methods))

Load your Doctrine fixtures in your tests:
Expand Down
12 changes: 2 additions & 10 deletions doc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

Available events:

- `LiipTestFixturesEvents::PRE_FIXTURE_BACKUP_RESTORE`: triggered before restoring the backup
- `LiipTestFixturesEvents::POST_FIXTURE_BACKUP_RESTORE`: triggered after the backup has been restored
- `LiipTestFixturesEvents::POST_FIXTURE_SETUP`: triggered before purging the database
- `LiipTestFixturesEvents::PRE_REFERENCE_SAVE`: triggered before saving the backup of fixtures
- `LiipTestFixturesEvents::POST_REFERENCE_SAVE`: triggered before the backup of fixtures has been saved

## Registering events

Expand All @@ -28,16 +24,12 @@ class FixturesSubscriber implements EventSubscriberInterface
public static function getSubscribedEvents(): array
{
return [
LiipTestFixturesEvents::PRE_FIXTURE_BACKUP_RESTORE => 'preFixtureBackupRestore',
LiipTestFixturesEvents::POST_FIXTURE_SETUP => 'postFixtureSetup',
];
}

public function preFixtureBackupRestore(PreFixtureBackupRestoreEvent $preFixtureBackupRestoreEvent): void
public function postFixtureSetup(FixtureEvent $fixtureEvent): void
{
$manager = $preFixtureBackupRestoreEvent->getManager();
$repository = $preFixtureBackupRestoreEvent->getRepository();
$backupFilePath = $preFixtureBackupRestoreEvent->getBackupFilePath();

// your code
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/Event/FixtureEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,8 @@

namespace Liip\TestFixturesBundle\Event;

// Compatibility layer to use Contract if Symfony\Contracts\EventDispatcher\Event is not available
use Symfony\Contracts\EventDispatcher\Event;

if (class_exists('\Symfony\Component\EventDispatcher\Event')) {
// Symfony < 5.0
class FixtureEvent extends \Symfony\Component\EventDispatcher\Event
{
}
} else {
class FixtureEvent extends Event
{
}
class FixtureEvent extends Event
{
}
29 changes: 0 additions & 29 deletions src/Event/PostFixtureBackupRestoreEvent.php

This file was deleted.

49 changes: 0 additions & 49 deletions src/Event/PreFixtureBackupRestoreEvent.php

This file was deleted.

49 changes: 0 additions & 49 deletions src/Event/ReferenceSaveEvent.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/LiipTestFixturesEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,9 @@
namespace Liip\TestFixturesBundle;

use Liip\TestFixturesBundle\Event\FixtureEvent;
use Liip\TestFixturesBundle\Event\PostFixtureBackupRestoreEvent;
use Liip\TestFixturesBundle\Event\PreFixtureBackupRestoreEvent;
use Liip\TestFixturesBundle\Event\ReferenceSaveEvent;

final class LiipTestFixturesEvents
{
/** @see PreFixtureBackupRestoreEvent */
public const PRE_FIXTURE_BACKUP_RESTORE = 'liip_test_fixtures.pre_fixture_backup_restore';

/** @see FixtureEvent */
public const POST_FIXTURE_SETUP = 'liip_test_fixtures.post_fixture_setup';

/** @see PostFixtureBackupRestoreEvent */
public const POST_FIXTURE_BACKUP_RESTORE = 'liip_test_fixtures.post_fixture_backup_restore';

/** @see ReferenceSaveEvent */
public const PRE_REFERENCE_SAVE = 'liip_test_fixtures.pre_reference_save';

/** @see ReferenceSaveEvent */
public const POST_REFERENCE_SAVE = 'liip_test_fixtures.post_reference_save';
}
Loading

0 comments on commit 28a9703

Please sign in to comment.