I
I
ildar-meyker2021-01-28 19:05:17
Laravel
ildar-meyker, 2021-01-28 19:05:17

Where can I see practices for writing good tests for laravel?

Actually, I turned to open source projects on github. And at first I liked how everything was implemented in this project https://github.com/austintoddj/canvas . Decided to take the approach. I started digging and here I don’t understand how a specific id is substituted into the endpoint template. https://github.com/austintoddj/canvas/blob/master/...

If you have links to other projects in mind where you can peep how to organize everything within laravel 8, I will be grateful. Or maybe a tutorial or an extensive article.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jazzus, 2021-01-29
@ildar-meyker

In programming, you can invent any kind of "best practice" in endless variations. I would not look at these inventions. Everything is clearly written in the docs. Http tests test http requests and nothing else, the list of assertions is given and so on. Tests are not written for best practices and "coverage", they are written so that you need them as a developer, fix the necessary functionality and work. Not tests for the sake of tests. In terms of structure, everything is simple - the same objects, configs, etc. (as, for example, he hasprimaryPost is duplicated everywhere) - in setUp class test if in all tests or is taken out in TestCase/traits and further tests. Each is started from scratch, with rare exceptions, dependencies are written through @depends. And tests need to be written before development (tdd). Otherwise it will be a hogwash, instead of tests. Or most likely they won't. "covering" existing functionality is very tedious and uninteresting. Unlike tdd, which makes development easy and enjoyable.

I
Ilya Chubarov, 2021-01-28
@agoalofalife

In general, you can look at Jeffrey Way at https://laracasts.com
I also liked his book, though it's probably not much outdated.

I started digging and here I don’t understand how a specific id is substituted into the endpoint template. https://github.com/austintoddj/canvas/blob/master/...to

I dug around and discovered something new for myself too ..
In the link there is a method below and it has a @dataProvider meta tag on top
What it is, you can read about it here
What about true way or laravel way - it's all relative.
For example, in this project, he tests relationships in models, let's just say this ..
Then he tests console commands .. I wonder why?
Of course, you can test everything, but what's the point?
Folder organization is also a delicate matter, as is the naming of methods and variables.
I like the DDD approach better. As a rule, business requirements and not infrastructure change most often in a project.
What can happen more likely - to change the database or change the algorithm for accruing funds?
So testing the domain is much more justified than testing model relationships in Eloquent.
Okay, something I went wrong, in short, write tests -> gain experience -> refactoring -> write tests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question