After reading this thread... is there any reason that TestDummy simply won't work in Lumen now?
Lumen + sqlite + TestDummy relationships
When using Lumen, sqlite, and laracasts/TestDummy, I'm finding that relationships in the Fakers aren't being built out.
For instance, in my factories.php I have the following:
<?php
$factory('App\Approval', [
'id' => $faker->randomDigitNotNull,
'person_id' => 'faker:App\Person',
'service_id' => 'faker:App\Service',
'processed_at' => $faker->dateTime,
]);
$factory('App\Attrib', [
'id' => $faker->randomDigitNotNull,
'person_id' => 'faker:App\Person',
'service_id' => 'faker:App\Service',
'k' => $faker->word,
'v' => $faker->sentence(6),
]);
$factory('App\Person', [
'id' => $faker->randomDigitNotNull,
]);
$factory('App\Service', [
'id' => $faker->randomDigitNotNull,
'service_name' => $faker->word,
'group' => $faker->randomDigitNotNull,
]);
Then in my PersonControllerTest.php I have:
public function testGetPeople()
{
// Arrange
Factory::times(3)->create('App\Attrib');
// Act
$response = $this->call('GET', '/people');
dd($response->getContent());
// Assert
$this->assertInstanceOf('App\Person', $people[0]);
$this->assertResponseOk();
}
When I run the test, I get the following in the sqlite table:
sqlite> select * from attributes;
2|faker:App\Person|faker:App\Service|quasi|Quia iste optio molestiae quis quia quia exercitationem.||2015-06-17 04:06:12|2015-06-17 04:06:12
5|faker:App\Person|faker:App\Service|aut|Voluptatem eveniet ut quis sit sequi sed consequuntur reiciendis.||2015-06-17 04:06:12|2015-06-17 04:06:12
9|faker:App\Person|faker:App\Service|minima|Et iste eveniet provident exercitationem explicabo magni magni.||2015-06-17 04:06:12|2015-06-17 04:06:12
sqlite> select * from people;
sqlite>
So, instead of creating the associated Person record, it simply throws in the faker:App\Person string.
Anyone figure out how to get this to work properly and create the associated record, and then insert the appropriate id?
Ok, it's either the beer in me (or lack of beer earlier) which made me use faker:... instead of factory:... in my factories.php file.
I've since changed my factories.php to this, to also not conflict with my seeds:
<?php
$factory('App\Approval', [
'id' => $faker->numberBetween(10000, 90000),
'person_id' => 'factory:App\Person',
'service_id' => 'factory:App\Service',
'processed_at' => $faker->dateTime,
]);
$factory('App\Attrib', [
'id' => $faker->numberBetween(10000, 90000),
'person_id' => 'factory:App\Person',
'service_id' => 'factory:App\Service',
'k' => $faker->word,
'v' => $faker->sentence(6),
]);
$factory('App\Person', [
'id' => $faker->numberBetween(10000, 90000),
]);
$factory('App\Service', [
'id' => $faker->numberBetween(10000, 90000),
'service_name' => $faker->word,
'group' => $faker->randomDigitNotNull,
]);
Please or to participate in this conversation.