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

Sergey Zhuk:
Test Coverage: Integration Between CodeClimate and Travis CI
Jan 11, 2018 @ 15:42:11

In a post to his site Sergey Zhuk shows you how to get up and running on Travis-CI and Code Climate for generation unit test coverage with an integration between the two services.

When you maintain an open-source project it is considered a good practice to have a high test coverage, so the community can feel safe about using your code in their projects. There are some services that can analyze your code quality and provide some feedback about it. One of the most popular is Code Climate. This service doesn’t run your tests, but you can use one of CI tools to run them and then send their result to Code Climate. This article will show how to use Travis CI to run your tests and CodeClimate to get your test coverage.

The rest of the tutorial is broken down into five steps (well, five-ish - some have sub-steps):

  • Get Your CodeClimate Reporter ID
  • Add Your Code Climate Token To Travis CI
  • Add CodeClimate Test Reporter Package
  • Update phpunit.xml
  • Update Travis CI Config To Send A Report

Each section includes the configuration changes to the .travis.yml or phpunit.xml configuration files you'll need to make to connect the services and generate the reports automatically.

tagged: unittest coverage metric travisci codecliemate integration automatic tutorial

Link: http://sergeyzhuk.me/2018/01/11/travis-with-codeclimate/

Remi Collet:
PHPUnit code coverage benchmark
Nov 09, 2015 @ 17:57:33

Remi Collet has a quick review of some of the performance results from running the Composer PHPUnit tests on PHP 5 versus PHP 7.

As already said numerous time, PHP 7 is faster than PHP 5. Since PHPUnit 4.8 you can choose between XDebug and phpdbg as driver to retrieve code coverage data, see PHPUnit 4.8: Code Coverage Support.

Here is some benchmark results. All the tests are run using PHPUnit 5.0.8, PHP 5.6.15 as SCL or PHP 7.0.0RC6 as SCL and XDebug 2.4.0beta1 (freshly released, with some additional patches) for the composer test suite.

He shows the results in execution time and memory used for PHP 5 versus PHP 7 versions, both with and without code coverage being generated. He also includes two examples of running the tests with PHP 7, once using the XDebug debugger and one using phpdbg.

tagged: remicollet phpunit composer coverage benchmark php5 php7

Link: http://blog.remirepo.net/post/2015/11/09/PHPUnit-code-coverage-benchmark

ThePHP.cc:
PHPUnit 4.7 and Three Shades of Green
Jun 08, 2015 @ 17:57:25

Sebastian Bergmann has posted a guide to PHPUnit 4.7 and some of the changes/new features it introduces.

PHPUnit 4.7 introduces a couple of small improvements. For instance, PHPUnit's PHPT test runner now supports --INI-- sections, information about the PHP runtime used is now printed in verbose mode, and a warning is now printed when code coverage data is collected but no whitelist is configured.

He also talks about the support that's been added improving the output of the HTML version of the code coverage reports, showing different colors based on how well covered the lines are. He also briefly looks ahead to PHPUnit 5, the versions it will support and the plans for release.

tagged: phpunit unittest v47 small medium large coverage shade phpunit5

Link: https://thephp.cc/news/2015/06/phpunit-4-7-and-three-shades-of-green

Freek Lijten:
Testing and improving PHP extensions for PHP 7
Mar 13, 2015 @ 15:02:47

In his latest post Freek Lijten talks about PHP extensions, the upcoming PHP version - well, PHP7 - and the things that can be (and are being) done to help improve and prepare the extension ecosystem. In his post he walks you through the process of getting a PHP7 install set up, a sample extension set up and writing some tests to help improve it.

PHP7 is coming. And it is coming to a neighbourhood near you :) A couple of people started an initiative to ensure extensions will be running out of the box once PHP7 hits the shelves. The fun part: You can help too! No C knowledge is necessary (although it is fun to dive into PHP's internals!). This piece is a short intro to help you help PHP! Help triaging extensions, write tests, add documentation and who knows when you'll be diving into C code.

He's encouraging this work as a part of the recently launched GoPHP7 - Extensions initiative launched a while back. He starts by helping you get PHP7 installed (from source, compiled). Once that's installed and working, he helps you get an extension up and running, in this case the enchant extension. He shows you how to run the tests for the extension and how to write some tests to contribute back to the project. He includes instructions for generating code coverage reports, walks you through some sample code and a link to a page with more information if you get stuck.

tagged: testing improving extension php7 version phpt unittest coverage gophp7

Link: http://www.freeklijten.nl/home/2015/03/12/Testing-and-improving-PHP-extensions-for-PHP-7

Dave Marshall:
Probing Test Suite Quality with Mutation Testing
Jan 08, 2015 @ 18:09:42

In this recent post to his site Dave Marshall looks at a method for evaluating the overall quality of your suite of unit tests with help from mutation testing.

100% code coverage should never really be a goal. [...] I feel pursuing 100% coverage in a PHP project is a particularly poor idea as our tooling generally only provides Line Coverage. [...] There are more reasonable coverage metrics to use to measure the quality of a test suite. Sebastian Bergmann and Derick Rethans are working hard on bringing some of these options to us, but for now we're limited to line coverage.

He talks about the difference between line, branch and condition coverage types (with code examples) and which allows for more effective and quality tests to be written. He then talks about the results of an experiment to achieve 100% coverage on the Router component in the Aura project. He found the problem using mutation testing - changing values in the production code to make sure the tests break. He also links over to a new mutation testing tool that's been released to help with this kind of thing, humbug, and some of the results it can report.

Mutation testing is a great thing to have a grasp of in theory, but it's not particularly easy to practice. The tools are very hard to write and then their output is often hard to understand or interpret effectively. I wouldn't recommend practicing with mutation testing on a regular basis, but it's certainly worth considering on the odd occasion.
tagged: test suite quality mutation testing unittest coverage

Link: http://davedevelopment.co.uk/2015/01/07/probing-test-suite-quality-with-mutation-testing.html

Derick Rethans:
Code Coverage: Finding Paths
Jan 07, 2015 @ 15:33:13

Derick Rethans has continued his series looking at the code coverage handling that XDebug and PHPUnit make available, allowing you to find the spots in your code not tested much easier. In this new post he talks about a new feature coming to the XDebug tool - branch and path coverage.

Picking up from where we left last time, in this second article we will look at some upcoming functionality in Xdebug. Sebastian has been pressuring me for years to add branch and path coverage to Xdebug, with issue #1034. In the post I will show you what "branch and path coverage" is, and how it helps.

How does this new type of coverage differ from the current functionality? Derick goes on to explain the difference via a simple example (and its resulting coverage). In the first example, using the XDebug available today, shows a fully tested function despite not all paths being testing correctly (a false coverage report). He gets into the "under the covers" changes he's made including how the opcodes are reported and changes he's made to the VLD to make it handle the branching smarter and make coverage more than just a "lines covered" metric. He shows an updated graph of the new coverage/branch flow and what a resulting coverage report might look like with the new "Paths" reporting.

tagged: code coverage phpunit xdebug report paths vld lines

Link: http://derickrethans.nl/path-branch-coverage.html

Derick Rethans:
Code Coverage: The Present
Dec 02, 2014 @ 17:54:01

Derick Rethans has posted the first in a series focusing on the Xdebug tool and the code coverage functionality it can provide via PHPUnit's testing. In this first post he catches the reader up on the current state of things and what all the Xdebug tool can do.

Since ages Xdebug has provided code coverage support for PHPUnit, a way to show which lines are covered by your test cases. But I never really wrote about how it works. A recently filed bug prompted me to write this post, as well as a follow up post on Code Coverage's future.

He starts off with the early days of Xdebug, how it hooked into the Zend Engine (that powers a lot of PHP behind the scenes) and when it was triggered. This came with its own set of problems so Xdebug was updated to overload some opcodes. He talks about how it can calculate the unused lines and determines which lines can be covered in the code coverage results. He provides some example code showing the execution of the coverage report on a simple function and try/catch handler, complete with the HTML output of the results.

tagged: xdebug codecoverage phpunit coverage history functionality opcode

Link: http://derickrethans.nl/code-coverage.html

NetTuts.com:
Unit Testing Succinctly: Why Unit Test?
Oct 16, 2014 @ 17:06:05

NetTuts.com has kicked off a new series of posts today that answers the question "Why unit test?" The series, Unit Testing Succinctly aims to define what unit testing is, approaches to implementing them and what they can do to help you and your application.

The usual mantra we hear regarding any software methodology is that it improves usability and quality, reduces development and testing time, and brings the product to market faster and with fewer bugs. These are lofty goals, but I have yet to see a methodology deliver the Grail of software development. Ultimately, the primary reason to write unit tests is to prove correctness, and this happens only if you write unit tests well.

In this first post they cover three of the more general reasons for making the dive into unit testing your applications at all. These are more "business value" kinds of ideas but they trickle down into the development level, providing value for the developers too.

  • Measuring Correctness
  • Repetition, Repetition, Repetition
  • Code Coverage

Their main point to reinforce is the first of the three, though. Unit testing helps to measure and ensure correctness of both the code itself and the functionality it performs.

tagged: unittest introduction why correctness coverage repeatability

Link: http://code.tutsplus.com/articles/unit-testing-succinctly-why-unit-test--cms-22410

Rami Alnawas:
How to unit test code with Phalcon MVC Models
Apr 29, 2014 @ 16:57:39

Rami Alnawas has posted an interesting tutorial for the Phalcon users out there showing one way you can unit test your models. It's based on his own experience with the framework in a current project.

My first contribution to the PHP community in general, and Phalcon folks in particular, was the introduction of MVC Functional Testing with PHPUnit, this meant that Applications developed using Phalcon Framework could be unit tested by requesting a url then asserting that the response is handled by a specific action within the controller. [...] To date, my latest addition is an example of how to unit test code that utilises Phalcon models, mainly the various static find methods. The code is available on github and the coverage report is coveralls.io.

He shows it at work, creating a simple "Popup" model and a facade to help with making instances for testing. He also includes the code to test this facade, checking the results of methods like "fetchall", "select" and "execute".

tagged: phalcon framework unit test coverage mvc model tutorial

Link: http://www.rami.me.uk/how-to-unit-test-code-with-phalcon-mvc-models

The PHP.cc Blog:
PHPUnit 4.0: Code Coverage Improvements
Mar 10, 2014 @ 15:47:41

The latest version of the popular PHP unit testing tool PHPUnit has officially been released (version 4.0.0) and comes with some nice improvements. In this post to the PHPcc blog Sebastian Bergmann talks about enhancements in one area - code coverage reporting.

One of the highlights of PHPUnit 4.0, which was released last week, is an improvement of the @covers annotation and the addition of the @uses annotation for better code coverage analysis.

He includes a few simple code snippets showing you how the "@covers" annotation has been working and how it can be used in both strict and non-strict modes. He also introduces the "@uses" annotation to define which objects the test is using and how the two interact. He finishes off the post with a mention of the "--strict-coverage" command line flag (or the more general "--strict").

tagged: code coverage improvements phpunit unittest

Link: http://thephp.cc/viewpoints/blog/2014/03/phpunit-4-0-code-coverage-improvements


Trending Topics: