Alice Data Fixtures Errors on Windows

134 Views Asked by At

On my Windows when I pull/clone this project from git and run this command

 bin/console doctrine:fixtures:load

Careful, database will be purged. Do you want to continue y/N ?y

purging database > loading AppBundle\DataFixtures\ORM\RequestFixture\RequestFixture

[Symfony\Component\Debug\Exception\ContextErrorException] Notice: Undefined offset: -5

It gives me an error.

But when I do it in my Mac, everything runs fine.

1

There are 1 best solutions below

0
sullimt On

I am having this same problem on Windows using XAMPP, PHP 7.2.0, and Symfony 4. The error that I had pointed me to vendor\fzaninotto\faker\src\Faker\Provider\Base.php. Inside Base::randomElements there is the following statement:

$num = mt_rand(0, $highKey);

It looks like $num is then used to select a random item from the array of fake data that is passed in to Base::randomElements and then add it to the array of returned $elements.

The call to mt_rand is, in your case, returning -5. The offset -5 is not defined on the array which is expecting a positive number as the offset.

What I was able to figure out is that mt_rand(0, $highKey) is actually returning a number between -$highKey/2 and +$highKey/2. Furthermore, every time the method is invoked it always generates the exact same numbers.

I haven't been able to figure our why mt_rand(0, $highKey) produces a negative number. It could be that the generator is improperly seeded, or it could be a bug in the implementation of mt_rand, but those just wild guesses at this point.