SQLite In-Memory Database for Unit Tests in Laravel

Introduction

When testing your code (and this is particularly true for functional tests), even if you mock most of the database iteractions, at some point you need to hit the persistent layer of your application in order to ensure that everything works correctly. In these cases you obviously are not willing to make definitive changes to your development database each time you run a test.

Luckily for us Laravel 5 provides two useful methods to solve this problem:

  • Database Transactions …
Read More
How to test the File System using vfsStream

Introduction

Let’s face it! In some situations, no matter how hard you try to mock everything, you have to unit test the file system in order to ensure that your application works correctly.

Testing directly the file system is a pain in the ass due to the many possible things that can go wrong. Remember: unit tests must be performed in isolation, therefore we need to make sure that each test case doesn’t affect the outcome of the others.

The old-fashioned way to avoid possible …

Read More
Inspect the response in Laravel PHPUnit tests

The Problem

Sometimes, when running integration tests using Laravel and PHPUnit, it’s useful to inspect the response when you can’t figure out why the test is failing. In Laravel 5 and later versions, testing has been highly improved with an API that allows nice and fluent interaction with your application.

Inspect the Response Object

In Laravel, each Test extends the default abstract TestCase class defined in Illuminate\Foundation\Testing. This class uses the CrawlerTrait to …

Read More
Basic ProcessWire website workflow - Part One

Introduction

For those of you who don’t know what ProcessWire is (shame on you!), here the introduction statement of the official website:

“ProcessWire is a free PHP content management system and framework (open source CMS/CMF) built to save you time and work the way you do. ProcessWire provides simpler and stronger control over your pages, fields, templates and markup at any scale.”

ProcessWire Logo

In my opinion, …

Read More
First steps with GraphQL in Laravel Framework - Part One

Introduction

GraphQL1 is one of the recent major technologies introduced by Facebook in the React ecosystem. Essentially it is a declarative approach for querying data from a backend.

“React is changing the way we build complex client-side UI applications. Flux rethinks the flow of data through applications. GraphQL is changing the way we fetch our data from the server.”

In a nutshell, GraphQL is challenging REST. The key concept is that the client is the only component of an …

Read More
JavaScript Quiz Answers Explained

Introduction

JavaScript is notoriously a simple programming language, but let’s be honest: it sucks!

Don’t get me wrong! I love programming in JavaScript, it gives extraordinary freedom in building things that runs everywhere, but at the cost that is so easy to write bad code. The reason falls back to its winding history, starting from its creation in 10 days by Brendan Eich. Wikipedia has an exhaustive entry on the subject, so I suggest you to check it.

Nevertheless after 20 …

Read More