RESTful API - Part 4: Validating Parameters with Symfony's Validator Component - PHP, Symfony 5, TDD

preview_player
Показать описание
Fourth episode of this short series where I'll try my best to walk you through the creation of a RESTful API with Symfony 5 (skeleton) in REAL TIME.

We used using Docker to setup a local environment and we'll use Redis to cache responses.

I use the TDD (Test Driven Development) approach where you write tests first to define the your objects' behavior which also helps obtaining a better design and test coverage. To do that I'm gonna be using PHPUnit, in particular the Symfony PHPUnit bridge package, and the Liip functional test bundle.

Far from me the idea of "teaching" programming to anyone. The point here is to provide a starting point to beginners and less experienced developers; I often find myself stuck or wondering on the best approach and in those circumstances Google, Stackoverflow and Youtube are your best friends, opening a window on other developers' ideas, opinions, best practices and approaches.

This wants to be my "little" way of giving back to the community.

In this episode we're integrating the Symfony's Validator Component and, in particular, we'll use its Collection Constraint to validate the parameters passed to our endpoint via the url's query parameters.

Useful links:

Timestamps:
00:00 RECAP
00:45 How we're going to proceed
03:00 Tests first
03:56 Fixing existing tests and configuring services for our test environment
09:30 Failing tests, let' implement our Validator to make 'em pass
19:54 Intoducing Symfony's Validator Component
20:22 The Collection Constraint (and its configuration)
25:05 Tests break! Let's refactor our code and make 'em pass
30:03 A tricky test failure and a silly error...
35:00 The solution and the passing tests
Рекомендации по теме
Комментарии
Автор

Hi, what editor color theme are you using? It looks great

danyos
Автор

It is hard to read on laptop because of text style do you have 1080p for readibility. I am working on TDD and data validation so this course was helpful.

eldahalas
join shbcf.ru