PHP code example of lzakrzewski / doctrine-database-backup

1. Go to this page and download the library: Download lzakrzewski/doctrine-database-backup 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/ */

    

lzakrzewski / doctrine-database-backup example snippets


/** {@inheritdoc} */
protected function setUp()
{
    parent::setUp();

    $this->entityManager = $this->createEntityManager();

    $backup = new DoctrineDatabaseBackup($this->entityManager);
    $backup->restore();
}

/** {@inheritdoc} */
protected function setUp()
{
    parent::setUp();

    $this->entityManager = $this->createEntityManager();
    $backup = new DoctrineDatabaseBackup($this->entityManager);
    
    $backup->restore(function (EntityManager $entityManager) {
        //your fixtures
        $entityManager->persist(new TestProduct('Iron', 99));
        $entityManager->flush();
    });
}

/** @BeforeScenario*/
public function restoreDatabase()
{
    // "getEntityManager" is your own getter for EntityManager
    $backup = new DoctrineDatabaseBackup($this->getEntityManager());
    $backup->restore();
}