201 search results

Factory Data Seeding

…handy. But it's actually wrapped in a special proxy object. So if we run the test now, you can see it's a proxy... and the LockDown is hiding inside. Why does Foundry do that? Well, if you go and find their documentation, they…

5:56
State Processors: Hashing the User Password

…Now, we need to hash that password before the User is saved to the database. Like we showed when working with Foundry, hashing a password is simple: grab the UserPasswordHasherInterface service then call a method on it: But to pull this off, we need a…

6:55
Allow Admin Users to Edit any Treasure

…a public function testAdminCanPatchToEditTreasure(). Then create an admin user with UserFactory::createOne() passing roles set to ROLE_ADMIN: That'll work fine. But if we need to create a lot of admin users in our tests, we can add a shortcut to Foundry. Open UserFactory…

4:11
Course

Pro Testing

PHPUnit: Integration Testing with Live Services

… When do I need that? Accessing services from the container Clearing the database between tests Seeding the database Foundry Factories & more! Partial Mocking: mock just some dependencies Testing emails Testing messenger messages Integration tests are fun and are a critical tool to a well-rounded…

10 videos
|
1:02:48
Course

Learn APIs

API Platform 3 Part 2: Security for your Treasures

…imaginable... and spin up a nifty test suite along the way: Disabling documentation on production Different types of API authentication Logging in via Ajax & sessions Creating an API Token system with "scopes" Securing your API resources Bootstrapping tests with zenstruck/browser & zenstruck/foundry! How to…

37 videos
|
3:43:31
Custom Resource State Processor

…tests/Functional/, create a new class called DailyQuestResourceTest. Make this extend the ApiTestCase that we created in the last tutorial and use ResetDatabase from Foundry to make sure our database is empty at the start of every test. Also use Factories. Ok, we don't…

6:48
Doctrine, Symfony 6 & the Database

…with Docker via the Flex recipe system Database config Creating (and updating) Entities with make:entity Generating & using migrations Inserting new data Fetching & Querying for data Doctrine Repositories Custom queries and the query builder Fixtures (Dummy data) using Foundry Relationships & Associations SELECT * FROM doctrine_knowledge.

22 videos
|
2:28:56
Doctrine, Symfony & the Database

…s go! Booting a database with Docker via make:docker:database Database Configuration Creating (and updating) Entities with make:entity Generating & using migrations Inserting new data Fetching & Querying for data Doctrine Repositories Custom queries and the query builder Fixtures (Dummy data) using Foundry Relationships & Associations

23 videos
|
2:22:24
QuestionTag Fixtures & DateTimeImmutable with Faker

…reflect this. First, since we now have a QuestionTag entity, we are going to be creating and persisting QuestionTag objects directly. So let's generate a Foundry factory for it. At your terminal, run: symfony console make:factory And choose QuestionTag. Go open that up…

4:07
Saving Relations

… This is actually pretty easy... but it might feel weird if you're used to working with databases directly. Open up src/DataFixtures/AppFixtures.php. We're using Foundry to add rich fixtures, or fake data, into our project. But to see how relationships work…

3:58
Detecting the "Published" State Change

…send the PUT request, there is exactly one CheeseNotification in the database. Now, thanks to Foundry - the library that helps us insert dummy data both in our data fixtures and in our tests - before each test case, our database is emptied. That will make it…

9:08
Symfony 5: Mastering Doctrine Relations

…Generating a ManyToOne relationship (association) Relation annotations / PHP 8 attributes The OneToMany inverse side of a relation Handling relationships in fixtures with Foundry The owning versus inverse sides of a relation Doing magic with the ArrayCollection (Criteria) Querying with Joins ManyToMany Relations So let's…

27 videos
|
2:45:18
Course

Pro Testing

Symfony End-to-End Testing: WebTestCase to Playwright

…way, we'll cover: Unit vs integration vs end-to-end tests: what each one is good at and where they fit WebTestCase and Symfony's built-in functional testing tools Creating exactly the database state we need with zenstruck/foundry zenstruck/browser for expressive…

20 videos
|
Rechecking Users with user_checker_on_refresh

…checker fast. Doing a bunch of database lookups in there would slow down every single authenticated request. Let's try it! Reload the fixtures so nobody is disabled: symfony console foundry:load-fixtures Now log in again as janeway@starfleet.space, password coffeeblack. We're…

3:33
Disabling Users with a Custom UserChecker

…enabled or disabled, public function isEnabled(): bool and inside, return null === $this->disabledAt;: Foundry gives you the ability to add states to your factory, and it's pretty simple to do. I want to add a disabled state to our user factory so we…

5:41
Resetting a Forgotten Password

…to create a migration: symfony console make:migration Find it under migrations/ in your IDE and set the description to add reset_password_request table: Then reload the fixtures: symfony console foundry:load-fixtures Let's look at some of the files that were created…

10:49
User Doctrine Relationship

…Finally, 'status' => StarshipStatusEnum::IN_PROGRESS: Great! Back in the terminal, reload the fixtures with: symfony console foundry:load-fixtures Now to grab "my ship" from the currently logged-in user! Back in MainController::index(), set $myShip to $this->getUser()?->getStarship(): The getUser() method is…

4:18
Creating a Super Admin Voter

…fixtures, so over in the terminal, reload them with: symfony console foundry:load-fixtures Now create our custom voter: symfony console make:voter Call it SuperAdminVoter. Jump back to the IDE and find it: src/Security/Voter/SuperAdminVoter.php. Clear everything out - the constants, supports…

5:23
Logging in with a Username or Email

…is fully updated, create a migration with: symfony console make:migration Jump to the migrations/ folder and find it. For the description, use add user.username column: Adjust the Foundry factory. In src/Factory/UserFactory.php, duplicate the email default, name it username, and use…

5:21
Customizing Authentication Error Messages

…makeitso. "Account is disabled." We see the real error now. Reload the fixtures so Picard is enabled again: symfony console foundry:load-fixtures Now use a wrong password: enterprise. "Invalid credentials." That makes sense - the credentials were invalid. But try an email that doesn't…

6:00