185 search results

Relating Resources

…new owner field to getDefaults() set to UserFactory::new(). I'm not going to go into the specifics of Foundry - and Foundry has great docs on how to work with relationships - but this will create a new User each time it creates a new DragonTreasure…

7:08
Cascade Persist

…again: Guess what? They work! Behind the scenes, Foundry is calling addDroid() on each Starship for each droid. And we just proved that addDroid() is back in action. The creation of the StarshipDroid join entity is now hidden from our entire codebase! But, what if…

2:51
Emails Assertions in Functional Tests

…before, this may look a tad different because I'm using some rocking helper libraries. zenstruck/foundry gives us this ResetDatabase trait which wipes the database before each test. It also gives us this Factories trait which lets us create database fixtures in our tests…

6:01
Resetting the Database

…log file instead: logFile=var/log/deprecations.log. Close that up. Now when we run the tests: Clean and tidy! And the deprecations are still waiting for us in the log file. Next: let's leverage Foundry Factories to make seeding our database an absolute delight!

4:47
JSON Test Assertions & Seeding the Database

…the database is empty. To make our test real, we need data: we need to seed the database with data at the start of the test. Fortunately, Foundry makes that dead-simple. At the top, call DragonTreasureFactory::createMany() and let's create 5 treasures. Now…

3:41
Translatable Mapping

…when we switch to French on our site, we'll display some mock French data, just like we currently have mock English data. We need to create a factory using Foundry. So, run: symfony console make:factory Create a factory for the Translation entity: 0…

5:19
The Repository Test Helper

Foundry comes with a nice trick for this. After we call the method, say LockDownFactory. Normally, we would call things like create or createMany, but this also has a method on it named repository. This returns an object from Foundry that wraps the repository - much…

5:13
Simple Doctrine Data Fixtures

…stuff. But for developing, I want a really rich set of data fixtures, like... maybe 25 mixes. We could add those by hand here... or even create a loop. But there's a better way, via a library called "Foundry". Let's explore it next!

3:25
Hashing Plain Passwords & PasswordCredentials

…property... but then the password property would stay null... and it would explode in the database because that column is required. So after Foundry has finished instantiating the object, we need to run some extra code that reads the plainPassword and hashes it. We can…

4:22
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
Writing an Integrational Test for Webhooks

…the test environment. Our test is failing because we need to set up a test database. We could do this manually using Doctrine console commands, but let's take advantage of Zenstruck Foundry, which we already have installed. In the test class, add use ResetDatabase…

7:16
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
App & Test Setup

…to use Symfony 5.1 and API platform 2.5: I also added Foundry to our system, which is a new library that makes it really easy to create dummy data: We're using Foundry inside of our data fixtures - so src/DataFixtures/AppFixtures.php -…

7:44
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
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
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
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
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