theofidry / AliceBundleExtension

Behat extension for HautelookAliceBundle.
MIT License
36 stars 23 forks source link

hautelook/AliceBundle 2.0 #27

Open goetas opened 6 years ago

goetas commented 6 years ago

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

theofidry commented 6 years ago

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 commented 6 years ago

@goetas did you fixed your problem?

goetas commented 6 years ago

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 commented 6 years ago

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