doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.76k stars 224 forks source link

ORMExecutor->execute expects diffrented class than Loader->getFixures() returns #414

Closed johanadivare closed 1 year ago

johanadivare commented 1 year ago

I get the following error from latest versions:

  Line   tests/Functional/FunctionalTestCase.php                                                                                                                      
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  91     Parameter #1 $fixtures of method Doctrine\Common\DataFixtures\Executor\ORMExecutor::execute() expects array<Doctrine\Common\DataFixtures\FixtureInterface>,  
         array<class-string<Doctrine\Common\DataFixtures\OrderedFixtureInterface>|int, Doctrine\Common\DataFixtures\OrderedFixtureInterface> given.    

I think it could be resolved if OrderedFixtureInterface extends from FixtureInterface

greg0ire commented 1 year ago

OrderedFixtureInterface doesn't extend FixtureInterface, which probably means something like OrderedFixtureInterface&FixtureInterface should be used somewhere.

greg0ire commented 1 year ago

Hard to tell where without the source code of tests/Functional/FunctionalTestCase.php, of course.

johanadivare commented 1 year ago

@greg0ire this is what the class looks like:

xxx

    protected function refreshFixtures(): void
    {
        $loader = new Doctrine\Common\DataFixtures\Loader();
        $fixture = new CustomFixture();
        $fixture->setContainer($this->getKernelBrowser()->getContainer());
        $loader->addFixture($fixture);
        $purger = new Doctrine\Common\DataFixtures\Purger\ORMPurger();
        $executor = new Doctrine\Common\DataFixtures\Executor\ORMExecutor($this->getEntityManager(), $purger);
        $executor->execute($loader->getFixtures());
    }
greg0ire commented 1 year ago

Ok, so the issue is with https://github.com/doctrine/data-fixtures/blob/1a4232c15143ca3c127812d19b23a7961c41eeed/lib/Doctrine/Common/DataFixtures/Loader.php#L184

Do you feel up to making it more precise?

Kind of makes me wonder why OrderedFixtureInterface doesn't extend FixtureInterface in the first place though :thinking:

johanadivare commented 1 year ago

Ok, so the issue is with

https://github.com/doctrine/data-fixtures/blob/1a4232c15143ca3c127812d19b23a7961c41eeed/lib/Doctrine/Common/DataFixtures/Loader.php#L184

Do you feel up to making it more precise?

Kind of makes me wonder why OrderedFixtureInterface doesn't extend FixtureInterface in the first place though thinking

Yes i think its in the Loader.php, i haven't debugged the issue much i could try to change the return types but i also wonder why that OrderedFixtureInterface doesn't extend from FixtureInterface haha i dont know who introduced it maybe they know best.

I saw docs updates where done in https://github.com/doctrine/data-fixtures/pull/389 but they made it consistent with the property $fixtures docs

greg0ire commented 1 year ago

i dont know who introduced it maybe they know best

If only there was a way for us to know that, like some kind of code history tool :thinking:

Trolling aside it was introduced more than 10 years ago in #5 , so… long shot, but @l3pp4rd , super long shot, but maybe you have some input you can provide on this?

johanadivare commented 1 year ago

Haha fair, i didn't look that fair back ;p