#vue.js #javascript

Using registered event listeners as conditionals in Vue

Today I was writing a form component that needed an optional back button. Since the form component is generic, the back button could point to anything.

Read more


#php #phpunit #testing / www.sitepoint.com

Is snapshot testing viable in PHP?

Christopher Pitt wrote a pretty comprehensive article on one of our latest packages, which is one of my favorite packages I’ve written at Spatie to date, phpunit-snapshot-assertions.

Ah-ha moments are beautiful and rare in programming. Every so often, we’re fortunate enough to discover some trick or facet of a system that forever changes how we think of it. For me, that’s what snapshot testing is.

Read the full article on SitePoint, or check out phpunit-snapshot-assertions on GitHub.


#programming / twitter.com

Fragmentation is fabulous

In a recent Twitter thread, Sebastian McKenzie (Yarn and Babel author) shared his thoughts on the current state of open source. This tweet stood out for me (and he later ironically dubbed it his “most thoughtleader tweet ever”):

Revel in fragmentation and duplication because without it there’s stagnation and it stifles innovation.

When someone shares their latest pet project library, it’s often met with responses like “What a waste of time, you can already do this with library X!”.

There’s no need for justification here. Maybe the author wants something that fully matches their use case instead of the 80% that library X does, maybe they want a different internal architecture. Maybe they have bigger future plans in mind, or most importantly, maybe they just want to experiment, learn, and have fun.

Read the entire thread on @sebmck’s Twitter.


#vue.js

Exposing multiple Vue components as a plugin

Quick Vue tip for package authors! If you publish a package that exposes multiple Vue components, you can write a small plugin to install them all at once.

Read more


#typescript #laravel

TypeScript with Laravel Mix

Since writing this post, TypeScript has become officially supported in Laravel Mix (version 0.12 and up). There’s still some informative stuff in here if you’re new to TypeScript, but use the official method if you’re on a newer version of Mix!

In a recent Spatie project we decided to give TypeScript a shot for the business critical part of a new application. TypeScript provides static analysis to reduce the chance of introducing bugs, to have self-documenting code, and to improve our tooling (autocompletion!)

Read more


#php

The list function & practical uses of array destructuring in PHP

PHP 7.1 introduced a new syntax for the list() function. I’ve never really seen too much list() calls in the wild, but it enables you to write some pretty neat stuff.

This post is a primer of list() and it’s PHP 7.1 short notation, and an overview of some use cases I’ve been applying them to.

Read more


#php #phpunit #testing

Automatically running PHPUnit with Watchman

A little bash script to run tests when a file has been changed.

Read more


#php #phpunit #testing

A package for snapshot testing in PHPUnit

The gist of snapshot testing is asserting that a set of data hasn’t changed compared to a previous version, which is a snapshot of the data, to prevent regressions. The difference between a classic and an is that you don’t write the expectation yourself when snapshot testing.

When a snapshot assertion happens for the first time, it creates a snapshot file with the actual output, and marks the test as incomplete. Every subsequent run will compare the output with the existing snapshot file to check for regressions.

Snapshot testing is most useful larger datasets that can change over time, like serializing an object for an XML export or a JSON API endpoint.

Read more


#laravel #php #seo

Non-breaking, SEO friendly urls in Laravel

When admins create or update a news item—or any other entity—in our homegrown CMS, a url slug is generated based on it’s title. The downside here is that when the title changes, the old url would break. If we wouldn’t regenerate the url on updates, edited titles would still have an old slug in the url, which isn’t an ideal situation either.

Our solution: add a unique identifier to the url that will never change, while keeping the slug intact. This creates links that are both readable and unbreakable.

Read more


#vue.js #javascript

Dealing with templates in Vue.js 2.0

Vue 2.0 introduced it’s own virtual DOM implementation. At first sight, this doesn’t seem to have a large effect on the way you write templates.

Read more