Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] chore: remove backup #289

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 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 @@ -14,18 +14,13 @@ jobs:
php-version: ['8.2']
composer-flags: ['']
symfony-version: ['^6.4']
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.2
symfony-version: "^6.4"
# add a specific job to test mysqldump from MariaDB
mysql-client: "mariadb-client"
- php-version: 8.2
symfony-version: "^7.0"
- php-version: 8.3
Expand Down Expand Up @@ -59,18 +54,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
sudo apt install ./mongodb-database-tools-*.deb
rm -f mongodb-database-tools-*.deb

- name: Checkout
uses: actions/checkout@v4

Expand Down Expand Up @@ -113,7 +96,7 @@ jobs:
run: echo '127.0.0.1 mariadb postgres mongodb' | sudo tee -a /etc/hosts

- name: Run tests
# Run tests twice to ensure that tests are idempotent even if database caching is enabled
# Run tests twice to ensure that tests are idempotent
run: |
php ./vendor/bin/phpunit --testdox --process-isolation
php ./vendor/bin/phpunit --testdox --process-isolation
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