willdurand / bazingafakerbundle Goto Github PK
View Code? Open in Web Editor NEWPut the awesome Faker library into the Symfony2 DIC and populate your database with fake data.
Put the awesome Faker library into the Symfony2 DIC and populate your database with fake data.
When will this library support Symfony 5?
The following file: https://github.com/willdurand/BazingaFakerBundle/blob/master/Resources/config/services.xml
Line 29.
Reads:
<service id="Bazinga\Bundle\FakerBundle\Command\PopulateCommand" class="%faker.populate.class%">
<tag name="console.command" />
</service>
But should read:
<service id="Bazinga\Bundle\FakerBundle\Command\PopulateCommand" class="%faker.populate_command.class%">
<tag name="console.command" />
</service>
This causes composer require willdurand/faker-bundle:dev-master
to fail when installing for Symfony 4.
I'm using your bundle for a few time now. But today, when I wanted to use the command, I had this error :
[InvalidArgumentException]
text() can only generate text of at least 5 characters
Nothing has changed in the config.yml so I don't know from where it could have come from.
Thanks
I would like to generate in the same table two different data sets with different formatter on the same columns
I tried the first idea that came in mind to declare the model twice but the first declaration isn't used.
Is there any way to do such a thing ?
Hi,
Could you please send me an example of how can I use this bundle ?
For example I have an Entity Person, which has properties, workPhone and cellPhone
I have this in my config_dev.yml
http://gist.github.com/1675612
This is my entity http://gist.github.com/1675621
I thought I should configure each method for each field in my Entity, but when I removed custom_formatters it almost worked,
it generated lastName and firstName but not the phone numbers, also envelope number was wrong generated
Could you please help me with this ?
Env = SF2.3 / Propel 1.6.9
schema.xml:
<table name="follow" isCrossRef="true">
<behavior name="timestampable" />
<column name="user_id" type="integer" required="true" primaryKey="true" />
<column name="debate_id" type="integer" required="true" primaryKey="true" />
<foreign-key foreignTable="user" onDelete="CASCADE" onUpdate="CASCADE">
<reference local="user_id" foreign="id" />
</foreign-key>
<foreign-key foreignTable="debate" onDelete="CASCADE" onUpdate="CASCADE">
<reference local="debate_id" foreign="id" />
</foreign-key>
</table>
I've populated the 2 foreign tables without problem and want some random datas for the crossRef table:
Acme\Model\Follow:
number: 150
The faker:populate try to populate this table with _sometimes_ the 2 same lines and for sure it throws the exception:
[PropelException]
Unable to execute INSERT statement [INSERT INTO `follow` (`user_id`, `debate_id`, `created_at`, `updated_at`) VALUES (:p0, :p1, :p2, :p3)] [wrapped: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '73-136' for key 'PRIMARY']
I've got the same problem with an "equal nest" table/relation.
Thanks.
How can I use "custom_modifiers" in config_dev.yml?
Hi,
I just tried to use this bundle in an sf4 project but I get the following error message after following documentation steps.
Am I doing something wrong?
The "faker.populator" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
Here is my config
# fconfig/packages/dev/bazinga_faker.yml
bazinga_faker:
orm: doctrine
entities:
App\Entity\Business:
number: 50
The "Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand" class is deprecated since Symfony 4.2, use "Symfony\Component\Console\Command\Command" with dependency injection instead.
Line where problem occurs: https://github.com/willdurand/BazingaFakerBundle/blob/master/Command/PopulateCommand.php#L20
Not sure how to fix without breaking code for earlier symfony versions. Maybe release in a major version only ?
Auto-registration of the command "Bazinga\Bundle\FakerBundle\Command\PopulateCommand" is deprecated since Symfony 3.4 and won't be supported in 4.0. Use PSR-4 based service discovery instead
3.4+ requires the commands to be explicitly tagged. in services.xml
Hello,
I used to work with Doctrine Fixtures, and by default it deletes datas before insert the new datas. Is this possible with this bundle?
Thank you
how to change locale?
Passing arguments to service definitions makes nothing.
I want to insert big data in two tables user -> notifications (about 50k user and 5M notifications). So it is taking very long to be executed. Is it possible to split data insertion ?
Maybe I have to write this in Faker instead of there.
How do I populate the middle table?
i am looking for the best practice on how to add custom formatters to faker in a symfony project with the faker bundle.
also see fzaninotto/Faker#49
for example if i want to add a Provider named FutureDates
<?php
namespace Faker\Provider;
class FutureDates extends \Faker\Provider\Base
{
/**
* @example DateTime('2011-09-19 09:24:37')
* @return \DateTime
*/
public static function dateTimeNextYear()
{
return static::dateTimeBetween("now", "+1 year");
}
/**
* @example DateTime('2011-10-05 12:51:46')
* @return \DateTime
*/
public static function dateTimeNextMonth()
{
return static::dateTimeBetween("now", "+1 month");
}
}
Just creating the issue to link it to PR later:
The "Symfony\Component\Config\Definition\Builder\TreeBuilder::root()" method called for the "faker" configuration is deprecated since Symfony 4.3, pass the root name to the constructor instead.
Example fix:
I has two entities, for example: Country and City. City has relationship with Country (by country_id):
entities:
Entity\Country:
number: 100
custom_formatters:
code: { method: countryCode }
title: { method: country }
Entity\City:
number: 20
custom_formatters:
country: { method: randomNumber, parameters: [1,2,3,4,5] }
With country or any standalone entity i don't have any problem, all is ok. But how now i can set country_id in City if in City (entity) i have:
/**
* Set country
*
* @param \Entity\Country $country
* @return City
*/
public function setCountry(\Entity\Country $country = null)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return \Entity\Country
*/
public function getCountry()
{
return $this->country;
}
I try randomNumber or randomElement, but they not work for me like i expected, country_id is NULL after populate City table.
calling the official dateTimeBetween
method like this:
MyCompany\MyBundle\Model\Event:
number: 50
custom_formatters:
Title: { method: null }
StartDate: { method: dateTimeBetween, parameters: [ '-1 days', '+1 month' ] }
results in an error:
[ErrorException]
Warning: strtotime() expects parameter 1 to be string, array given in .\vendor\fzaninotto\faker\src\Faker\Provider\DateTime.php line 82
I think that this bundle is great, but I currently use it only in dev or in test environment. I think that this usage is pretty common (I mean, I cannot find any good use case for production).
So, my proposal for a docs improvement is to enforce using this bundle in dev/test env only, just like, for example, SensioGeneratorBundle.
Needed changes are for bundle registering and for config_dev.yml use.
If agreed, I can do a PR.
Is there any way to use https://github.com/fzaninotto/Faker#modifiers with the YAML config? If not I think we should add it.
bazinga_faker:
locale: ru_RU
it doesn't work, it still filled database British symbols...
Is it possible to use this bundle with multiple entity managers / connections ?
[RuntimeException]
The "--em" option does not exist.
Hi,
I have an error running command line and unit tests :
PHP Fatal error: Call to a member function parse() on a non-object in /media/OS/mach/vendor/faker/src/Faker/Provider/Address.php on line 91
Have you got any idea ?
Cédric
Hello,
I've just installed this bundle but it seems that I don't have the last code of the FakeBundle. For example, I've edited the "Image" class code, and don't have the "fullPath" argument described in the FakeBundle documentation.
public static function image($dir, $width = 640, $height = 480, $category = null)
FakeBundle documentation:
/**
* Image generation provided by LoremPixel (http://lorempixel.com/)
*
* @param $dir An absolute path to a local directory
* @param $width/$height Size (in pixel) of the generated image (defaults to 640x480)
* @param $category One of 'abstract','animals','business','cats','city','food','nightlife','fashion','people','nature','sports','technics', and 'transport'
* @param $fullPath Whether to have the full path to the image or just the filename (default true)
*/
Is there something to change in the composer file?
Thanks.
Hi,
I need to make faker result in my jointure table product_category but it's not an entity, it's just a relation :
manyToMany:
categories:
targetEntity: Category
inversedBy: products
joinTable:
name: product_category
joinColumns:
product_id:
referencedColumnName: id
inverseJoinColumns:
category_id:
referencedColumnName: id
unique: true
how can i do with yaml to fill my jointure table ?
thx a lot !
Whenever I tried to implement optional, I always got the fake value. I assume I'm trying to use it right:
foobar: {method: realText, optional: true}
The Faker docs state:
// optional() accepts a weight argument to specify the probability of receiving the default value.
// 0 will always return the default value; 1 will always return the provider. Default weight is 0.5.
and in Factory/FormatterFactory.php, you are incorrectly implementing it as:
$generator = $generator->optional((double) $optional);
producing a value of 1.0 being passed to optional(), which always gives the fake value
So, removing the (double) $optional
param makes Faker default to a weight of 0.5.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.