项目作者: camilledejoye

项目描述 :
Clean your DB and reload your events !
高级语言: PHP
项目地址: git://github.com/camilledejoye/prooph-fixtures.git
创建时间: 2018-12-26T23:37:21Z
项目社区:https://github.com/camilledejoye/prooph-fixtures

开源协议:MIT License

下载


Prooph Fixtures

Build Status
Coverage Status

During my experiments with ES I find myself in a situation where Doctrine data fixtures missed me.

Thats why I decided to try to reproduce something similar for Prooph.

Installation

Oh, sweet Composer!

  1. composer require --dev elythyr/prooph-fixtures

Versions management

Since its a practice project, I don’t really care about BC breaks.
I will only try to not break minor versions, meaning that:

  • Updating from 1.0.0 to 1.0.9 should not break anything
  • Updating from 1.0.0 to 1.1.0 might break a lot of stuff

Configuration

There is no configuration per se.
All the configuration should already be done, see Prooph EventStore
for more information.

Usage

An example of how to configure the pieces together:

  1. // /test.php
  2. // Configure your system:
  3. // Replace it by your own container or create everything manually :'(
  4. $container = new class() implements ContainerInterface {
  5. public function has($id) { return false; }
  6. public function get($id) { return null; }
  7. };
  8. // Retrieve your event store
  9. $eventStore = $container->get('event_store');
  10. // Create a provider for your fixtures
  11. $fixturesProvider = new InMemoryFixturesProvider([
  12. $youContainer->get('a_fixture'),
  13. $youContainer->get('another_fixture'),
  14. // ...
  15. ]);
  16. // Retrieve the cleaning projection strategy
  17. // No implementations are provided since it depends on your EventStore implementation
  18. $cleaningProjectionStrategy = $container->get('cleaning_projection_strategy');
  19. // Retrieve the names of all your projections
  20. $projectionsNames = $container->get('projections_names');
  21. // Create the cleaner you want to use, here we will clean both event streams and projections
  22. $cleaner = new ChainCleaner([
  23. new EventStreamsCleaner($eventStore),
  24. new ProjectionsCleaner(
  25. $cleaningProjectionStrategy,
  26. $projectionsNames
  27. ),
  28. ]);
  29. // Create the fixtures manager, just a front to regroup everything in one place
  30. $fixturesManager = new FixturesManager($fixturesProvider, $cleaner);
  31. // Lets do some cleaning !
  32. $fixturesManager->cleanUp();
  33. // Loading is so easy, you can do it yourself :)
  34. // Under the hood the manager do all the heavy lifting by ordering the fixtures
  35. foreach ($fixturesManager->getFixtures() as $fixture) {
  36. $fixture->load();
  37. }

Todo

  • Adds CI with Travis
  • Adds tests coverage
  • Make a first release
  • Publish to packagist
  • (When needed) Adds the possibility to not clean the DB
  • (When needed) Adds the possibility to filter the fixtures to load