thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
531 stars 72 forks source link

Cannot define model #427

Open StefanGramadnikov opened 8 years ago

StefanGramadnikov commented 8 years ago

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:

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

<?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

GrahamCampbell commented 8 years ago

Is codeception requiring the file?

StefanGramadnikov commented 8 years ago

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

Jan-Siva commented 6 years ago

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

tuanmy commented 6 years ago

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

ctrlaltdylan commented 6 years ago

same issue

pawelryznar commented 5 years ago

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

natsu90 commented 2 years ago

I'm using ZF2 framework and have similar issue