185 search results

Hello, Can we make fixtures for [Embeddables] class ? For example "User Entity" use "Adress embeddable class" who store the field City, Town, Street How we can use Foundry to generate many User ? Thank you.
…generate some text but text are in Latin I added configuration in file config/package/zenstruck_foundry.yaml ``` when@dev: &dev # See full configuration: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#full-default-bundle-configuration zenstruck_foundry: # Whether to auto-refresh proxies by default…
Hey gazzatav! Great catch on that error message - both the mistake and the suggestion! I've created a pull request for it - https://github.com/zenstruck/foundry/pull/289 Cheers!
weaverryan
weaverryan
Read Full Comment
Hey Gary, First of all, I'm not sure what you're doing, I don't see the course code has any "Zenstruck\Foundry\Proxy" use statements in the code related to this video, or am I missing it? Could you point to the exact…
hi victor , looks like you missed my reply to my own question below and yes I had 'Zenstruck\Foundry\Proxy' in the use statements. Would still like to know what 'chain configured namespaces' are.
Hey Gary, It sounds like you missed to use the namespace, i.e. make sure you have that "Zenstruck\Foundry\Proxy" namespace in the use statements in whatever class where you use that "Proxy". Please, double check it first. Cheers!
…read this and didn't get a new `make:factory` command. I think the new recipes (v1.10+) are not compatible with Symfony 5.1.x. Make sure you register the bundle manually. `# config/bundles.php return [ // ... Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true…
julien_bonnier
julien_bonnier
Read Full Comment
Hello. In some previous tutorials, you presented us other library for the fixture called Alice Bundle. I wonder beacause this tuto is newer (Symfony 5) so this bundle zenstruck/foundry is better and I should use this instead for new project? Thanks
…symfony 5.0 and php 7.3. I've worked through some issues with Foundry (had to update to php74 to get a version that actually has the make:factory command) and at the point where AsciiSlugger() was used, I had to `composer require symfony…
61 lines | src/Factory/UserFactory.php
// ... lines 1 - 2
namespace App\Factory;
use App\Entity\User;
use App\Repository\UserRepository;
use Zenstruck\Foundry\RepositoryProxy;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
// ... lines 10 - 28
final class UserFactory extends ModelFactory
{
public function __construct()
{
parent::__construct();
// TODO inject services if required (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services)
}
protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'email' => self::faker()->text(),
'roles' => [],
'firstName' => self::faker()->text(),
];
}
protected function initialize(): self
{
// see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
return $this
// ->afterInstantiate(function(User $user) {})
;
}
protected static function getClass(): string
{
return User::class;
}
}
See Code Block in Script
59 lines | src/Factory/QuestionTagFactory.php
// ... lines 1 - 2
namespace App\Factory;
use App\Entity\QuestionTag;
use App\Repository\QuestionTagRepository;
use Zenstruck\Foundry\RepositoryProxy;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
// ... lines 11 - 28
final class QuestionTagFactory extends ModelFactory
{
public function __construct()
{
parent::__construct();
// TODO inject services if required (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services)
}
protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'taggedAt' => self::faker()->datetime(),
];
}
protected function initialize(): self
{
// see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
return $this
// ->afterInstantiate(function(QuestionTag $questionTag) {})
;
}
protected static function getClass(): string
{
return QuestionTag::class;
}
}
See Code Block in Script
61 lines | src/Factory/TagFactory.php
// ... lines 1 - 2
namespace App\Factory;
use App\Entity\Tag;
use App\Repository\TagRepository;
use Zenstruck\Foundry\RepositoryProxy;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
// ... lines 11 - 28
final class TagFactory extends ModelFactory
{
public function __construct()
{
parent::__construct();
// TODO inject services if required (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services)
}
protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'name' => self::faker()->text(),
'createdAt' => null, // TODO add DATETIME ORM type manually
'updatedAt' => null, // TODO add DATETIME ORM type manually
];
}
protected function initialize(): self
{
// see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
return $this
// ->afterInstantiate(function(Tag $tag) {})
;
}
protected static function getClass(): string
{
return Tag::class;
}
}
See Code Block in Script
…and Foundry make it easy, and here is how you use Foundry with Doctrine relations". This chapter really just focuses on covering one edge-case when people use Foundry with relations (that's this part here: https://symfonycasts.com/screencast/doctrine-relations/foundry-factory-relation…
weaverryan
weaverryan
Read Full Comment
62 lines | src/Factory/AnswerFactory.php
// ... lines 1 - 2
namespace App\Factory;
use App\Entity\Answer;
use App\Repository\AnswerRepository;
use Zenstruck\Foundry\RepositoryProxy;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
/**
* @extends ModelFactory<Answer>
*
// ... lines 14 - 27
*/
final class AnswerFactory extends ModelFactory
{
public function __construct()
{
parent::__construct();
// TODO inject services if required (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services)
}
protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'content' => self::faker()->text(),
'username' => self::faker()->text(),
'createdAt' => null, // TODO add DATETIME ORM type manually
'updatedAt' => null, // TODO add DATETIME ORM type manually
];
}
protected function initialize(): self
{
// see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
return $this
// ->afterInstantiate(function(Answer $answer) {})
;
}
protected static function getClass(): string
{
return Answer::class;
}
}
See Code Block in Script
Is there a mistake in the course description then? One of the topics is "Handling relationships in fixtures with Foundry"
…forward to it! These doctrine courses are the reason I got a subscription Sweet! > my implementation of foundry for testing is incredibly hacky We won't be talking about Foundry and testing in this tutorial. But if you have any specific questions, I'd…
weaverryan
weaverryan
Read Full Comment
Looking forward to it! These doctrine courses are the reason I got a subscription. I'm currently working on a massive warehouse management database and my implementation of foundry for testing is incredibly hacky
Thanks for all your help so far. Do you maybe know on which course / chapter I can learn about Foundry? I can not remember if it was already in one of the Symfony 5 courses. Foundry sounds fimiliar though.
… Excellent questions! > First one: I'd like to create dummy users and I've got a password property I had a long conversation about this with Foundry's creator Kevin. The problem (and it's kind of by design) is that the factories are…
weaverryan
weaverryan
Read Full Comment
Thanks Ryan! I guess we can say that it is better to use one or the other based on your own implementation or use case, which speaks really well about Foundry.
Ismael A.
Ismael A.
Read Full Comment