Thoughts on Unit Testing

I’ve never been someone who understood the value of unit testing. During my programming studies, when I learned new languages like PHP or JavaScript, unit testing was never a topic that came up. The byproduct of a non university, tertiary education I guess?

The first time I discovered unit tests was when I was working with a Python developer in the late 2000s. I can’t remember how it came about, but it was through him that I learned about the concept, how you write the tests first and then write the code to pass the tests. I still didn’t understand the value, so I did some cursory research but generally moved on.

Over the course of the next few years I often saw articles or discussions on unit testing, but the idea of unit testing my code was not something that was a part of any developer position I’ve held in the last 15 years, so I never learned how to, or why I should, write unit tests.

In 2015, when I started developing for WordPress, unit testing came up again, as I looked into contributing to WordPress core. In my search to ramp up my WordPress development knowledge I discovered Know the Code, and one of Tonya’s courses was about unit tests. At around the same time I started using Laravel, which meant eventually finding Laracasts, which also included a course on Unit Testing. Through these places I eventually discovered Grumpy Learning by Chris Hartjes, who has 3 books dedicated to unit testing PHP code.

I’ve since come to appreciate the value and need for unit tests and have committed myself to writing unit tests for all new functionality I code from 2019 onward. At first it was daunting, but today something finally clicked.

It started with a new feature. I needed to verify the extension of a media file path, ignore any query strings that might be appended to that path, and return the correct base name to the actual file. Contrary to my unit testing resolution, I wrote the actual code first, but realised that when it came time to test it, I’d need to do a whole bunch of other work to deploy the code and test it manually, the old fashioned way. I realised this was a great chance to write some unit tests.

During the writing of some simple assertEquals() assertions, I soon realised that my initial understanding of the problem was flawed. By writing a few additional tests for cases I had not originally thought of, I could more thoroughly test my solution and improve it to handle these new situations.

In a round about way, I ended up eventually writing the correct unit tests I should have written in the first place, rewriting my code from scratch to solve these tests, and ending up with a much better overall solution.

The tests themselves and the code solution was trivial. What was important was the realisation that, had I started writing the tests first, my mind would have provided additional cases I might not have thought of. I would therefore be preparing myself to not only come up with a better solution, but with a much faster way to test and confirm it.

Through all this I’m getting a good grasp of which types of problems lend themselves to unit testing and which do not. I also realise that if I’m going to write more unit tests I need to allow myself more time up front to plan and execute proper unit testing. I’m still learning, so things like mocks and stubs are still far off concepts I’m aware of but will need to master. I am however excited to see how this improves as I practice, and how it improves my development output as a whole.

The Clear View – Get the MOST from your freelance developer

A-Clear-View

Have a clear understanding of your project requirements to ensure you get the most out of your freelance developer

The purpose of this post is to ensure that you know precisely what you need to do in order to get the most out of the freelance developer you’re about to hire. You need a complete understanding of what you want to achieve before even looking at the Freelance for Hire pages. Seriously. Otherwise you will waste time and money and nobody has an endless supply of either.

Here’s a great example…

You are an expert teddy bear maker. You love them. You know that your particular brand of bear is exceptional and you want to build a business out of them. You contact a developer and you say, “I want to sell teddy bears online.”

While an admirable plan, this is too vague and will require a lot of work to fine tune into a final requirements list. Instead, look at developing a breakdown of your requirements that outline every aspect of your business, your needs, your requirements and your customer deliverables.

Something like this…

–          I would like to build an eCommerce store that can help me to sell my teddy bears

–          The store needs to support a product gallery that can showcase each bear

–          The store needs to support a short product description for each bear along with a list of specifications such as fur used, type of eyes etc.

–          I would like to accept credit card payments along with EFT and possibly Snapscan or another app payment platform

–          I would like the payment gateway to support both international and local credit cards

–          I need to add shipping to the order after it has been placed as these will differ depending on the product purchased and the location of the customer

–          I would like web hosting options

–          I have a domain and email accounts that are linked to that domain, and I think the domain and emails are managed by my internet service provider

–          I would like my store to be built with WordPress and WooCommerce

This level of detail really helps both you and your freelance developer to assess the job and what will need to be implemented to make it work. And what underlying technologies will need to be used. We will be exploring the process of clarifying these requirements in greater detail in a later post/chapter as they will help you with pre-hire and with how to harness the help of a freelancer in the scoping and investigative phase.

The detail

Have you ever tried to explain a complex concept to a child? As the parent of two very inquisitive young boys I have learned a lot about how to take something complex and breaking it down into pieces that their brains can understand.  To achieve this, you need a solid understanding of the concept yourself. There’s little point in explaining the concept of why the wind blows unless you understand high and low air pressures (I was a geography nerd at school).

The same theory applies to your product or service. Understand your product and its requirements intricately before you move into a relationship with a freelance developer. You can’t brief something unless you know it really well. This also ensures you have a clear vision and will inform all your engagements with your freelancer.

Another bonus is that it will also refine your vision and you will potentially identify any loopholes or issues before it is too late.

CASE STUDY: The successful client/freelance relationship

Craig from Seriously Simple Podcasting

–          He understands the concept of podcasting really well

–          He was able to define the value of Seriously Simple Podcasting and how its add-on services delivered value to customers

–          Already had a viable customer base

–          Understands what his clients want

–          Has completed some programming tutorials and has some understanding around the basics of web development and the concepts that define it

–          Works with his freelance developer to define scope, determine project goals and discuss possible solutions to any problems that arise

CASE STUDY: The flexible partner

Melinda from Agency Of Creativity*

–          She is a designer and owns her own agency

–          She uses a popular page builder plugin to build her client’s websites

–          Each client has a common requirement that she has to build from scratch each time and she realises that this could be developed as a plug-in

–          She isn’t clear on the underlying technologies required to make this a reality but she is happy to hire a coding expert who can work with her to achieve her goals

–          She provides clear and concise instructions

–          She knows exactly what her clients need and is the ideal person to test what is built along the way to ensure it meets specifications

CASE STUDY: The client that can’t

Dawid from Services R Us*

–          He has a vague idea of the service listing he would like to provide but isn’t sure about implementation

–          Assumes that the process is as simple as ‘just add this field to this page, it should be quick’

–          Rambles on about different ideas that pop into his head without actually getting to the point

–          Doesn’t send a clear briefing email but rather wanders with his thought processes

–          Can’t provide a detailed list of requirements but expects a clear and fixed cost/time estimate

–          Constantly contacts the developer, asking them to fix other technical issues that are unrelated to the project. He expects freelance support for free just because of the project

The first two projects are a development success. The last is a time and energy vortex that leaves both client and freelance developer gasping. The best way for your project and your vision to succeed is to have a clear vision and to be open to the reality of what is required.

*Names changed

Monitor MySQL command line imports and exports on Ubuntu using Pipe Viewer

If you’ve been working with PHP/MySQL based websites for any amount of time, you’ve probably heard about the MySQL command line tools for importing and exporting your database.

The syntax is quite simple, for exports you run

mysqldump -udbuser -p dbname > dbfile.sql

which exports the database to a file on the local machine. For imports you run

mysql -udbuser -p dbname < dbfile.sql

which imports the contents of the local file (dbfile.sql) into the empty database.

This is usually the quickest way to export a database from one location to import it into another.

One problem I’ve experienced from time to time is exporting and importing large databases. By default the tools don’t output any progress indicator (or anything at all really), and using the -v (verbose) switch outputs every single MySQL command being run from the import file, which is like watching the code in the Matrix.

via GIPHY

Fortunately, there is a way you can run imports and exports and show a progress bar, with Pipe Viewer.

Pipe Viewer is a terminal-based tool for monitoring the progress of data through a pipeline. The Pipe Viewer homepage has all the install commands for the various operating systems, and Ubuntu has an official package for it, so you can install it through apt.

sudo apt-get install pv

Once pipe viewer is installed, you merely need to make two small changes to you import and export commands.

pv dbfile.sql | mysql -udbuser -p dbname
mysqldump -udbuser -p dbname | pv -W > dbfile.sql

And viola! You will be presented with a progress monitor that shows file size imported, time taken, percentage progress. Much better than staring at a blank screen.

Setting up Trusted SSL Certificates for Local Development, Using mkcert on Ubuntu 18.04 with Apache.

Computer Surgery

One of the many little annoyances that I encounter while working on client sites, is when the client has a valid SSL certificate installed on their server, but the HTTPS redirection happens in code instead of at the server level.

This means that even if I export the database with the site urls replaced to match my local environment, or run a search or replace on the local database, the code execution will still try to redirect to the secure version of the domain, meaning I have to first find out where that redirection is taking place, and remove it.

Often it’s done inside the site config, which is pretty quick to comment out, but other times it’s done via a plugin which is harder to find. In the long run it would be infinitely quicker and easier to just have a trusted SSL certifcate installed for the local site. My previous attempts at this meant installing a self signed certificate, but this means it’s not ‘trusted’ by the browser, and you either have to configure your browser to trust the certificate, or get an annoying warning about the site’s certificate not being trusted or secure enough every time you browse to the local site.

Thankfully, after asking around, I was pointed to mkcert “a simple zero-config tool to make locally trusted development certificates with any names you’d like.” It creates a local certificate authority, installs the authority into your local and browser trust stores. It also includes a tool to make local, trusted certificates for any local domain name. All that I have to do is set those certificates up for each local domain.

Installing mkcert is pretty straightforward and the project readme contains instructions for the various operating systems.

Regular Apache Virtual Hosts for local development

Because I use Ubuntu as my OS and Apache as my local webserver, whenever I add a new client site, it’s usually a 4 step process:

I start by creating a new Apache VirtualHost config file, copied from an existing one, and change some site related values

cd /etc/apache2/sites-available/
sudo cp 000-default.conf localsite.conf
sudo nano localsite.conf

The values I change are ServerName, ServerAdmin, DocumentRoot and Directory values. I usually also set site specific log files

<VirtualHost *:80>
        ServerName localsite.test
        ServerAdmin webmaster@localsite.test
        DocumentRoot /home/jonathan/development/websites/localsite
        <Directory "/home/jonathan/development/websites/localsite">
            #Require local
            Order allow,deny
            Allow from all
            AllowOverride all
            # New directive needed in Apache 2.4.3: 
            Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/localsite-error.log
        CustomLog ${APACHE_LOG_DIR}/localsite-access.log combined
</VirtualHost>

Once the config is saved, I enable the new site, and restart Apache

sudo a2ensite localsite.conf
sudo service apache2 restart

The last step is to let my local machine know what IP address to resolve the VirtualHost ServerName value to, in this case localsite.test

sudo nano /etc/hosts
127.0.0.1   localsite.test

Once this is all done, I can browse to http://localhost.test and it will serve the files in the /home/jonathan/development/websites/localsite directory.

Note, if you get a ‘permission denied error’ doing this, the quick way to fix this is to change the user and group that Apache runs as, to your local user.

sudo nano /etc/apache2/apache2.conf
# These need to be set in /etc/apache2/envvars
#User ${APACHE_RUN_USER}
#Group ${APACHE_RUN_GROUP}
User jonathan
Group jonathan

Save that file, restart Apache, and you’ll be good to go.

Adding a SSL layer to a local site

I wasnt sure if the set up of a local, trusted certificate would be any different, and I was pleased to find out this was indeed the case.

Creating the new local Certificate Authority

Once mkcert is installed, the first thing I needed was to create and install the new local certificate authority. Fortunately this only needs to be done once.

mkcert -install

Once you’ve installed the CA, you can issue site certificates against it. I like to place all my site certificates on one place like ssl-certs

mkdir ssl-certs
cd ssl-certs

Then it’s time to create the certificates.

mkcert localsite.test

This creates a localsite.test.pem certificate and a localsite.test-key.pem key, which is used in the Apache SSL config for the site.

Side note, I’ve started using .test for my local domains, because Chrome doesn’t seem to like my use of .local domains until I tell it to. Earlier this year I discovered this is because it’s reserved for link-local host names that can be resolved via the Multicast DNS name resolution protocol. So I switched to .test. Thanks to Andrey Savchenko for pointing this out to me.

Setting up the certs for a local site

First step was to enable the SSL module for Apache. This also needs to only be done once.

sudo a2enmod ssl

Next, I needed to create an SSL version of the local site virtual host config. I started by copying the existing default-ssl.conf and making my changes

cd /etc/apache2/sites-available/
sudo cp default-ssl.conf localsite-ssl.conf
sudo nano localsite-ssl.conf

It’s actually pretty similar to a standard VirtualHost config, except for the checking if the SSL module is installed, the VirtualHost domain and port, and stuff from SSLEngine down. As you can see the certificate and key are specified in the SSLCertificateFile and SSLCertificateKeyFile entries respectively

<IfModule mod_ssl.c>
	<VirtualHost _default_:443>
		ServerAdmin webmaster@localsite.test

		DocumentRoot /home/jonathan/development/websites/localsite

		<Directory "/home/jonathan/development/websites/localsite">
            #Require local
            Order allow,deny
            Allow from all
            AllowOverride all
            # New directive needed in Apache 2.4.3: 
            Require all granted
        </Directory>

		ErrorLog ${APACHE_LOG_DIR}/localsite-error.log
		CustomLog ${APACHE_LOG_DIR}/localsite-access.log combined

		SSLEngine on

		SSLCertificateFile	/home/jonathan/ssl-certs/iwezimoto.test.pem
		SSLCertificateKeyFile /home/jonathan/ssl-certs/iwezimoto.test-key.pem

		<FilesMatch "\.(cgi|shtml|phtml|php)$">
				SSLOptions +StdEnvVars
		</FilesMatch>
		<Directory /usr/lib/cgi-bin>
				SSLOptions +StdEnvVars
		</Directory>

	</VirtualHost>
</IfModule>

Once the SSL config is created, I enable it.

sudo a2ensite localsite-ssl.conf

I can then restart Apache, and the SSL secured version of the local site is enabled.

This is something I’ve wanted to get set up for the longest time, so a massive thanks to Filippo Valsorda for creating mkcert.

11 steps to getting the most out of your freelance developers

Working with Freelance Developers

A handy guide for clients working with freelance developers so nobody gets hurt…

Working with freelancers can be, for some, the equivalent of playing with a loaded gun. It can work out, but there are times when it can really affect your business and your life. As a client, you need a handy guide to working with freelance developers to ensure that every person working on the project comes out on top.

Step 01: A clear view

You need to understand your product and its requirements very intricately before you move into a relationship with a freelance developer. You can’t brief something in to someone until you know it really well. This also ensures you have a very clear vision of the final product and will inform all your engagements with your freelancer.

Step 02: Have a basic understanding

You will need some basic knowledge of web and development before you embark on this adventure. Yes, you are hiring a professional to take on your project so theoretically you shouldn’t need to know a thing. The fact is, if you have a modicum of understanding then you will have more realistic ideas around time frames, deliverables and project potential (and the magic Foo of your developer).

Step 03: Budget is everything

Don’t expect your freelance developer to be happy to cut their rates to suit your budget.The work they do is complex and specialised. Instead, be prepared to cut your requirements to fit your budget. That way you are assured of quality work from a reliable developer.

Step 04: Clarify your requirements

This is an extension of Step 01. Why? Because this is the most important step of all – it will cost you money and time if your requirements are vague so spend time on clarifying them. It’s worth it.

Step 05: Develop a clear timeframe

Work closely with your freelance developer to break the project down into achievable phases,each with their own milestones and deliverables. This will ensure that both you and your freelance development team are on the same page and working towards the same goals. This way nobody can say that they didn’t know that X had to be done by Y date…And this includes you providing your development team with the information and materials they need to achieve these goals.

Step 06: Create communication channels

From Slack to Asana to Evernote to Skype – there are plenty of communication and collaboration tools available to help you streamline communication with your freelance developers. Many of these offer timeline and deadline management tools as well, making it really easy for you to track timing and status.

Step 07: Don’t hover

The headline says it all. Science has shown that for every interruption, it takes a person at least 20 minutes to get their concentration back. Every time you interrupt,you slow your project down.

Step 08: Test

Every step, every aspect, every phase – test. Test assumptions, capabilities, developer promises and results. This will ensure that the final product has had most of the kinks ironed out iteratively rather than a messy tangle to unwrap at the end.

Step 09: Feedback

There is bad feedback, there is good feedback and there is great feedback. Learn how to do the last two types of feedback really well. Good feedback is defined as giving the person the information they need to make changes, fix problems, address issues and overcome obstacles with precision. Vague and wishy-washy comments like, ‘Yeah, it doesn’t feel right’ are not helpful. Nor are nasty and antagonistic ones. Nobody puts passion into a project for someone they don’t like.

Step 10: Everything is in writing

From the onset of your project to the phases and timelines to the final deliverables ensure that your project is clearly documented and that all parties have read and signed every document. You do not want to end up at the end of a messy conversation or project with someone saying that something was never clarified.Assume the best, prepare for the worst.

Step 11: Manage expectations

Your developer won’t always be around to leap to your requests or requirements. This is very normal and you may not be their only client. Be patient and trust that they will get back to you and respect your urgency.

Are you an experienced freelance, full stack developer, who loves building things for WordPress?

Codeable needs people like you!

Do you have a special relationship with the WordPress Codex, dream about coding standards and are able to build your own custom plugins from scratch? 

Do you work well with clients, have amazing communication skills and can solve the most difficult of WordPress customisation problems?

Want to be part of the best WordPress outsourcing platform in the world? Then Codeable wants you!

If you’ve followed this blog over the past few years you will know how joining Codeable changed my life. Well, now is the chance for you to experience the same life changing experience, by applying as a Codeable Expert developer.

Codeable is currently looking for expert WordPress full stack developers who love building elegant plugin or theme customisation solutions for clients around the world. If this is you, and you want to join the #1 outsourcing service for WordPress, then apply today.

P.S. I don’t get anything out of this, other than the satisfaction of maybe helping someone else become part of the Codeable family.

P.P.S if you don’t consider yourself a full stack (hardcore coder) developer and more of a WordPress developer (website builder) then you should also apply. I just happen to know that Codeable is looking for full stack developers at the moment.

Why I’m not building any new Divi plugins, or adding features to any existing ones.

If you’re reading this because you found me through the various Divi Facebook communities, you probably know that I am/used to be a Divi plugin developer. You may have already purchased one of my plugins and found this link on the Atlantic Wave home page.

When I first started in the WordPress space I built a few custom plugins for the Divi theme and sold them on Elegant Marketplace, the most recent (and probably most popular) one being Rebrand DE.

Rebrand DE was launched in June 2016, over two years ago. Since then I’ve not released any new Divi plugins and I’ve only released one free plugin on WordPress.org, roughly at the end of 2016. I’ve also not added any new major features to any of my existing plugins. So why no new plugins, or plugin features, in almost two years?

1. Money

The first mistake I made when releasing my plugins was not pricing them properly. Take a look at Rebrand DE, it sells for $18 once off, which is great for the consumer, but a bad business model for me as a developer, trying to support the plugins. I probably ended up making about $250 a month from Divi plugin sales, but spent at least 5 times as much on support queries, which meant a net loss for me. 

However the income I was (or wasn’t) receiving from the plugins wasn’t the major problem, the major problem was…

2. Time

Building a plugin empire is a game for those who have a lot of free time on their hands. In the first month I made $1500 on plugin sales, but each month after my sales dropped, until they reached the average of $250 a month income I mentioned earlier. At the same time I was supporting customers who purchased the plugin, as well as trying to fix bugs and add new features to the plugins. So I struggled to find time to market the plugins to new customers, or look at how I could do things like increase the price or implement new features.

Essentially the time I spent on the plugins was cannibalising what I made out of them, as well as my main source of income, custom client work. I had to start making excuses for why I wasnt able to fix bugs as quickly or ship new features. As a husband and father it also meant I was spending more of my time on supporting the plugins and less with my family.

I soon came to a realisation.

Having enough time to fix bugs or ship new features meant I would have to increase the cost of the plugins to accommodate. Because I was not clever enough to launch the plugins with things like yearly license/support renewals this meant upping the price dramatically for any new customers but still supporting the existing customers on the old prices. For whatever reason, this didn’t feel right. It was not fair to ‘punish’ new customers for my mistakes.

So, where does that leave us?

Before WordCamp Europe 2018 I decided that it was time to make a decision about the future of the plugins. I had a chat with the owner of Elegant Marketplace and we agreed that they would take over the bulk of support requests and would only contact me if major bugs occurred that needed fixing. I would take a much smaller cut of the profits, leaving me more time to focus on other things. It also meant that the plugins would be ‘feature frozen’ and any new (or planned) features would not be added going forward. 

“I want feature x in one of your plugins”.

If you are reading this because you clicked on a link from the Atlantic Wave site and you want a specific feature in one of my plugins, then you do have the option of hiring me to build it for you. If you choose this route I’m open to a ‘profit sharing’ option, if you’re willing to let me upgrade the plugin for the public domain (ie to be sold with the new feature on Elegant Marketplace) I’ll build the feature at a 50% discount on my development time.

Basically what it boils  down to is helping to cover the cost of my development time, should any new features be requested to be added to any of the plugins. That way you benefit, as you get the feature you want for half of what it would cost you actually build it, and I benefit from the profit share I make on the plugin sales over time.

I will still fix bugs.

I’m still committed to keeping the plugins up to date, so if you find a bug in any of my Divi plugins, please do email me, let me know and I’ll fix it as soon as possible. 

New focus in 2019.

Usually, towards the end of a year, I start looking back at the year that has been, and looking forward to the year ahead, planning my new goals and resolutions.

This year, however, I have one very specific goal in my head. It’s an idea that actually birthed itself way back in July of 2016, when I wrote a post about why I got into development and blogging about development, in the first place. 

2018 has been a year of personal goal achievement and so for 2019 I want to get back to sharing my (limited) knowledge and experience with others, to assist them in achieving their goals, both personally and professionally. So with that in mind I’d like to announce a few changes that will happen on this blog and my podcast, and a few other additions I’m making that will hopefully help support my efforts.

The Jonathan Bossenger Patreon

I have retooled and relaunched my Patreon page. The goal of this page is to give those of you who read my blog, listen to my podcast, or generally follow me online, the ability to help fund my work. I get a lot of folks asking questions in the comments area of my blog posts, and I’d like to be able to spend more time in helping them solve the problems they present. The Patreon is the perfect place to do this.

If you’d like to be able to get a little more out of me, from answering your questions to helping you solve your WordPress or web development problems, or you want me to write about specific experiences or topics, or even interview specific people on the podcast, the Patreon is the perfect way to have your voice heard. For a small monthly fee you can help me bring you the kind of content you are looking for.

The Jonathan Bossenger Mailing List

At the bottom of every blog post there is a ‘subscribe to my mailing list’ form. If I’m honest I’ve not really used my mailing list to it’s full effect. I intend to do so moving forward. I promise I won’t bombard you with rubbish, but I will select a few useful topics or articles, from either my blog or the web, that I think you will find useful, to send to you, no more than twice a month. 

I will also use this mailing lists to announce any new exciting things I am doing.

A new focus for the blog.

You may have noticed that I have been blogging a lot more the past few months. This is because I’ve recently started working with a copywriter, who is helping me get my content out there. While I will still use this blog to share my personal experiences, it is my hope that with the assistance of the copywriter I will produce more useful and relevant content to my readers.

WP HackerCast – Season 2

If you were a regular listener to the podcast, you will have noticed things went very quiet after episode 18. This was mostly due to not really having enough time to find guests and prepare podcasts. For 2019, and with the help of my Patreon, I hope to relaunch the podcast with more interesting guests and interviews.

So, if you like the sound of all this, and you want to be more involved in what’s happening here or on my podcast, then please consider becoming a Patron, subscribe to my newsletter, or visit and subscribe to the podcast.