The testing book you've been waiting for.
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do.
Welcome
Ive seen it way too many times. As your application grows, so does your sloppy, untested codebase. Before long, you begin to drown, as your ability to manually test the application becomes unrealistic, or even impossible! Its at these specific times, when you begin to realize the down-right necessity for testing. Sure, you might have read a TDD book in the past, but, like many things in life, we require real-life experience, before we suddenly - in that wonderful aha moment - get it.
The only problem is that testing can be a tricky thing. In fact, its quite possible that your codebase, as it currently stands, is untestable! What you may not realize is that, while, yes, testing does help to ensure that your code works as expected, following this pattern will also make you a better developer. That messy, untestable spaghetti code that you might have snuck into your project in the past will never happen again. Trust me: as soon as you bring the question how could I test this to the forefront of every new piece of code, youll, with a smile on your face, look back to your former self, and laugh at your crazy, cowboy ways.
Welcome to modern software development.
| While the principles of testing (and TDD) are language-agnostic, when it comes to execution, there are a variety of tools and techniques at your finger tips. This book is as much an introduction to TDD, as it is a deep analysis of the Laravel way of testing applications. |
It Has Begun
When it comes to programming languages, everyone has an opinion. And when the topic of conversation switches to PHP specifically, well, prepare yourself for the vitriol. Despite the fact that the language has matured significantly in the last five years, there are those who, like a father staring at his grown-up daughter, still cant help but see PHP as a baby.
The naysayers dont see version 5.5, or OOP, or modern frameworks like Laravel, or Composer, or a growing emphasis on test-first development. No, what they see is that old sloppy PHP 4 code, and, worse, poorly made WordPress themes from 2008.
Is PHP as beautiful a language as Ruby? No. Is its API inconsistent from time to time? Definitely. Has its community lead the development world, in terms of innovation and software design? Certainly not. So the question is, why? Why does PHP dominate - to the point of 80% market share - when competing languages are admittedly more elegant? Well, maybe theres something else to its success. Maybe, the fact that you can create a file, echo
hello world, and immediately see the output in a browser is far more powerful and user friendly than we give it credit for. Maybe its flexibility is a virtue, rather than a vice.
Since when did ease-of-use become something that others mocked?
Or, perhaps the simple truth is that PHP is not the new hotness. Its not overly sexy. Its not in beta. But, you know what? We get stuff done. Say as much as you want about PHP 4. While youre doing that, the rest of us will be building things with the latest that the language and surrounding ecosystem have to offer.
The time for hating PHP is over. The PHP renaissance has begun. We use modern object-oriented techniques, we share packages through Composer, we embrace version control and continuous integration, we evangelize modern frameworks, we believe in testing (you soon will too), we welcome newcomers (rather than lock the door), and we do it all with a smile.
The best part is that, as a Laravel user, youre at the forefront of this new modern movement! When I first joined Laravels IRC channel, within minutes, somebody said Welcome to the family. Nothing describes our community more beautifully than that. Were all in this together. This is the PHP community I love.
If you purchased this book, it sounds like you could use a bit of help in the testing department. In Laravel spirit, welcome to the family. Lets figure this out together.
Is This Book For Me?
The difficult thing about writing a technical book is determining where to draw the line, in terms of which prerequisites are required before reading chapter one. As long as you have a basic understanding of the following technologies, please do continue!
- PHP 5.3
- Laravel 3 (preferably version 4)
- Composer
Why Laravel-Specific?
Sure, many of the techniques outlined in this book can be applied to any language or framework, however, in my experiences, its best to take your first steps into this new world in as comfortable shoes as possible. Can you learn test-driven development from a Java book? Absolutely! Would it be easier through the lens of the language and framework that you already know? Certainly.
Secondly, the downside to a generic testing book is that I wouldnt be able to demonstrate many of the PHP-specific features and packages that I use in my every day coding. This includes everything from PHPUnit helper packages, to acceptance testing frameworks, like Codeception.
Finally, its my hope that, as you read through this book, in addition to improving your testing knowledge, youll also pick up a variety of Laravel-specific tips and tricks.
Exercises
Sporadically throughout this book, Exercise chapters will be provided. Think of these as highly in depth tutorials that you are encouraged to work through, as you read the chapter. Theory can only take us so far; its the actual coding that ultimately commits these patterns and techniques to memory.
So, when you come to an Exercise chapter, pull out the computer and join me through each step!
Errata
Please note that, while Ive made every attempt to ensure that this book is free of errors and typos, my human-ness virtually guarantees that some will sneak in! If you notice any mistakes, please file an issue on GitHub, and Ill update the book as soon as possible. As a reward, a five minute hug will be granted to each bug filer.
How to Consume This Book
While you can certainly read this book from cover to cover, feel free to flip around to the chapters that interest you most. Each chapter is self-containing. For instance, if you already understand the basics of unit testing, then you clearly dont need to read the obligatory Unit Testing 101 chapter! Skip it, and move on to the more interesting bits and pieces.
Get in Touch
It sounds like were going to be spending a lot of time together, as you work your way through this book. If youd like to attach a face to the author, and, perhaps, ask some questions along the way, be sure to say hello.