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

Remi Collet:
Microsoft SQL Server from PHP
Sep 23, 2016 @ 11:57:34

In this recent post to his site Remi Collet shows you how to set up your PHP installation to allow it to work with a Microsoft SQL Server as it's data store.

Here is a small comparison of the various solutions to use a [Microsoft SQL Server](https://en.wikipedia.org/wiki/Microsoft_SQL_Server) database from PHP, on Linux. All the tests have be run on Fedora 23 but should work on RHEL or CentOS version 7.

Several different extensions were tested as a part of making the connection to the SQL server:

  • Using PDO, ODBC and FreeTDS
  • Using PDO, mssql and FreeTDS
  • Using PDO, ODBC and Microsoft® ODBC Driver
  • Using the Microsoft® Driver
  • Using PDO and the Microsoft® Driver

Each item comes with a list of the requirements involved (other modules/extensions), examples of the configuration changes you'll need to make and some sample code to create the connection.

tagged: tutorial microsoft sql sqlserver database connection example testing

Link: http://blog.remirepo.net/post/2016/09/20/Microsoft-SQL-Server-from-PHP

Pascal MARTIN:
Series - Introduction to PHP 7.1 (Update)
Sep 15, 2016 @ 09:42:57

Pascal Martin has made the tenth post in his series covering PHP 7.1 and how it differs from previous versions. While this series was previously mentioned there have been significant updates to the series warranting a new post.

Here is the full list of the current ten articles he's written up so far:

There's lots of good information about this upcoming minor release in each of these articles as well as an interesting view into the release process for a new PHP version.

tagged: types enhancements testing overview preview articles series php71 update

Link: https://blog.pascal-martin.fr/post/php71-en-introduction-and-release-cycle.html

Jani Hartikainen:
How many tests is too many?
Sep 13, 2016 @ 09:21:21

While not specific to PHP Jani Hartikainen asks an interesting question in his latest post - how many tests are too many?. He gives an example of the number of tests in a widely used open source project and how, sometimes, more tests doesn't mean better code.

Some time ago I stumbled upon some crazy stuff… Specifically, I found out that SQLite has 787 times more tests than they have actual code! It’s no joke, it’s documented right on their website. While they have about 116 300 lines of source code, they have 91 577 300 lines of test code.

That sounds completely insane. [...] I bet you’ve sometimes wondered what is the right amount of tests to write. In some cases, it’s easy to end up with more tests than code. [...] When thinking of how many tests is enough, we need to think of what the goals are – both for the tests and our actual project.

He focuses in on this last idea, talking more about the SQLite project and its test suite. He then helps answer the main question - how do you know how many tests are enough? Should you "bend over backwards" to make tests for every possible scenario just because you can? He suggests a few things that can help the situation including refactoring where testing is difficult and writing regression tests for bugs fixed.

tagged: testing code opinion toomany unittest sqlite project

Link: http://codeutopia.net/blog/2016/09/10/how-many-tests-is-too-many/

Pascal MARTIN:
Series - Introduction to PHP 7.1
Sep 08, 2016 @ 10:51:15

Pascal MARTIN has been in the process of posting a series of articles to his site covering the upcoming PHP 7.1 release including coverage of both new and deprecated features. So far there's four articles post with the latest coming out today:

A new minor version of PHP is just around the corner: PHP 7.1! Its release date is not really set yet, as it depends on the amount of bugs that will be reported and fixed on Releases Candidates, but it should happen before the end of this year. One year after PHP 7.0, this first minor release will bring its fair share of new enhancements!

Let’s take a look at those, going with about ten posts spread over the next few days.

So far he's covered:

Keep an eye on his site in the upcoming days for more pots in this series, helping you to prepare for the 7.1 release before it happens.

tagged: php71 series articles preview overview testing enhancements types

Link: https://blog.pascal-martin.fr/post/php71-en-introduction-and-release-cycle.html

Zend Developer Zone:
Testing your project with PHP 7.1
Aug 23, 2016 @ 12:20:12

On the Zend Developer Zone author Cal Evans has written up a post showing you how to test your application with PHP 7.1, the upcoming minor release version for the PHP 7.x series.

Both PHP 7.0 and the upcoming PHP 7.1 release are fairly benign releases. They do not break backwards compatibility except in a few edge cases. If you’ve not yet moved to PHP 7.0, check out our posts tagged php7 for details on what might trip you up there.

Regardless of what version you are moving to, 7.0 or 7.1, you are going to want to test your application before you make the move in production. Sometimes that is difficult though you need a server properly configured, you need someone to manage it, most importantly, you need unit tests. While I can’t help you with that last one – other than point you to @grmpyprogrammer who will publicly abuse you until you write them – I can help you with the “where to test” problem.

Cal shows how to make use of Docker containers to easily test your application in a more self-contained environment and make it simpler to swap out the PHP versions in your platform. He walks you through the steps you'll need to follow to get the environment set up, pull down required components, install and compile PHP and, finally, install Composer globally. Once set up, he shows how to log in, clone your project and execute its test suite. He finishes the post with a few comments about this being a "sandbox", not a CI environment and how it is "future proof" for later versions of PHP too (as it doesn't lock it down to just PHP 7.1.x).

tagged: testing project php71 docker container tutorial

Link: https://devzone.zend.com/7262/testing-project-php-7-1/

Laravel News:
Laravel Scout is now open for developer testing
Aug 16, 2016 @ 10:37:38

The Laravel News site has a new post with an update for those looking forward to trying out Laravel "Scout", the search handling to be released along side the next Laravel framework release. The post announces that Laravel Scout is now open for developer testing directly from the live repository.

Laravel Scout is a driver based full-text search for Eloquent that is going to be available when Laravel 5.3 launches.

The driver is not officially released yet, however, the repository is now live and available for those that want to play with more engines. Taylor said he would be working on docs this week in anticipation of the official 5.3 release and this first release should only be used in testing until it’s officially launched.

If you're interested in more details about Scout, check out this post from Matt Stauffer with details and code examples.

tagged: laravel scout developer testing search functionality

Link: https://laravel-news.com/2016/08/laravel-scout-is-now-open-for-developer-testing/

Testing Your Drupal Site with Behat
Aug 11, 2016 @ 11:32:45

On the php[architect] site there's a new tutorial posted from Oscar Merida about testing Drupal sites with Behat, a popular PHP-based "Behavior Driven Development" testing tool to help ensure your application is performing correctly from the outside.

If automated testing is not already part of your development workflow, then it’s time to get started. Testing helps reduce uncertainty by ensuring that new features you add to your application do not break older features. Having confidence that your not breaking existing functionality reduces time spent hunting bugs or getting reports from clients by catching them earlier.

Unfortunately, testing still does not get the time and attention it needs when you’re under pressure to make a deadline or release a feature your clients have been asking for. [...] After reading all the theory, I only recently took the plunge myself. In this post, I’ll show you how to use Behat to test that your Drupal site is working properly.

He starts by listing some of the requirements you'll need to get started (packages installed via Composer) including the installation of a Drupal specific plugin to make testing these sites easier. From there he shows how to configure the Behat tool and write a simple feature to test the visiting of a certain page and looking for matching results. He also includes tips about testing with user authentication, using custom contexts and Selenium integration.

tagged: behat testing bdd tool tutorial drupal application introduction

Link: https://www.phparch.com/2016/08/testing-your-drupal-site-with-behat/

Steve Azzopardi:
Setting up GrumPHP with Laravel
Aug 02, 2016 @ 12:17:11

On his Medium blog Steve Azzopardi has a tutorial showing you how to install and use the GrumPHP tool to evaluate the quality of the code in your Laravel-based codebase.

First of lets go through what is GrumPHP and how it can help in our workflow to make pull requests less “Code Check Styles” and more proper architecture review. There are specifically built tools for code style checks such as nitpick or styleCI, but even tools like these will only help you after you push your code to GitHub. GrumPHP will do all the style checks and other tasks, such as run PHPunit before you do a commit.

He expects a few prerequisites to already be installed but they're pretty minimal (basically Composer and Git). He then makes a brand new Laravel application and (optionally) sets up a development environment in a Vagrant VM. Next he pulls in GrumPHP and executes it, showing the happy green "grump" as there's no code defined to test. Next he adds in PSR-2 format testing with PHP_CodeSniffer and shows the unhappy red "grump" that results from bad code. He then adds in PHPUnit testing and adds in a gulp task to load other required resources.

tagged: grumphp testing laravel tutorial installation configuration

Link: https://medium.com/@steveazz/setting-up-grumphp-with-laravel-202f158e9862#.id38p25bs

SitePoint PHP Blog:
Hassle-Free Filesystem Operations during Testing? Yes Please!
Jul 28, 2016 @ 12:24:56

On the SitePoint PHP blog there's a new tutorial posted suggesting a method for hassle-free filesystem operations during testing in your applications. Traditionally external sources, including the file system have proved difficult to test mostly because connection/state issues or conflicts.

When working with the filesystem in our tests suites, a big concern is cleaning up the temporary files after each test runs. However, if for any reason the test’s execution is interrupted before the cleanup phase, further tests might fail, as the environment has not been cleaned up.

In this post, we will use a library named vfsStream to create filesystem mocks. It’s little more than a wrapper around a virtual filesystem, which also works very nicely with PHPUnit.

They start by creating a simple FileCreator class that just uses a file_put_contents call to write data to a provided path. They start with the traditional approach in testing - just writing to the actual file and ensuring it exists. Then comes vfsStream, changing up the testing to use mocks of the directory and file and it's own checks to ensure existence. These mocks work in basically the same way as a directory/filesystem structure would without the external interaction making it much easier to test in isolation.

tagged: filesystem testing phpunit unittest vfsstream package tutorial

Link: https://www.sitepoint.com/hassle-free-filesystem-operations-during-testing/

SitePoint PHP Blog:
Testing Your Tests? Who Watches the Watchmen?
Jul 21, 2016 @ 12:10:48

In a tutorial posted to the SitePoint PHP blog Claudio Ribeiro tries to answer the question of "who watches the watchmen" (your application's tests) to ensure they're functioning as expected and are correct. In this new tutorial he introduces the Humbug mutation testing tool and how it can be used to verify your own tests.

Regardless of whether you’re working for a big corporation, a startup, or just for yourself, unit testing is not only helpful, but often indispensable. We use unit tests to test our code, but what happens if our tests are wrong or incomplete? What can we use to test our tests? Who watches the watchmen?

[...] Mutation Testing ( or Mutant Analysis ) is a technique used to create and evaluate the quality of software tests. It consists of modifying the tests in very small ways. Each modified version is called a mutant and tests detect and reject mutants by causing the behavior of the original version to differ from the mutant. Mutations are bugs in our original code and analysis checks if our tests detect those bugs. In a nutshell, if a test still works after it’s mutated, it’s not a good test.

He starts by helping you get it installed (a quick composer require) and creating a simple "calculator" test to show it in use. He then creates the test for the class with some simple testing methods for the basic calculator functionality. He then configures the Humbug installation (via a JSON config file) and executes it on the current tests, sharing the resulting output. He goes through the results showing how to interpret them and points out places where the tests could be improved.

tagged: testing unittest humbug mutation variation example tutorial output

Link: https://www.sitepoint.com/testing-your-tests-who-watches-the-watchmen/