Posts tagged with testing
Continuous Integration with GitHub Actions and Laravel 6
Roberto B wrote a good tutorial on how to test your Laravel 6 application using GitHub actions.
The scenario that I would like to explain you is: I have a Web App based on Laravel 6, every time I push some new code on master branch on the GitHub repository, I would like to execute automatically Unit tests and Feature tests.
Read more [medium.com]
Join 9,500+ smart developers
Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
"Freek’s newsletter is one of the best ways to stay updated with the Laravel and PHP ecosystem. It consistently highlights useful packages, tools, and ideas from the community, especially the amazing work coming from Spatie. As a Laravel developer building SaaS and web platforms, I find it extremely helpful to discover practical tools and insights that improve my development workflow."
Useful testing methods in Laravel
☝️If you are relatively new to Testing in Laravel. Here are 3 methods you NEED to be familiar with.
— Caleb Porzio (@calebporzio) August 21, 2019
Understanding these will make your life much easier. pic.twitter.com/x3mxjCsV9z
Read more [twitter.com]
Implementing event sourcing: testing aggregates original
Earlier this year we released v2 of laravel-event-sourcing. This package is probably the easiest way to getting started with event sourcing in Laravel. A significant feature of v2 was the addition of aggregates.
Today we released another new version of the package that adds test methods. These methods allow you to verify if the aggregate behaves correctly. In this post, I'll show you an example and explain how the test methods are implemented.
These test methods were inspired by the awesome testing methods Frank De Jonge made in his Eventsauce package.
Start testing your Laravel applications
Jason McCreary wrote an epic blogpost on how to get started with tests in a Laravel app. I wish I could have read this when I started out with testing.
This brings me to the next common response, we don’t know where to start testing. This comes in two forms. The first form is quite literally we don’t know which test to write first. The second form is more not knowing how to write the first test. ... Today, I want to focus on getting started with testing your Laravel applications.
Read more [jasonmccreary.me]
The case of the Laravel TestCase
Tim MacDonald, a freelance software developer based in Sydney, investigates how to make Laravel tests run faster. Turns out you a lot can be gained by caching the config.
I saw a conversation on Twitter the other day discussing how Laravel was slowing down a test suite. I decided I wanted to dig into this and see if there was anything to it.
Read more [timacdonald.me]
A package to control the flow of time original
Imagine you're building that your app can notify your user, but you don't want to send more than one notification in a timeframe of five seconds. How are you going to test the time aspect? Do you have to create a test that takes five minutes?
Your first performance budget with Lighthouse
Ire Aderinokun, Front-End Developer and User Interface Designer, explains how you can Lighthouse in CI.
Until recently, I also hadn't setup an official performance budget and enforced it. This isn’t to say that I never did performance audits. I frequently use tools like PageSpeed Insights and take the feedback to make improvements. But what I had never done was set a list of metrics that I needed the site to meet, and enforce them using some automated tool.
Read more [bitsofco.de]
Tests and types
My colleague Brent wrote another excellent blog post, this time on tests and types.
So while strong types can help us to ensure program correctness, some tests will always be a necessity to ensure business correctness. It's a matter of "both and", not "either or".
Read more [stitcher.io]
Testing Streamed Responses in Laravel
Over at Laravel News, Paul Redmond published a good way to test streamed responses.
Read more [laravel-news.com]
The right way to call assertions in PHPUnit
It's a bit of a click baity title, but reading it I learning that all PHPUnit's asserts have a function equivalent.
During the preparation of TDD workshops, I began to think about how to write assertions. It turns out that there are several possibilities, but is there the only correct one?
Read more [arkadiuszkondas.com]
How to test something is being pulled out of storage in Laravel
How to test something you are pulling OUT of Storage.
— Jake Bennett (@JacobBennett) March 19, 2019
Typically Laravel Storage testing is comprised of asserting that you put something IN Storage. If you happen to be pulling something down from a Storage disk and doing some processing on it, this has been helpful. pic.twitter.com/VjSqo914US
Read more [twitter.com]
Tidying Up Your PHPUnit Tests with Data Providers
Over at the Tighten blog, Chris Trombley published a new post on how to use data providers in PHPUnit.
PHPUnit gives us a way to consolidate this common logic while varying our setup data, without losing the benefit of dedicated, smaller test methods. In this post, we'll explore PHPUnit's data providers. While data providers are available in any PHPUnit test suite, let's look at how they can help us tidy up our tests in a Laravel application.
Read more [tighten.co]
Testing simple S3 uploads with randomized file names in Laravel
? Testing simple S3 uploads with randomized file names in Laravel? Use `Storage::fake` and real-time Facades. Handled. pic.twitter.com/LIBfHbLQxD
— HEMPHILL (@davidhemphill) March 12, 2019
Read more [twitter.com]
Adding your own faker provider
One great way to keep your @laravelphp test factories clean is by creating custom faker providers that you can use to create custom fake data, whenever you need to fake something that the built-in faker does not yet support. pic.twitter.com/kwwuevuUf9
— Marcel Pociot (@marcelpociot) March 5, 2019
Read more [twitter.com]
Using relations in Laravel factories
? Laravel tip: Use your defined Eloquent relationships when you Factory models.
— Rasmus C Nielsen (@rasmuscnielsen) March 4, 2019
This can save you many lines of code and make your tests much more eloquent.
Simply install this package: https://t.co/6XNeQZk40T pic.twitter.com/f4T5xayL5X
Read more [twitter.com]
20 lines of code that will beat A/B testing every time
In an older but still post, Steve Hanov explains a nice algorithm to test out new features on your audience. I don't now if this approach will yield better results, but it sure is an interesting idea.
In recent years, hundreds of the brightest minds of modern civilization have been hard at work not curing cancer. Instead, they have been refining techniques for getting you and me to click on banner ads. It has been working. Both Google and Microsoft are focusing on using more information about visitors to predict what to show them. Strangely, anything better than A/B testing is absent from mainstream tools, including Google Analytics, and Google Website optimizer. I hope to change that by raising awareness about better techniques.
Read more [stevehanov.ca]
How migrations might be slowing down your Laravel tests
Having a lot of migrations might slow down your tests. My colleague Alex shares how you can fix this.
One of the larger test suites I run daily has about 1500 tests in it. It takes just over 4 minutes to complete at an average of 160ms per test. That's pretty good. However, lately I've noticed a delay between starting PHPUnit and running the first test. This delay grew to the point where running a single test would take almost 12 seconds with the setUp method using most of that time on... migrations.
Read more [alexvanderbist.com]
Tips to Speed up Your Phpunit Tests
On the Laravel News blog, Tim MacDonald wrote a nice collection of tips on how to make PHPUnit tests run faster.
Having a fast test suite can be just as important as having a fast application. As a developer, getting feedback quickly about the state of your code allows for a much quicker development turnaround. Here we are going to run through some tips you can implement today to make your tests run faster.
Read more [laravel-news.com]