Skip to content
This repository has been archived by the owner on Sep 25, 2022. It is now read-only.

hautelook/AliceBundle 2.0 #27

Open
goetas opened this issue Dec 13, 2017 · 4 comments
Open

hautelook/AliceBundle 2.0 #27

goetas opened this issue Dec 13, 2017 · 4 comments

Comments

@goetas
Copy link

goetas commented Dec 13, 2017

Any plan to have AliceBundleExtension compatible with hautelook/AliceBundle 2.0 ?

@theofidry
Copy link
Owner

theofidry commented Dec 13, 2017

Not really. Not that I'm not interested in it but I don't really use that extension anymore so whilst I'll gladly accept any PR I don't really want to actively work on it.

That said if there is any upgrade, I think HautelookAliceBundle can be ditched for FidryAliceDataFixtures for this extension

@OskarStark
Copy link

@goetas did you fixed your problem?

@goetas
Copy link
Author

goetas commented May 31, 2018

yes, just wrote it on my own... was simpler than expected.

Here it is

<?php

namespace App\Tests\Behat\Context;

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
use Fidry\AliceDataFixtures\LoaderInterface;
use Fidry\AliceDataFixtures\Persistence\PurgeMode;

class FidryAliceDataFixturesLoaderContext implements Context
{

    /**
     * @var LoaderInterface
     */
    private $loader;

    public function __construct(LoaderInterface $loader)
    {
        $this->loader = $loader;
    }

    /**
     * @Given the fixtures :fixturesFile are loaded
     * @Given the fixtures file :fixturesFile is loaded
     *
     * @param string $fixturesFile Path to the fixtures
     */
    public function thereAreFixtures($fixturesFile)
    {
        $this->loader->load([$fixturesFile]);
    }

    /**
     * @Given the following fixtures are loaded:
     * @Given the following fixtures files are loaded:
     * @Given /^the following fixtures are loaded using the (append|delete|truncate) purger:$/
     *
     * @param TableNode $fixturesFiles Path to the fixtures
     */
    public function thereAreSeveralFixtures(TableNode $fixtures, $purgeMode = null)
    {
        switch ((string)$purgeMode){
            case 'append';
                $purgeMode = PurgeMode::createNoPurgeMode();
                break;
            case 'truncate';
                $purgeMode = PurgeMode::createTruncateMode();
                break;
            case 'delete';
            case '';
                $purgeMode = PurgeMode::createDeleteMode();
                break;
           default;
                throw new \RuntimeException("Invalid purge mode");
                break;
        }

        $fixturesFiles = [];

        foreach ($fixtures->getRows() as $fixturesFileRow) {
            $fixturesFiles[] = $fixturesFileRow[0];
        }
        $this->loader->load($fixturesFiles ,  $parameters = [], $objects = [], $purgeMode);
    }
}

thats it!

@goetas
Copy link
Author

goetas commented May 31, 2018

it would be nice to have it as extension... but for my case worked good enough.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants