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

SitePoint PHP Blog:
Testing PHP Code with Atoum – an Alternative to PHPUnit
Oct 21, 2016 @ 11:52:28

The SitePoint PHP blog has a tutorial posted introducing you to a more recent addition to the testing tools available to PHP: atoum. The tutorial provides the basics and shows you how to use it in testing your code as an alternative to PHPUnit.

f you’ve been around PHP for more than a little while, you’ve no doubt started to test your code. And if you ask anyone in the PHP space what to use for writing unit tests, likely the first answer that they’ll give you is PHPUnit.

It’s the de facto standard in the PHP community, and with good reason. But it’s not the only choice. Whilst it does command the lion’s share, other choices abound, one of which I’m going to take you through in this tutorial; it’s called atoum.

They briefly introduce the tool (a "simple, modern, and intuitive unit testing framework for PHP") and help you get it installed. They also recommend installing the "atoum/stubs" package as well, making it easier to do autocomplete in most IDEs. From there the tutorial helps you configure your atoum installation to allow for code coverage reports to be generated. With things configured nicely, the next step is creating a first test evaluating a simple method that either works correctly or throws an exception. Code is included showing how to use the testing to set up expectations and evaluate the results of method execution. Finally they show the command to execute the test(s) and what the resulting code coverage reports look like.

tagged: testing unittest atoum introduction tutorial alternative

Link: https://www.sitepoint.com/testing-php-code-with-atoum-an-alternative-to-phpunit/

A better dd() for your TDD
Oct 13, 2016 @ 11:57:45

On the Tighten.co blog they have a recent post sharing a better dd() for your TDD - basically a better method for debugging the current state of object with a "dump and die" function.

An important part of every Laravel developer's debugging arsenal is the humble dd() helper function—"dump and die"—to output the contents of a variable and terminate execution of your code. In the browser, dd() results in a structured, easy-to-read tree, complete with little arrow buttons that can be clicked to expand or hide children of nested structures. In the terminal, however, it's a different story.

[...] Fortunately, it's simple to build your very own customized version of dd() to help tame your unwieldy terminal output—helping you find the details you're interested in quickly, without wearing out your trackpad (and your patience).

He provides two options you can use to help clean up the output of a "dump or die" method from the extensive results the current "dd" function provides:

Kint provides a few other helper methods you can use and easily configurable max and min depth to show in the output.

tagged: tdd testing vardumper kint library package output debugging

Link: https://blog.tighten.co/a-better-dd-for-your-tdd

QaFoo Blog:
Database Tests With PHPUnit
Oct 05, 2016 @ 11:57:36

The QaFoo blog has a new tutorial posted showing you how to work with PHPUnit and database testing for acceptance testing of your application. Acceptance testing (or integration testing) generally exercises the tests with live data from a database rather that stubbed or mocked data in true unit testing.

Most of us do not use PHPUnit solely for Unit Tests but we also write Integration or Acceptance Tests with PHPUnit. One very common question then is how to interact with the database correctly in those tests. Let me show you the different options and their trade offs...

There are multiple aspects of database tests where our decision has impact on test atomicity and test runtime. All decisions boil down to: More test atomicity leads to longer test runs, and we can buy test speed by omitting test atomicity.

They talk more about the time added for testing with database functionality included and where running them might be most appropriate (local vs on the CI server). The article then talks about one of the main decisions around doing a full data/schema reset or just removing data when the tests start or end. They then get into this last point - where the reset should happen, before or after the tests are executed. They talk in detail about each option, breaking it down into a few options: before each test, before each test class or before the whole test run. The post ends with a section talking about "mocking the database away", a method usually used in traditional unit testing but points out that this can be highly prone to errors, especially if you attempt to replace one database system with another (like replacing MySQL with SQLite).

tagged: testing acceptance database phpunit integration reset location mock

Link: https://qafoo.com/blog/090_database_tests_with_phpunit.html

Master Zend Framework:
How to Build a Docker Test Environment
Sep 28, 2016 @ 11:20:40

The Master Zend Framework site continues their series covering the creation of a Docker-based testing environment in this second part highlighting the addition of testing support.

In the first part in this series on developing web applications using Docker, we saw how to create a local development environment using Docker; one ideally suited to creating Zend Expressive (or any other kind of PHP-based web application). But, what we didn’t cover was how to handle testing in a Docker-based environment.

[...] How do you run tests when working with Docker containers? After a bit of searching, I found that it’s not that difficult. But you have to use the right combination of commands.

Since unit tests can be run locally if need be (they shouldn't need any resources from the service if they're true unit tests) he focuses on acceptance testing. For his examples he uses the Codeception testing tool. He walks you through the setup of some simple tests based on the "home" page functionality of the Zend Expressive skeleton application. With that in place, he shows the updates that will need to be made to execute the tests from outside the instance via a "docker exec" call. The post finishes with a look at adding two other tools to the mix as well: Make and Phing.

tagged: docker test environment series part2 testing acceptance codeception make phing

Link: http://www.masterzendframework.com/how-to-build-a-docker-test-environment/

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/