Testing with Laravel is very easy, but it can be a nightmare when the tests depend on Events and Listeners. In this post I’m gonna show you how you can simplify and improve those tests.
Laravel is one of the most popular PHP frameworks nowadays, and I’d say its Event handler is one of the most powerful features. Using events in Laravel is usually very easy, but when your app gets bigger you can get in trouble with previously written tests.
When testing events in Laravel, you can
fake() events in a very simple way, like the documentation says. The problem is not with the events, but with the listeners, because usually a listener does a single action, but with more than one listener you start writing repeatable tests.
Continue reading Solitary or Sociable? Testing Events and Listeners using Laravel
Learn how to configure XDebug and PHPUnit in PHPStorm, allowing you to write better tests and fix bugs faster.
Test Driven Development (TDD) is an old topic, I know, but it seems many people don’t understand how it makes you write better code. The point here is that one of the most important benefits it’s to use debugging tools together with tests, making your flow more efficient.
I started using TDD on the command line, and still use it sometimes, but since I started using PHPStorm and decided to try how it handles tests, and that’s amazing! When you add debugging tools – like XDebug – to it everything starts making sense, then you have the feeling you’re on the right path.
PHPStorm has a dedicated interface to run and debug tests, almost in the same window, what makes the process of writing code safer and easier.
Continue reading Using XDebug with PHPUnit in PHPStorm