185 search results

… Actually, I would say that *your* way probably has more benefits in general, because you're using more of Foundry's features - I just hadn't thought of it! Using afterInstantiate() gives you more power (e.g. you could call any method on your entity…
weaverryan
weaverryan
Read Full Comment
Hey Sean, I just double-checked it: download the course code, goes to the start/ directory, require orm and zenstruck/foundry packs and it worked for me. So, not sure why exactly you hit that error, probably a new version was released that conflicted with…
Hello again. I swear Ill make it through one of these without running into an issue. Tonight suddenly started getting an error running "composer require zenstruck/foundry --dev", which is weird because I installed it a few days ago.....I dunno. If anyone else is…
54 lines | src/Factory/QuestionFactory.php
// ... lines 1 - 6
use Symfony\Component\String\Slugger\AsciiSlugger;
// ... lines 8 - 20
final class QuestionFactory extends ModelFactory
{
// ... lines 23 - 35
protected function initialize(): self
{
// see https://github.com/zenstruck/foundry#initialization
return $this
->afterInstantiate(function(Question $question) {
if (!$question->getSlug()) {
$slugger = new AsciiSlugger();
// ... line 43
}
})
;
}
// ... lines 48 - 52
}
See Code Block in Script
54 lines | src/Factory/QuestionFactory.php
// ... lines 1 - 6
use Symfony\Component\String\Slugger\AsciiSlugger;
// ... lines 8 - 20
final class QuestionFactory extends ModelFactory
{
// ... lines 23 - 35
protected function initialize(): self
{
// see https://github.com/zenstruck/foundry#initialization
return $this
->afterInstantiate(function(Question $question) {
if (!$question->getSlug()) {
$slugger = new AsciiSlugger();
$question->setSlug($slugger->slug($question->getName()));
}
})
;
}
// ... lines 48 - 52
}
See Code Block in Script
42 lines | src/Factory/QuestionFactory.php
// ... lines 1 - 2
namespace App\Factory;
use App\Entity\Question;
use App\Repository\QuestionRepository;
use Zenstruck\Foundry\RepositoryProxy;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
/**
* @method static Question|Proxy findOrCreate(array $attributes)
* @method static Question|Proxy random()
* @method static Question[]|Proxy[] randomSet(int $number)
* @method static Question[]|Proxy[] randomRange(int $min, int $max)
* @method static QuestionRepository|RepositoryProxy repository()
* @method Question|Proxy create($attributes = [])
* @method Question[]|Proxy[] createMany(int $number, $attributes = [])
*/
final class QuestionFactory extends ModelFactory
{
protected function getDefaults(): array
{
return [
// TODO add your default values here (https://github.com/zenstruck/foundry#model-factories)
];
}
protected function initialize(): self
{
// see https://github.com/zenstruck/foundry#initialization
return $this
// ->beforeInstantiate(function(Question $question) {})
;
}
protected static function getClass(): string
{
return Question::class;
}
}
See Code Block in Script
…for my database, and when using the ResetDatabase trait I am unable to run my tests. They fail as foundy cannot drop the database because it is in use. The connection that is in use is the Test script that is running. Did i miss…
…cryptic Darn, we've been trying to [make this error](https://github.com/zenstruck/foundry/blob/0a65872885d63c826ff6f0ef022b0fa8ff7187af/src/Exception/FactoriesTraitNotUsed.php#L30) more helpful but it's a bit hacky and we can't seem to catch every scenario. Regardless, I'm glad you solved…
…at the top of my test case. Since the previous examples (running with `--filter=....`) ran fine, I didn't think it was necessary. So if you're using a newer version of Symfony/Doctrine/Foundry, you should add `use Factories;` to your test case or…
…able to create Foundry factories in your project. However, if you already have the foundry installed in your project - than `make:factory` will just work for you, so no need to run that `composer require --dev factory`. Moreover, if you have Foundry lib already installed…
Blog
SymfonyCasts November Open Source Roundup!

…object to another! SymfonyCasts/dynamic-forms: v0.1.3 Add dynamic/dependent fields to Symfony forms zenstruck/phpmyadmin-server: v1.9.0 Run phpMyAdmin in the background with a PHP webserver zenstruck/foundry: v2.2.2 A model factory library for creating expressive, auto-completable…

…as it comes to this module where we have the first access to DB, DB access fails complete. It is that the whole zenstruck part is depecreated and not working anymore with zenstruck/foundry >= ^2. I do not see any database item at all.
Blog
Kevin Bond (aka Zenstruck) joins SymfonyCasts

…to use his libraries and has repeatedly taken a hard or ugly task in Symfony and made it easy and beautiful. Just look at Foundry (for data fixtures - including inside tests), zenstruck/browser (for functional tests) or a number of other libraries for testing emails…

…in your app, have other classes that have nothing to do with Foundry but which follow the factory pattern. Unless it's confusing for you, there is nothing wrong with having non-Foundry classes that also live in `src/Factory/`. If you don't like…
weaverryan
weaverryan
Read Full Comment
…of Foundry, I had add trait of ResetDatabase and Factories to the fixture-tests, because a single RoleFactory call had some problems with $entitymanager->flush(). After adding the traits my test-code was running very slowly and interrupted. So I stopped my experiment with Foundry
…objects I'm looking for. Or use foundry to find random items - e.g. ``` ProductFactory::createOne([ 'category' => CategoryFactory::random() ]); ``` But, to answer your question.... yes and no! :p. The answer is no. But, that's actually by design. With Foundry, you are still using…
weaverryan
weaverryan
Read Full Comment
… use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Zenstruck\Foundry\ModelFactory; use Zenstruck\Foundry\Proxy; use Zenstruck\Foundry\RepositoryProxy; /** * @extends ModelFactory * * @method User|Proxy create(array|callable $attributes = []) * @method static User|Proxy createOne(array $attributes = []) * @method static User|Proxy find(object|array|mixed $criteria) * @method static User|Proxy findOrCreate(array $attributes…
…User::class; } } ``` They key thing is your `User` class needs to have a getter and setter for `User::address` and `Address` of course needs getters/setters for it's respective properties. Then you just use foundry as you would with any other entity. E.g…
Jesse-Rushlow
Jesse-Rushlow
Read Full Comment
…generate data with it? Are those data really localized? If so, it sounds like a misconfiguration or a bug in the Foundry bundle, I'd recommend you to open an issue there. Btw, keep in mind that not all the data might be translated. Please…
…it required to download somewhere the language packs? ``` Current configuration for extension with alias "zenstruck_foundry" ================================================================== zenstruck_foundry: auto_refresh_proxies: true faker: locale: fr_FR seed: null service: null instantiator: without_constructor: false allow_extra_attributes: false always_force_properties: false service: null ```