We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fabricate::create()
Thank you for creating great tools for testing.
I got weired behavior in this library.
When I want to create sequentional data in same model, the follwing way.
class CakeFabricateTest extends TestCase { /** * Want to create multiple data from Same Model. */ public function testCreateSameModelDataInACase() { Fabricate::create('Users', function($data, $world) { return [ 'username' => 'taro', ]; }); Fabricate::create('Users', function($data, $world) { return [ 'username' => 'taro2', ]; }); $expected = 2; $actual = TableRegistry::get('Users')->find('all')->count(); $this->assertSame($expected, $actual); } }
I expected two data creating, but actually created only one data.
There was 1 failure: 1) CakeFabricate\Test\CakeFabricateTest::testCreateSameModelDataInACase Failed asserting that 1 is identical to 2.
This is representing code. Please look at this if you want 🙏 https://github.com/otukutun/cakephp-fabricate-adaptor/tree/create-multiple-data-from-same-model
The text was updated successfully, but these errors were encountered:
Hi, otukutun.
Thanks reporting.
The User's id type is number. Fabricator generates sequential value for number field by default inside each creation method scope.
In this case, I recommend usage followings:
number_of_generation
public function testCreateSameModelDataInACase() { $names = ['taro', 'taro2']; Fabricate::create('Users', 2, function($data, $world) use($names) { return [ 'username' => $names[$data->id - 1], ]; }); $expected = 2; $actual = TableRegistry::get('Users')->find('all')->count(); $this->assertSame($expected, $actual); }
public function testCreateSameModelDataInACase() { Fabricate::create('Users', function($data, $world) { return [ 'id' => $world->sequence('id'), 'username' => 'taro', ]; }); Fabricate::create('Users', function($data, $world) { return [ 'id' => $world->sequence('id', 2), 'username' => 'taro2', ]; }); $expected = 2; $actual = TableRegistry::get('Users')->find('all')->count(); $this->assertSame($expected, $actual); }
Sorry, something went wrong.
@sizuhiko Thanks for your response!
I understand Fabricate sequence behavior 🙏
default inside each creation method scope.
Do you have a plan to change sequential value scope? In factory bot, they have sequential values globally. I think it is more useful than local scope.
REF: https://github.com/thoughtbot/factory_bot/blob/master/lib/factory_bot/sequence.rb
No branches or pull requests
Thank you for creating great tools for testing.
I got weired behavior in this library.
When I want to create sequentional data in same model, the follwing way.
I expected two data creating, but actually created only one data.
This is representing code. Please look at this if you want 🙏
https://github.com/otukutun/cakephp-fabricate-adaptor/tree/create-multiple-data-from-same-model
The text was updated successfully, but these errors were encountered: