RESTful API - Part 3 - The Data provider (Repository) - Symfony 5, Docker, Redis, PHPUnit, TDD

preview_player
Показать описание
Third 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'll 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 implementing the provider/repository which will retrieve our data from the data source. At the moment the data source consists of a collection in Json format. The provider implements an interface so we will be able to replace it at minimum cost. Of course we're using the Test Driven Development approach.

Useful links:

Timestamps:
00:00 Recap
01:52 TDD means tests first
03:27 The Get* method
04:18 Fixtures
05:07 Making the test pass
12:17 Moving forward: filtering results based on parameters (and more fixtures)
14:20 array_filter (PHP function)
20:25 introducing a query parameter to limit the number of results
25:16 LONG TALK ALERT: how to implement the limit, array_filter limitations, previously overlooked "limit" design (if you're not interested you can skip to 30:03)
30:03 the right approach and the passing tests
38:40 what's coming next
Рекомендации по теме
Комментарии
Автор

these TDD approach looks like insanity. You mock your provider, then write tests to test your mock wtf. I dont understand it

Lancelot
welcome to shbcf.ru