March 29, 2017

Software Development Testing

Too often best practices for testing are an after-thought, or a non-thought with respect to the development and deployment of code. This generally results in shortcuts or bandaids being applied to the SDLC of an organization which can build up over time and become a major constraint on the future product evolution. With respect to a PHP driven application, my preference is PHPUnit. So briefly a friendly reminder to distinguish your tests by categorization, without opening up a can-of-worms on how to classify a test; we can do that later. The simplest and easiest ways to get started with this is to organize your tests within PHPUnit, so you can run…

September 19, 2016

Building a Unit Test in Symfony 3 using JWT Token Authentication

When you’re working with JWT Token Authentication and you want to be a well behaved software developer and build out your Unit Tests (in this case we’re using phpunit), it can be somewhat challenging to tackle out of the box. My solution here uses an inherited “service” that generates the token that can be used in any subsequent requests:

In the interest of adhering to the DRY principle, this class exists specifically for the purpose of being called in every unit test as a means of authorizing each request (see below).

You may want to expand upon this to do some additional authorization or validation on the $token response, but…

August 12, 2016

Simulating a POST with DateTimeType to a Symfony3 Api with Forms and avoiding `Invalid value for this field`

When building an Api using Symfony3, you’ll be smart to process all input through Forms, and my strong recommendation is to do so via unique form classes for each Entity. However, when doing so with custom datetime fields, you’ll need to explicitly specify a format so you don’t waste countless hours debugging what you are certain is a proper DateTime! Using phpunit to validate a simple node creation, the entire request-to-response flow is as follows: Api Request Controller Form Validation ORM (Doctrine) Response This simple Unit Test is simulating a form submission with a body and post_date field populated for a simple Node entity. If we were creating this in a Controller or elsewhere,…