Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Freek Van der Herten:
A tool to automatically rerun PHPUnit tests when source code changes
Aug 04, 2017 @ 15:12:37

In this post to his site Freek Van der Herten shares information about a tool that can help to streamline your development workflow. The phpunit-watcher tool mimics tools from other languages to watch for changes in the source of your application and automatically execute your PHPUnit tests when modifications are made.

In the JavaScript world Jest, built by Facebook, is an excellent tool to run tests. Not only can it automatically rerun your tests when source code changes, but there’s also an interactive mode where you can set a filter on which tests to run while the tool is running. Would it be great if we could have these awesome features while working with PHPUnit?

Our newly released phpunit-watcher tool provides a Jest like experience. You can simply install it by running composer global require spatie/phpunit-watcher.

Once the tool is installed it can then be run from the command line, sitting and waiting for changes to the target files and directory. It's configurable in case you don't follow some of the usual package directory structures and can be filtered to only run on certain filename matches. This can also be done manually (real-time) via the tool. Screenshots are included showing the tool in action too.

tagged: phpunit watcher automatically execute unittest package

Link: https://murze.be/2017/08/tool-automatically-rerun-phpunit-tests-source-code-changes/

SitePoint PHP Blog:
How to Write JavaScript-Style Test Watchers in PHP
Jul 20, 2017 @ 18:18:43

On the SitePoint PHP blog there's a new tutorial that talks about creating "watchers" in your PHP code similar to the ones that the Javascript world has used to detect changes in files and automatically perform actions.

In the land of JavaScript, it’s not uncommon to preprocess source code. In the land of JavaScript, developers write in syntax not widely supported, and the code is transformed into syntax that is widely supported, usually using a tool called Babel.

In order to reduce the burden of invoking the transformation scripts, boilerplate projects have started to include scripts to automatically watch for file changes; and thereafter invoke these scripts.

These projects I’ve worked on have used a similar approach to re-run unit tests. When I change the JavaScript files, these files are transformed and the unit tests are re-run. This way, I can immediately see if I’ve broken anything.

The author (Christopher Pitt) then shows how to create the project and make use of pre-processing and some sample scripts to run tests against. He shows how to set up the test configuration and provides an example test. Finally he includes a script that's used by the "watcher" to recompile the scripts before the tests are executed. To to the watching, he uses the yosymfony/resource-watcher package and a long running PHP script ("watch-test").

tagged: watcher javascript tutorial unittest phpunit resourcewatcher

Link: https://www.sitepoint.com/write-javascript-style-test-watchers-php/

SitePoint PHP Blog:
PHP, Arduino And… Minecraft? Combining Minecraft with PHP!
Jul 07, 2016 @ 18:35:15

On the SitePoint PHP blog author Christopher Pitt has a new tutorial posted about combining PHP, Arduino and Minecraft and combine the physical and software worlds in an interesting IoT combination.

Some of the most interesting programming I’ve done has been in Minecraft. It’s an open-world, sandbox game developed by Mojang, (recently acquired by Microsoft). Minecraft began as a canvas for creative expression, and while I do very different things in it these days, it still is that for me.

I’m going to take you on a journey, as we build a Minecraft mansion, and then secure it with a real-world alarm system. There’s quite a bit of ground to cover, and though I plan for this to be a two-part series, I’m going to have to leave some of the tangential details for you to discover!

For those not familiar with "programming" in Minecraft (not the backend language, but using things like redstone) he gives a brief introduction. He then sets up the situation - the creation of a "sprawling mansion" in your Minecraft world and a need to secure the front door. He includes the command to set up the "door open" test on a command block. He then shows how to hook this into a loop to continuously test if a door is open or not. With this open/closed door check system in place he then brings PHP into the mix, having it check log files for the "whispers" when the door actions happen. He then creates a watcher for these events and has it respond with a chat message back to the user. That's all in this tutorial but a future part of the series will add on the physical aspect - the Arduino.

tagged: tutorial physical arduino minecraft notification watcher series part1

Link: https://www.sitepoint.com/php-arduino-and-minecraft-combining-minecraft-with-php/

PHP-Tip-a-Day:
PHP Tutorial: King Floyd and the Seventeen Princes - A Tale of the Observer Pattern
Jun 22, 2012 @ 14:20:39

On the PHP-Tip-a-Day site today there's an new "fable" posted in the Design Pattern Fables series. This time it's about the Observer pattern (and kings and princes).

The first place I recall encountering the observer pattern was not in PHP, but in JavaScript. If you've ever set a listener to fire when an event happened, you've used the observer pattern. Functions or methods are registered with an object so that when it experiences a specific event, it "notifies" the registered functions or methods by calling them.

His story tells about a royal family, a pregnancy and magic mirrors that allows for instant communication between the family and outlying locations. He relates it to the objects and "watchers" that make up the Observer pattern and gives a brief code example (in Javascript) of a HTML button and a jQuery event observer that fires when it's clicked.

tagged: designpattern fable story observer event watcher

Link:


Trending Topics: