I have a laravel 5 app that uses MongoDB as its secondary data store and unit tests set up that makes use of FactoryMuffin.
One of the collections/models has an embedded doc structure:
{
details: {title:'first name', other:'other name'}
}
To get started I followed the FactoryMuffin Tutorial.
Factory Definition:
FactoryMuffin::define(
'App\User',
array(
'details'=>array(
'title'=>'first name',
'other'=>'other_name'
)
)
);
Actual Test:
public function testSampleFactory()
{
$user = FactoryMuffin::create('App\User');
$this->assertInstanceOf('App\User', $user);
}
But I came across an error:
There was 1 error:
1) TestUserModel::testSampleFactory
substr() expects parameter 1 to be string, array given
/var/www/wfd2/app/vendor/league/factory-muffin/src/Generators/Base.php:87
/var/www/wfd2/app/vendor/league/factory-muffin/src/Factory.php:660
/var/www/wfd2/app/vendor/league/factory-muffin/src/Factory.php:600
/var/www/path/app/vendor/league/factory-muffin/src/Factory.php:348
/var/www/path/app/vendor/league/factory-muffin/src/Factory.php:259
/var/www/path/app/vendor/league/factory-muffin/src/Facade.php:93
/var/www/path/app/tests/ExampleTest.php:17
/var/www/path/app/tests/ExampleTest.php:17
It seems FactoryMuffin is expecting attribute values to be strings only. Is this the case? How would I add embedded/nested test data with Factory Muffin?
Thank you
Aucun commentaire:
Enregistrer un commentaire