Hey Dang!
Yes, mo Foundry is much better than Alice. Foundry didn't exist when I wrote the earlier tutorials that used Alice. I now *much* prefer Foundry of Alice :). So use it instead!
Cheers!
Oh, yes! We will cover that - just not using Foundry specifically inside of tests :).
Hey @Farry7!
Right here: https://symfonycasts.com/screencast/symfony-doctrine/foundry
Cheers!
Hi!
I'm trying to work my way around Foundry but I'm facing two issues.
First one: I'd like to create dummy users and I've got a `password` property. So I tried to emulate the Symfony Doc tip to encode password into…
…C.!
> So if I see this right zenstruck/foundry acts as a replacement for the hautelook/AliceBundle
💯 I have not been very happy with Alice for awhile now, and have been looking for replacements. Foundry even has (via a simple trait, similar to…
Hey |mention:66023|
This may sound silly, but did you load the fixtures? `symfony console foundry:load-fixtures`
If you did, could you do it again and see if there were any errors or warnings?
Another thing to check is whether you're using Docker…
Hey |mention:71831|
That's a bit odd. The `_real()` method gives you the entity object instead of a wrapper coming from Foundry. Are you calling `persist()` on each droid object?
You can click on expand to view the entire fixtures file in this code…
Hey |mention:66023|
I just gave this a try (with the new code) and it works fine. Could you copy-paste the AppFixtures code from this code block and try again?
https://symfonycasts.com/screencast/doctrine-relations/many-to-many-foundry#codeblock-3d67ea2ef7
Cheers!
I've updated my fork of the course (https://github.com/survos-sites/easyadmin-cast) with _everything_, foundry:^2, php8.4, Symfony 7.2, doctrine/persistence:^4, I mean everything. And every recipe. AssetMapper instead of Webpack. Attributes instead of annotations.
```
composer outdated
Direct dependencies…
…package name now :) Actually, we do recommend `zenstruck/foundry` instead, than in turn has that faker as a dependency, so with Foundry you get double-win with creating your fixtures ;) We also have many videos about Foundry on SymfonyCasts, you can check them here: https…
…and it is a great experience!
However, I noticed a memory issue whlie using Foundry factories and `doctrine:fixtures:load`.
I'm trying to use these to setup testing data for my application. While preparing basic config like some users, organization and permissions everything was…
…thread is about.
Namely: why in the tutorial Ryan was able to use `browser->actingAs($user)` with `$user` created with Foundry factory and when I try to do this I get the 500 error mentioned by |mention:81069| at the beginning of this thread? And…
…that's actually on purpose, entity factories from the Foundry lib need that to add more magic in tests - those proxy objects helps you to do not worry about the problem with refreshing the entity in tests. But that AppEntityUserProxy actually extends your User class…
|
|
// ... lines 1 - 2
|
|
namespace App\Tests\Functional; |
|
|
|
use App\Factory\PlanetFactory; |
|
use App\Factory\VoyageFactory; |
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
use Zenstruck\Browser\Test\HasBrowser; |
|
use Zenstruck\Foundry\Test\Factories; |
|
use Zenstruck\Foundry\Test\ResetDatabase; |
|
|
|
class VoyageControllerTest extends WebTestCase |
|
{ |
|
use ResetDatabase; |
|
use Factories; |
|
use HasBrowser; |
|
|
|
public function testCreateVoyage() |
|
{ |
|
PlanetFactory::createOne([ |
|
'name' => 'Earth', |
|
]); |
|
VoyageFactory::createOne(); |
|
|
|
$this->browser() |
|
->visit('/') |
|
->click('Voyages') |
|
->click('New Voyage') |
|
->fillField('Purpose', 'Test voyage') |
|
->selectFieldOption('Planet', 'Earth') |
|
->click('Save') |
|
->assertElementCount('table tbody tr', 2) |
|
->assertSee('Bon voyage') |
|
; |
|
} |
|
} |
See Code Block in Script
…I have no idea tbh. I've never used MSSQL, and I don't think the creator of Foundry has either, so it's quite possible that it's not coded correctly for that. You could try using https://github.com/dmaicher/doctrine-test-bundle…
Hey Cameron,
This is actually from doctrine/orm package. This might be an indirect deprecation for other packages that uses doctrine/orm in their dependecies including Foundry like you said. You can just ignore it for now and it should be fixed by package maintainers…
Awesome! And thanks for sharing that this worked. I couldn't think of any reason why simply "renaming the namespace" would cause any issues, but I had never tried it before with Foundry!
…I changed RoleFixture by using the factory of Foundry...
Yes, I agree: I think the mixture of the DependentFixtures system and Foundry won't play nicely together. So if you're heavily dependent on `DependentFixtures`, stay with that. But eventually, using Foundry would be nice :)…
|
|
// ... lines 1 - 2
|
|
namespace App\Factory; |
|
|
|
use App\Entity\User; |
|
use App\Repository\UserRepository; |
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; |
|
use Zenstruck\Foundry\ModelFactory; |
|
use Zenstruck\Foundry\Proxy; |
|
use Zenstruck\Foundry\RepositoryProxy; |
|
|
|
|
|
|
|
|
// ... lines 14 - 29
|
|
|
|
final class UserFactory extends ModelFactory |
|
{ |
|
const USERNAMES = [ |
|
'FlamingInferno', |
|
'ScaleSorcerer', |
|
'TheDragonWithBadBreath', |
|
'BurnedOut', |
|
'ForgotMyOwnName', |
|
'ClumsyClaws', |
|
'HoarderOfUselessTrinkets', |
|
]; |
|
|
// ... lines 42 - 47
|
|
public function __construct( |
|
private UserPasswordHasherInterface $passwordHasher |
|
) |
|
{ |
|
parent::__construct(); |
|
} |
|
|
// ... lines 54 - 59
|
|
protected function getDefaults(): array |
|
{ |
|
return [ |
|
'email' => self::faker()->email(), |
|
'password' => 'password', |
|
'username' => self::faker()->randomElement(self::USERNAMES) . self::faker()->randomNumber(3), |
|
]; |
|
} |
|
|
// ... lines 68 - 71
|
|
protected function initialize(): self |
|
{ |
|
return $this |
|
->afterInstantiate(function(User $user): void { |
|
$user->setPassword($this->passwordHasher->hashPassword( |
|
$user, |
|
$user->getPassword() |
|
)); |
|
}) |
|
; |
|
} |
|
|
|
protected static function getClass(): string |
|
{ |
|
return User::class; |
|
} |
|
} |
See Code Block in Script
|
|
// ... lines 1 - 2
|
|
namespace App\Factory; |
|
|
|
use App\Entity\DragonTreasure; |
|
use App\Repository\DragonTreasureRepository; |
|
use Zenstruck\Foundry\ModelFactory; |
|
use Zenstruck\Foundry\Proxy; |
|
use Zenstruck\Foundry\RepositoryProxy; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final class DragonTreasureFactory extends ModelFactory |
|
{ |
|
|
// ... lines 32 - 36
|
|
public function __construct() |
|
{ |
|
parent::__construct(); |
|
} |
|
|
// ... lines 41 - 46
|
|
protected function getDefaults(): array |
|
{ |
|
return [ |
|
'coolFactor' => self::faker()->randomNumber(), |
|
'description' => self::faker()->text(), |
|
'isPublished' => self::faker()->boolean(), |
|
'name' => self::faker()->text(255), |
|
'plunderedAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()), |
|
'value' => self::faker()->randomNumber(), |
|
]; |
|
} |
|
|
// ... lines 58 - 61
|
|
protected function initialize(): self |
|
{ |
|
return $this |
|
|
|
; |
|
} |
|
|
|
protected static function getClass(): string |
|
{ |
|
return DragonTreasure::class; |
|
} |
|
} |
See Code Block in Script
x
185