Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using fixtures in functional tests #316

Open
Kris1992 opened this issue May 5, 2020 · 2 comments
Open

Using fixtures in functional tests #316

Kris1992 opened this issue May 5, 2020 · 2 comments

Comments

@Kris1992
Copy link

Kris1992 commented May 5, 2020

Hi,
I had problem with load fixtures in behat based functional tests. When I load fixture class with Dependency Injection inside it, it works fine, but when I try to load another fixture which depends on first one by getDependencies() method I take following error:

Type error: Too few arguments to function App\DataFixtures\UserFixtures::__construct(), 0 passed in vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php on line 231 and exactly 2 expected (Behat\Testwork\Call\Exception\FatalThrowableError)

Below is code from behat loading process and fixtures :

Behat loader:

`
private function loadFixtures($fixturesNames)
{
//use Doctrine\Common\DataFixtures\Loader;
//I tried $loader = new ContainerAwareLoader($this->kernel->getContainer()); too but with the same result :(

    $loader = new Loader();

    foreach ($fixturesNames as $fixtureName) {
        $fixture = $this->kernel->getContainer()->get('App\DataFixtures\\'.$fixtureName.'Fixtures');
        $loader->addFixture($fixture);
    }

    $executor = new ORMExecutor($this->getEntityManager());
    $executor->execute($loader->getFixtures(), true);
}

`

Fixture one (if I run this fixture in bahat alone it works)

`
class UserFixtures extends BaseFixture
{

private $passwordEncoder;
private $userImageManager;

//That contructor makes problem
public function __construct(UserPasswordEncoderInterface $passwordEncoder, ImagesManagerInterface $userImageManager)
{
    $this->passwordEncoder = $passwordEncoder;
    $this->userImageManager = $userImageManager;
}

`

Fixture 2:
class FooFixtures extends BaseFixture implements DependentFixtureInterface { public function getDependencies() { //When I do that if, behat works ok, but if it's possible I don't want that if here because some fixtures needs only UserFixtures::class and I cannot push empty array here if ($_ENV['APP_ENV'] !== 'test') { return [ UserFixtures::class, Foo2Fixtures::class, Foo3Fixtures::class, Foo4Fixtures::class, ]; } else { return [ //UserFixtures::class, Foo2Fixtures::class, Foo3Fixtures::class, Foo4Fixtures::class, ]; } }

I'm not sure it strictly depends of DoctrineFixturesBundle, but I look for answer and maybe someone from here know the solution. Thanks for any reply.

@geoff-maddock
Copy link

Looking to do this as well - come to any solution to loading fixtures in functional tests?

@fullbl
Copy link

fullbl commented Apr 7, 2021

personally I load them once and use dama/doctrine-test-bundle to make them run into a transition!

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

No branches or pull requests

3 participants