201 search results

Saving Items in a ManyToMany Relation

…they are not related to any questions in the database because we never set the owning side of the relationship. So... let's put that code back. Next: let's use Foundry to create a bunch of Tag objects and randomly relate them to questions.

6:36
Publishing a Listing

…for the JSON body, send isPublished set to true: And... the status code we expect is 200: So here's the flow: we create a User - via the Foundry library - and then create a CheeseListing. Oh, but we don't want that published() method: that…

6:02
Customizing the User Class

…users to our database using the fixtures system. Open up src/DataFixtures/AppFixtures.php. We're using Foundry to help us load data. So let's create a new Foundry factory for User. Since we're having SO much fun running commands in this video…

3:08
Creating the User Class

…explore a registration form later, but for now, let's use a Foundry factory for local development. Create the factory with: symfony console make:factory Select our User entity. Open src/Factory/UserFactory.php. I think we can improve these defaults a bit! For email…

7:27
Understanding Password Hashing

…from the terminal and open src/Story/AppStory.php. Replace the plain text password for makeitso with the copied hash: Back in the terminal, reload our fixtures with: symfony console foundry:load-fixtures Go back to our login page... refresh... enter makeitso as the password..…

9:51
User Roles

…we're creating his user. Add 'roles' => , and in an array, ROLE_CAPTAIN: At your terminal, reload the fixtures with: symfony console foundry:load-fixtures Reload the page... we're logged out because we reloaded the fixtures. Log back in... Nice, we're in…

5:47
Restricting Impersonation with a Voter

…ROLE_ADMIN. Duplicate this line to add 5 more but for ROLE_CAPTAIN: That creates five admins and five captains on top of our existing users. Load them: symfony console foundry:load-fixtures Back in the app, refresh - we'll be logged out, because the…

6:40
Cosmic Queries: the Repository Class

…second is the findAll() from findMyShip(). Perfect! Next, let's improve our fixtures and make them 100 times more fun with a library called Foundry. This will let us create a whole fleet of Starships as if we had a replicator. Let's do it!

5:15
PHP 8.4 & Recipe Updates

…from Doctrine. We'll have a whole chapter on upgrading Doctrine a little later, so we'll ignore these for now. The fourth one is a deprecated config option from zenstruck/foundry. Before manually fixing this, let's first update our Symfony Flex recipes. Sometimes…

11:21
Mapped Superclasses

…scout. Let's see how this plays out when we reload the fixtures for our app. Run: symfony console foundry:load-fixtures Here's a snag: we can't instantiate the abstract class Starship. We're using Foundry factories, and since Starship is now abstract…

4:05
Running Code "On Publish"

… At the end of the test, say NotificationFactory - that's a Foundry factory that I created, ::repository() - to get a repository helper - then ->assert()->count(1). With Foundry, our database is always empty at the start of a test: so checking for 1 row is…

6:05
Bootstrapping a Killer Test System

…But that's way too much work. Instead, add one more trait to our test class: use ResetDatabase: This comes from Foundry: the library we've been using to create dummy fixtures via the factory classes. ResetDatabase is amazing. It automatically makes sure that the…

8:18
Testing a Service

…created the $lockDown variable through Foundry, it's wrapped in a Proxy. One of the main features of a Proxy is called "auto-refreshing". Each time you access a property or call a method on your entity, behind the scenes, Foundry queries for the latest…

7:31
Upgrading Encore and your assets/ Setup

…fixed all of the conflicts... and commit! Now, dear friends, we are on the last update. It's zenstruck/foundry. This is an easy one. Run: git status It is, once again, environment configuration going into a main file. So let's commit that. And..…

8:22
Data Fixtures

…especially once you have database relationships where objects are linked to other objects... these classes can get ugly fast. And they're not much fun to write. So, next: let's use a shiny new library called Foundry to create numerous, random, rich dummy data.

5:18
18 lines | config/packages/zenstruck_foundry.yaml
when@dev: &dev
// ... line 2
zenstruck_foundry:
enable_auto_refresh_with_lazy_objects: true
// ... lines 5 - 18
See Code Block in Script
so foundry generates a "Factory", so what do I call my acctual (non fixtures) factories then? Or is a foundry factory supposed to be used (i.e. replace my existing entity factories?) for generating non-fixtures also? It's a bit confusing.
// ... lines 1 - 5
use Zenstruck\Foundry\Test\ResetDatabase;
class LemonSqueezyRequestParserTest extends WebTestCase
{
use ResetDatabase;
// ... lines 11 - 18
}
See Code Block in Script
// ... lines 1 - 8
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
// ... line 11
class LockDownRepositoryTest extends KernelTestCase
{
use ResetDatabase, Factories;
// ... lines 15 - 42
}
See Code Block in Script
I tried using foundry, but it's not clear how to override the createOne method (if you need to do some custom work). Is there somewhere that has more comprehensive information on how to use this? It would be great if you guys had some…