Martin Joo Profile picture
Jan 5, 2022 7 tweets 3 min read Read on X
This is the red-green-refactor cycle from the Test-Driven Development world.

It helps you:
- Approach problems from a different perspective
- Avoid bugs
- Build more maintainable applications

🧵Keep reading Image
1/6 The red

First, you write a test. You don’t have any code yet, but you know what you want to write.

So you write a test for the most simple use-case.

Something like that: Image
2/6 The green

(Yes, we are doing the calculator example!)

Now it’s time to make this test pass, or in other words, make it green!

In this phrase you should write the minimum amount of code that makes your test green: Image
3/6 In the red again

After that, you may find new requirements or edge-cases for your class.

For example, what happens with division by zero?

You found a new edge-case, so you write a test for it: Image
4/6 In the green again

Of course, you don’t have any code yet that takes care of division by zero, so you should write it: Image
5/6 The refactor

Now everything is green, but during lunch, you read about clean code, and now you hate the divide function.

At this point, you have 100% code coverage meaning the whole class is covered with tests. You’re almost unable to make mistakes! So let’s refactor: Image
6/6 Thank you for reading this!

Today I released a book “Test-Driven APIs with Laravel and Pest” where I cover these topics in great detail.

So far it got only 5-star ratings:
martinjoo.gumroad.com/l/tdd-api-lara…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Martin Joo

Martin Joo Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mmartin_joo

Mar 12
🛠️ How to measure performance in Laravel

There are some pretty simple tools you can start measuring your app's performance with:
- ab
- jmeter
- Inspector
- Telescope

🧵 Keep Reading Image
1/14 Here are some of the most important measures of an API/backend service:
- Throughput: the number of requests the system can handle
- Load time: the amount of time it takes for an HTTP request to respond
- Size: the total size of the HTTP response.
2/14 ...measures of an API/backend service

- Server uptime: the duration of time the server is up and running
- CPU usage: the amount of CPU your system needs to run. It is usually expressed as load average
- Memory usage: the amount of memory your system uses
Read 15 tweets
Nov 24, 2023
💡How to integrate 3rd parties into your application?

We have to integrate with a ton of 3rd party APIs, and SDKs in every project. You can treat them as mini-applications inside your app.

🧵Keep Reading Image
1/14

Treat your 3rd parties as if they were mini-applications inside your application. They have their own namespaces with their own DTOs service classes and so on. Something like this: Image
2/14

In the Services folder, I create a new folder for each 3rd party and treat it like it is a mini-application inside my app.

It looks like this: Image
Read 15 tweets
Nov 21, 2023
💡 If you're running PHP or Laravel apps in production you're probably using nginx and php-fpm.

But do you actually know what these terms mean?
- CGI
- FastCGI
- php-fpm
- How do they connect to nginx?

Let's find out!

🧵 Keep Reading
Image
Image
1/9 CGI

CGI stands for Common Gateway Interface. As the name suggests, it's not a package or library. No, it's an interface, a protocol.

CGI gives us a unified way to run scripts from web servers to generate dynamic content. Image
2/9 CGI

It's platform and language-independent so the script can be written in PHP, python, or anything.

CGI uses a "one-process-per-request" model. It means that when a request comes in to the web browser it creates a new process to execute the php script:
Read 10 tweets
Sep 20, 2023
🔥If you struggle to start with CI/CD pipelines here’s a pretty basic but useful one with:

- phpstan analysis
- phpinsight analysis
- unit tests

🧵Keep Reading
Image
Image
1/10

At the beginning of every GitHub workflow, we need to define what is going to trigger it.

In this case, it’ll run if you push to the main branch or you open a PR to it: Image
2/10

In the next section, we can define the jobs. Each job defines a set of steps (for example a script) and these steps run in order.

In this simple example, I only have one job that runs on Ubuntu: Image
Read 11 tweets
Sep 19, 2023
💡 If you're running PHP or Laravel apps in production you're probably using nginx and php-fpm.

But do you actually know what these terms mean?
- CGI
- FastCGI
- php-fpm
- How do they connect to nginx?

Let's find out!

🧵 Keep Reading
Image
Image
1/9 CGI

CGI stands for Common Gateway Interface. As the name suggests, it's not a package or library. No, it's an interface, a protocol.

CGI gives us a unified way to run scripts from web servers to generate dynamic content. Image
2/9 CGI

It's platform and language-independent so the script can be written in PHP, python, or anything.

CGI uses a "one-process-per-request" model. It means that when a request comes in to the web browser it creates a new process to execute the php script:
Read 10 tweets
Sep 11, 2023
Here are my favorite 16 Laravel packages📦

I would immediately DIE without them!

🧵Keep Reading
1/17 laravel-excel

The single best package to handle Excel exports and imports:

- Exporting collections
- Storing files
- Exporting from a query
- Queue jobs
- And more Image
2/17 laravel-health

This amazing Spatie package can monitor the health of your application and server. It sends you notifications if something's wrong. For example:
- CPU load
- Used disk space
- Database connections
- Redis
- and more Image
Read 18 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(