Logan Bailey

Adventures In Web Development

Blog, About, GitHub, and LinkedIn

Testing With Traits

April 5th, 2018
Traits are an easy way to share code between classes, but how do you test them? I used to test the trait in isolation and not test the traits functionality while testing the classes that used the trait. This lead to passing tests and bugs. I tried copy and pasting code between tests, but this always seemed like a bad solution. Lately, I've been using traits to test traits and have been happy with the results so far.

Ramsey UUID and Unit Tests

March 22nd, 2018
Generating Uuids with Ramsey Uuid is damn easy, \Ramsey\Uuid\Uuid::uuid1(). Generating predictable Uuids for testing while not obvious, is not difficult either. In a few simple steps you can replace the default Uuid Factory with a mock factory that will return your specified Uuids .

Monolog And The Fingers Crossed Handler

March 10th, 2018
Monolog is the defacto logging library for php and FingersCrossedHandler _should_ be the defacto Handler. It's designed to only show debug logs when an error level log has been recorded. But this can lead to too many logs or not enough logs. Luckily, with the right configuration the handler can provide you with just the right amount of the right logs. Come see how to configure your Fingers Crossed Handler.

You're Writing Your Tests Wrong

March 31st, 2017
While preparing for a talk, I realized that I'd been writing unit tests wrong for the last 3 years. I'd always approached test writing iteratively rather than from the outside in. With this one change, I was able to write cleaner more maintainable tests.

Data Provider Quick Tips

January 11th, 2017
Data providers are a powerful tool that allows the developer to reuse the same test with different input variables. Here are some easy tips that will take your dataProvider to the next level

Interesting Articles About PHP Middlewares

December 13th, 2016
While doing research for an upcoming talk about php middlewares, I came across these blog posts and libraries that I thought were really insightful and interesting.

Converting Strings to Streams

September 29th, 2016
With PSR-7 almost execlusively using streams, it's almost essential to have an easy way to convert a `string` into a `stream` resource. Combing across the internet, I've found Evert's blog post last updated June 23rd 2016. I've adapted his 3 liner sample code into a simple function:

When Convention Gets It Wrong

June 10th, 2016
Convention is a powerful tool, it allows programmers to make assumptions about how code will work. However, when choosing between self documenting code and convention, self documenting wins. Conventions make assumptions of the users prior experience, where as self documenting makes no assumptions.

Language Idioms, Yearnings For A Simpler Time

April 12th, 2016
As the php language grows and evolves, I wonder if it's losing itself in an attempt to be "good". The language over the years has grown wide spread criticism for bad programming and enabling bad programmers. Some of these bad programmers have drastically changed their lives, enabling them to have opportunities they would have never imagined. In an effort to seek acceptance, the php community and language have gone through many changes. But at what cost are all of these changes?

Extending Laravel's Blade

January 19th, 2016
Creating simple 1 parameter extensions in laravel is plainly laid out in the documentation. Taking it a step further can be a little more tricky. But this doesn't need to be true.

From Spaghetti To MVC

June 5th, 2015
A step by step example based explanation of transitioning a web page into an MVC based application.

Protecting Actionable Links from CSRF Attacks

February 9th, 2015
For a long time, I didn't protect my actionable links from CSRF attacks. By actionable links, I mean links that will modify data on the server, e.g. "delete product", "publish post", "like". I'd always written these as regular "a href" links, but this can be a very easy to manipulate attack.

So Long WordPress

February 6th, 2015
This blog has been powered by WordPress for somewhere close to 5 years. However, as of this morning, it is powered by my own blogging platform, OpenPub. This was something that I had been meaning to do for awhile, but never had the time. WordPress is a monster of a legacy codebase. I found that as I wanted to add new features, I was forced to rely on third party plugins or digging into the inner workings of WordPress.