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

Rob Allen:
Replacing a built-in PHP function when testing a component
Oct 22, 2018 @ 10:55:58

Rob Allen has a new post to his site sharing a method you can use in your testing to replace a built-in PHP function with something customized for your needs.

Recently I needed to test part of Slim that uses the built-in PHP functions header() and headers_sent(). To do this, I took advantage of PHP’s namespace resolution rules where it will find a function within the same namespace first before finding one with the same name in the global namespace. The idea of how to do this came courtesy of Matthew Weier O’Phinney where this approach is used for similar testing in Zend-Diactoros.

He starts off with the code he wants to test - a response method - and a simplified version of the test. This method makes use of the headers_sent and header functions in PHP but those needed to be overridden in order to make the test actually work. He includes the changes to make to the test to override these methods because of how namespaces resolve (using the global PHP namespace last).

tagged: replace builtinfunction tutorial namespace testing unittest slim

Link: https://akrabat.com/replacing-a-built-in-php-function-when-testing-a-component/

TechBeacon:
Why your choice of software testing suites matters
Oct 09, 2018 @ 10:44:14

On the TechBeacon site they've posted an article about choosing the right testing tools for your codebase and why making the right choice matters.

Fast end-to-end tests are the next big thing. The tooling has improved tremendously, and the productivity and insight gains are too good to ignore. Modern tools such as Cypress and >TestCafe are becoming quite impressive and can give you confidence in your product's quality.

As with most facets of software development, there is a balance to be strived for between speed and test confidence. The leverage point depends on the project, and the two most common types of software project these days are web services and enterprise software.

They talk about some of the differences between the testing of web services versus enterprise software as well as some of the practical advantage of fast tests. They also cover the advantages of broad tests and cover some of the current tools for testing including Cypress.io and Laravel Dusk.

tagged: software testing tool suite decision opinion

Link: https://techbeacon.com/why-your-choice-software-testing-suites-matters

CloudWays Blog:
Automate Codeigniter Unit Testing With PHPUnit
Oct 08, 2018 @ 12:08:59

On the CloudWays blog there's a tutorial posted for the CodeIgniter framework users out there showing how to get started with unit testing your application.

Quality assurance is one of the central aspects of software development. In fact, test-driven development is an entire development methodology developed around the concept of integrating quality assurance within the development cycle. However, before discussing how to automate Codeigniter unit testing, I will describe the theoretical basis of unit testing and how it adds value to the Codeigniter projects.

The tutorial starts out by defining what a "unit" is and how testing provides value to your project, making it easier to find issues early on and building in simplicity in its structure. It also talks about some of the limitations of unit testing including the effort involved (and lack or potential gain) and having test code with bugs too. It then starts in on some example tests, showing how to work with configuration objects and built test cases and execute the tests.

tagged: unittest codeigniter tutorial introduction testing

Link: https://www.cloudways.com/blog/codeigniter-unit-testing/

Marcel Pociot:
Using Travis-CI for your Laravel Nova packages
Sep 27, 2018 @ 09:26:38

Marcel Pociot has a recent post to his site showing how you can set up builds on the Travis-CI service for your Laravel Nova packages. Laravel Nova is the recently released product from the Laravel creators that provides an administrative dashboard.

Today Laravel announced that Laravel Nova can now be installed via composer. This works by providing your nova.laravel.com username and password as credentials for composer, as well as adding a custom Laravel Nova composer repository to your composer.json file.

[...] This is great news, as this does not only simplify updating Laravel Nova, but it also allows Nova tools/package developers to add continuous integration to their projects! But there is still a problem: we do not want to provide our Laravel Nova credentials in our open source repository. But how can we solve this?

Marcel then walks you through the process of using Travis-CI's encrypted environment variables to protect your credentials. He shows how to install the travis Ruby gem to get the travis command line tool, encrypt the values and update your Travis-CI configuration (.travis.yaml) to pull those into the build.

tagged: travisci continuous build tutorial testing credential encrypted

Link: http://marcelpociot.de/blog/travis-ci-for-laravel-nova-development

Symfony Blog:
Introducing Symfony Panther: a Browser Testing and Web Scraping Library for PHP
Sep 26, 2018 @ 12:24:02

Earlier this month, the Symfony blog made an announcement about a new browser testing and web scraping tool that's been released under the Symfony umbrella: Panther.

Since the very first version of Symfony 2, the framework provides a suite of convenient tools to create functional tests. They use the BrowserKit and DomCrawler components to simulate a web browser with a developer-friendly API.

The post starts with a "refresh" of the current WebTestCase helper functionality to create these functional tests. They also include an example of a repository class that stores/retrieves the news and a matching controller to handle the requests (and Twig templates for output). They then create a test using the WebTestCase functionality to get the index and ensure that some of the content is correct.

The tutorial then takes this same scenario and applies tests using the new Panther functionality. Where the WebTestCase uses a simulated browser internal to the framework, Panther uses an actual browser to run is tests using the Facebook PHP WebDriver library. They show the slight updates that would need to be made to the current test and the resulting output.

The tutorial goes on to provide other examples of tests for API requests and Javascript functionality for a Vue.js frontend. It wraps up mentioning some of the additional functionality Panther includes such as the ability to take screenshots and injecting Javascript into the pre-rendered page.

tagged: panther symfony tutorial introduction testing functional library

Link: https://symfony.com/blog/introducing-symfony-panther-a-browser-testing-and-web-scrapping-library-for-php#comment-form

Larry Garfield:
Don't use Mocking libraries
Sep 21, 2018 @ 11:02:10

Larry Garfield has written up a post with a somewhat controversial headline, especially for anyone that's done any kind of unit testing on a larger codebase. His suggestion is to no use mocking libraries and some other techniques that can replace them.

I am all for testing. [...] There's a lot of opinions on what constitutes a "good" test, of course, and much is subjective to the type of code you're working on. However, since the release of PHP 7 I've found that while writing tests... I am never using a mocking library. In fact, I'm going to go as far and say that you should never use a mocking library in PHP 7.

Before all of you gasp, clutch your pearls, and send ninja hit squads after me, let me justify that position.

He starts off by defining what a "mock" is a more general sense and then, more specifically, how mocking libraries are mostly implemented in PHP. He covers the DSL (domain specific language) knowledge that's required to use most of them and how something already included in PHP 7 - anonymous classes - could be a viable alternative. He goes on to show examples of using this method rather than a mock for simple object handling and even recommends making an actual class (just for testing) if the need is there. He ends the post talking about the "upper bounds" of when this might not be as useful and how this can actually be good (using it as an indicator that you need to refactor the main code to simplify).

tagged: mocking mock library testing unittest opinion anonymous class

Link: https://steemit.com/php/@crell/don-t-use-mocking-libraries

Matthias Noback:
Testing actual behavior
Jun 26, 2018 @ 13:48:02

Matthias Noback has posted another article covering domain-driven development practices, this time focusing on testing actual behavior and some of the downsides that can come with it and domain-driven development.

He breaks the article up into three main sections:

  • The downsides of starting with the domain model
  • The downsides of starting with the smallest bricks
  • The downsides of your test suite as the major client of your production code

Each includes a description of the downsides related to the topic and, where it helps, code to illustrate the issue. The post also includes three experiments to try to help prevent some of these downfalls from happening (including not testing constructors and not adding getters).

Tests are not the main use case of an object, they should guide the development process and make sure you write exactly the code that you need. This means not sacrificing the object's encapsulation just to make it testable.
tagged: domaindriven development tutorial testing behavior downsides

Link: https://matthiasnoback.nl/2018/06/testing-actual-behavior/

Sammy Kaye Powers:
Testing Unreleased Features of PHP
Jun 26, 2018 @ 09:31:52

In a new post to his site Sammy Kaye Powers shows you how to test unreleased features of PHP using a pull request related to a RFC that's officially been proposed.

We'll be discovering and testing a completely unreleased feature of php-src from an RFC that's still under discussion.

If you've ever wanted to be ahead of the curve of PHP features or you've just wanted to contribute back to PHP internals, testing an unreleased feature from an RFC is a fun and educational way to do so.

He uses the typed properties RFC in his example (allowing the addition of types to class properties). He then walks through the checkout of the PHP source, grabbing the pull request for the RFC and compiling PHP with the new code in place. He shows an example of a script that makes use of this new feature and tries it out. Finally, he covers how to run tests on this new version and some suggestions on adding typed properties to real-world projects.

tagged: language rfc pullrequest tutorial testing unreleased feature

Link: https://www.sammyk.me/how-to-compile-an-unreleased-rfc-feature-for-php-source-php-internals

Michaelangelo van Dam:
Testing your e-commerce PHP application
May 02, 2018 @ 10:10:45

Michelangelo van Dam has a new post on his site sharing some helpful hints you can use to test your e-commerce application, be it WooCommerce or other popular PHP-based e-commerce packages.

I'm participating (as much as possible) in the #30daysoftesting challenge organised by Ministry of Testing and SauceLabs. If you're interested, read the full 30 Days of E-Commerce Testing article and join this fun and educational challenge.

The 2nd challenge on the list was to read and share interesting blog articles about E-commerce testing. Since I'm working as a PHP professional I thought it would be great if I oriented my focus on testing PHP based E-commerce platforms. I picked WooCommerce as it's an easy to install and use E-commerce solution. For Magento, PrestaShop and others I've added useful links at the bottom of this article.

He then gets into the details of WooCommerce and what it has available from a testing perspective. He also includes links to a few resources for more general WordPress testing too. The remainder of the post consists of links to more information about testing the other popular e-commerce packages: Magento, PrestaShop, OpenCart, Sylius and Laravel-based packages.

tagged: testing ecommerce application woocommerce magento prestashop

Link: https://www.dragonbe.com/2018/05/testing-your-e-commerce-php-application.html

php[architect]:
Testing Strategy With the Help of Static Analysis
Apr 30, 2018 @ 12:49:41

php[architect] magazine has shared another article from their April 2018 issue on their site. In this article Ondrej Mirtes covers the use of static analysis to help testing and inform you of type safety issues.

When developing an application, our aim as software developers is to make sure it does what it ought to do and to keep the number of defects as low as possible. [...] In this article, I’d like to introduce you to the concept of type safety and how it can improve the reliability and stability of your code. Once your code is more type-safe, and that fact is verified by automated tools, you can cherry-pick which parts of your application need extensive unit tests and where you can rely just on well-defined types.

He starts off by talking about types (strict and dynamic) in PHP and the current state of the typing system for variable values. He covers the role of good type hinting in method and function definitions and how it can help IDEs like PhpStorm locate issues. He also talks about how type hints can provide you feedback on the design of the application and some of the tools that can help you find issues.

He wraps up the article with some tips for making your code more strongly typed and a look at what kind of tests are needed to help ensure these types remain enforced.

tagged: testing staticanalysis help article tutorial tools

Link: https://www.phparch.com/2018/04/testing-strategy-with-the-help-of-static-analysis/