PHP code example of elythyr / prooph-fixtures

1. Go to this page and download the library: Download elythyr/prooph-fixtures library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

elythyr / prooph-fixtures example snippets


// /test.php

// Configure your system:
// Replace it by your own container or create everything manually :'(
$container = new class() implements ContainerInterface {
    public function has($id) { return false; }
    public function get($id) { return null; }
};

// Retrieve your event store
$eventStore = $container->get('event_store');

// Create a provider for your fixtures
$fixturesProvider = new InMemoryFixturesProvider([
    $youContainer->get('a_fixture'),
    $youContainer->get('another_fixture'),
    // ...
]);

// Retrieve the cleaning projection strategy
// No implementations are provided since it depends on your EventStore implementation
$cleaningProjectionStrategy = $container->get('cleaning_projection_strategy');

// Retrieve the names of all your projections
$projectionsNames = $container->get('projections_names');

// Create the cleaner you want to use, here we will clean both event streams and projections
$cleaner = new ChainCleaner([
    new EventStreamsCleaner($eventStore),
    new ProjectionsCleaner(
        $cleaningProjectionStrategy,
        $projectionsNames
    ),
]);

// Create the fixtures manager, just a front to regroup everything in one place
$fixturesManager = new FixturesManager($fixturesProvider, $cleaner);

// Lets do some cleaning !
$fixturesManager->cleanUp();

// Loading is so easy, you can do it yourself :)
// Under the hood the manager do all the heavy lifting by ordering the fixtures
foreach ($fixturesManager->getFixtures() as $fixture) {
    $fixture->load();
}