September’s links.Read More
In our previous 2 articles (“What is Test Driven Development?” and “Introduction to PHPUnit”), we discussed what Test-Driven Development is and why you should use it and we gave a very basic intro to PHPUnit. In this article, we’ll work through how to use PHPUnit to develop some new features using TDD.Read More
As developers, we spend a lot of time testing code that we’ve written. Generally, this is a manual process where we write a little code and then type in some inputs to verify we get what we expect. The downside to this process is that it’s very time-consuming to manually enter a bunch of input to see if one of them now fails after we’ve made a change.
What if we could use an automated testing tool to do the hard work for us? That’s where PHPUnit comes into the picture.Read More
As developers, a large portion of our time is spent testing code that we’ve just written. In a traditional testing cycle, we’ll write some code and then manually test. We’ll enter some inputs and find that it causes an error so we’ll write a little bit more code to fix that error and test again only to find another set of inputs that fails. We’ll slowly work through this process until we feel confident that everything is operating correctly. But how do we know that the first set of bad data we found is still error-free? How do we know it’s still error-free a year from now?
We could continue to manually test all these permutations but almost all of the time they’re going to continue to run perfectly. Because it’s very time consuming to run through all these permutations we’re not going to keep this up. Using tools like PHPUnit we can create automated tests that will make testing our code infinitely more repeatable. Embracing Test-Driven Development (TDD) will allow us to quickly build a suite of automated tests that will allow us to improve the maintainability and reliability of our code.Read More
August’s links.Read More
One of the hard parts about learning how to develop software is the minefield of acronyms that exist within the industry.
The goal of this series of articles is to shine a light on an acronym so that the next time another developer uses it in conversation you can follow along without missing a beat.Read More
In PHP it’s fairly common to see the
We run across these all the time and can easily understand what happens when we pass them a
false value. However what happens when the condition of the
if statement is an object, a string, or a number?
Loosely typed languages like PHP allow us to use any kind of variable as if it was a boolean value in our
When PHP needs to evaluate the
if statement it converts our variable into something is can represent as a boolean. Ideally this would be a
false but in PHP it will convert any variable into something it can represent as one of those two values. This is where “truthy” and “falsy” come in. A variable that isn’t
false can be truthy or falsy.
Luckily for us there’s a logical consistency with how PHP type juggles our variables into truthy and falsy. For the most part the logic is that anything “empty” is falsy and anything with a value is truthy.
0 is falsy but
-1 are truthy.
Empty arrays are falsy but arrays with a value are truthy.
Empty strings are falsy but strings with a value are truthy.
null values are falsy.
subscribe via RSS