• Home
  • Get Noticed 2017
  • PHP
  • Quick Tips
  • Contact
  • About me

Bartosz Sosna Blog

Bartosz Sosna Blog

PHP BLOG

PhpUnit code coverage report
Get Noticed 2017, PHP, PHPUnit

PhpUnit code coverage report

PHPUnit code coverage report

If you want to sleep without worry about your code you should write tests. The most popular test framework in PHP is called PHPUnit. That is an advanced product with a very good documentation. In the new version, it’s even faster and more efficient than before. Today I show you how can you create PHPUnit code coverage report. I will definitely use this with my “Image optimizer API” project.

Why generate a report?

The best practice is to write tests before you start to write code, but some time must we work with old code or with code from someone else. If you have huge project can you not sure which code is already tested.

When you use with PHPUnits with legacy code then you definitely want to see how many codes tested you already too. That can you generate an HTML report and check it or presents someone the results.

In this all case you need code coverage report. Best in a readable form such as HTML. PHPUnit can generate it for you.

TIP! You don’t have to coverage 100% code with tests. It does not make sense. You should have hight percentage code coverage and focus on the most important piece of code. That should reduce the risk of errors.

How to generate the code coverage report

To generate the report need you XDebug debugger too, so first you have to install this tool. That is not complicated. I won’t copy an XDebug manual. All the information can you find here:
https://xdebug.org/docs/install

Now can you generate yours first report. You must in your console write:

./vendor/bin/phpunit --coverage-html coverage-folder

That’s it. Now can you check a result in your browser. You should see a page some like this:

phpunit code coverage report
phpunit code coverage report

The instruction how to read a report find you on PHPUnit site:
https://phpunit.de/manual/current/en/code-coverage-analysis.html

I hope that from today testing will become easier for you.

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Google+ (Opens in new window)

Related

Written by Bartosz Sosna in March 24, 2017 / 1163 Views
Tags | get notice 2017, php, phpunit
AUTHOR
Bartosz Sosna

I'm Web and App developer. I love gadgets and new technologies. I'm also productivity freak.

You Might Also Like

PHP coding standards – the first steps

April 22, 2017

Phinx – PHP database migration

April 30, 2017

Why did I choose Slim Framework

March 19, 2017

No Comment

Please Post Your Comments & Reviews
Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Previous Post
Next Post

Serach

Newsletter

Latest Posts

  • API, Get Noticed 2017, PHP“Image Optimizer API” is ready“Get Notice 2017” contest is over My project “Image Optimizer…May 21, 2017
  • Get Noticed 2017, Quick Tips, zshZ shell (zsh) – better bashWhy zsh is better? I use console from years and…May 18, 2017
  • API, Get Noticed 2017, Quick TipsPostman – powerful tool to work with APIPostman – powerful tool to work with API I’m creating…May 7, 2017
  • Capistrano, Get Noticed 2017, PHP, Quick TipsHow to add tasks to capistranoHow to add tasks to Capistrano I wrote in post…May 5, 2017
  • Get Noticed 2017, MySQL, PHP, Quick TipsPhinx – PHP database migrationWhat is “database migration” I meet migrations first time in…April 30, 2017

STAY UPDATED

About Me

About Me

Web and App developer.

I'm Web and App developer. I love gadgets and new technologies. I'm also productivity freak.

About me (de)

Latest Posts

  • API, Get Noticed 2017, PHP“Image Optimizer API” is ready“Get Notice 2017” contest is over My project “Image Optimizer…May 21, 2017
  • Get Noticed 2017, Quick Tips, zshZ shell (zsh) – better bashWhy zsh is better? I use console from years and…May 18, 2017
  • API, Get Noticed 2017, Quick TipsPostman – powerful tool to work with APIPostman – powerful tool to work with API I’m creating…May 7, 2017
  • Capistrano, Get Noticed 2017, PHP, Quick TipsHow to add tasks to capistranoHow to add tasks to Capistrano I wrote in post…May 5, 2017
  • Get Noticed 2017, MySQL, PHP, Quick TipsPhinx – PHP database migrationWhat is “database migration” I meet migrations first time in…April 30, 2017
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

FOLLOW ME ON TWITTER

  • RT @DamianNaprawa: Festiwal Docker & Kubernetes - DZIEŃ 3 BARTOSZ SOSNA @brtsos Palec wskazujący skierowany w prawo Konfiguracja środowi…33 days ago
  • W końcu MacBook Pro bez bezużytczego touch bara? https://t.co/5tweGBUxP245 days ago
Bartosz Sosna Blog

Copyright © Bartosz Sosna