factory-muffin icon indicating copy to clipboard operation
factory-muffin copied to clipboard

Cannot define model

Open StefanGramadnikov opened this issue 9 years ago • 7 comments

Hi,

I'm using codeception and symfony 2.8 with doctrine 2. I'm writing unit tests with codeception and I want to pre load some data with Factory Muffin, but I'm getting stuck. Here is my setup:

  • Enabled Modules
modules:
    enabled:
        - Asserts
        - Symfony
        - Db
        - Doctrine2:
            depends: Symfony
        - \Helper\Unit
        - DataFactory:
            factories: tests/_support/factories
            depends: Doctrine2

note: I have installed factory muffin and the faker through composer

  • I have the factories folder in tests/_support/factories
  • My factories are in the folder above
  • My factory looks like this
<?php
use League\FactoryMuffin\Faker\Facade as Faker;

$fm->define('AppBundle\Entity\User', [
    'name' => Faker::name(),
    'email' => Faker::email(),
    'isActive' => Faker::boolean(100),
    'isDeleted' => Faker::boolean(0),
    'type' => 'user',
    'apiKey' => 'test'
]);

My problem is that when I run the tests I get ->


[League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException]     
The model definition 'AppBundle\Entity\User' has already been defined

I was trying to debug it and saw that the method define in FactoryMuffin.php is being called two times and I couldn't figure out why. The second time is where it throws the exception.

If I try $fm->make instead of define I get

[League\FactoryMuffin\Exceptions\DefinitionNotFoundException]  
 The model definition 'AppBundle\Entity\User' is undefined. 

Can you please tell me if I'm doing something wrong or check if there is some mistake in the code. If you need more info about my configuration I'll be in touch.

Thank you

StefanGramadnikov avatar Jul 20 '16 14:07 StefanGramadnikov

Is codeception requiring the file?

GrahamCampbell avatar Jul 20 '16 15:07 GrahamCampbell

Which file exactly. It is requiring the factory and it is throwing the exception when I call $fm->define().

StefanGramadnikov avatar Jul 21 '16 05:07 StefanGramadnikov

Hi @StefanGramadnikov ! Did you get any further help on this? I am facing a similar issue.

Jan-Siva avatar Sep 05 '17 14:09 Jan-Siva

the same issue with me, I am implementing this repo for Codeigniter 3.x. when I define a Model, after run a testcase It throw "The model definition 'User' is undefined" if I use namespace for Model, it's okay, but I dont want to use namespace for it, I throw above error. Any guys have solutions to solve this ?? @StefanGramadnikov @GrahamCampbell

tuanmy avatar Oct 30 '17 04:10 tuanmy

same issue

ctrlaltdylan avatar Oct 30 '17 20:10 ctrlaltdylan

Did any of you the solution? I have the same issue trying to integrate Codeception in ZendExpressive.

pawelryznar avatar Aug 12 '19 13:08 pawelryznar

I'm using ZF2 framework and have similar issue

natsu90 avatar May 16 '22 05:05 natsu90