178 search results

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…
MolloKhan
MolloKhan
Read Full Comment
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!
MolloKhan
MolloKhan
Read Full Comment
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…
Tac-Tacelosky
Tac-Tacelosky
Read Full Comment
…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…
37 lines | tests/Functional/VoyageControllerTest.php
// ... 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…
weaverryan
weaverryan
Read Full Comment
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!
weaverryan
weaverryan
Read Full Comment
…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 :)…
weaverryan
weaverryan
Read Full Comment
89 lines | src/Factory/UserFactory.php
// ... 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;
/**
* @extends ModelFactory<User>
// ... 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
74 lines | src/Factory/DragonTreasureFactory.php
// ... 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;
/**
* @extends ModelFactory<DragonTreasure>
*
* @method DragonTreasure|Proxy create(array|callable $attributes = [])
* @method static DragonTreasure|Proxy createOne(array $attributes = [])
* @method static DragonTreasure|Proxy find(object|array|mixed $criteria)
* @method static DragonTreasure|Proxy findOrCreate(array $attributes)
* @method static DragonTreasure|Proxy first(string $sortedField = 'id')
* @method static DragonTreasure|Proxy last(string $sortedField = 'id')
* @method static DragonTreasure|Proxy random(array $attributes = [])
* @method static DragonTreasure|Proxy randomOrCreate(array $attributes = [])
* @method static DragonTreasureRepository|RepositoryProxy repository()
* @method static DragonTreasure[]|Proxy[] all()
* @method static DragonTreasure[]|Proxy[] createMany(int $number, array|callable $attributes = [])
* @method static DragonTreasure[]|Proxy[] createSequence(array|callable $sequence)
* @method static DragonTreasure[]|Proxy[] findBy(array $attributes)
* @method static DragonTreasure[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])
* @method static DragonTreasure[]|Proxy[] randomSet(int $number, array $attributes = [])
*/
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
// ->afterInstantiate(function(DragonTreasure $dragonTreasure): void {})
;
}
protected static function getClass(): string
{
return DragonTreasure::class;
}
}
See Code Block in Script
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!