PHP Classes

PHP Create Badges: Create badges for project coverage

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 38 All time: 10,933 This week: 206Up
Version License PHP version Categories
badger 1.0MIT/X Consortium ...5PHP 5, Graphics, Project Management
Description 

Author

This package can create badges for project coverage.

It can read a code coverage report in Clover XML format to extract the coverage value.

The package can generage a JSON definition for a badge from the coverage value and sends a HTTP request to the Shields.io API to generate the badge for the project.

Innovation Award
PHP Programming Innovation award nominee
May 2021
Number 5
Badges are a nice way to show certain metrics about the packages in a graphical way.

This package can generate badges using the Shields.io service. The badges can show the level of test coverage of a package using coverage tools that generate reports in Clover XML format.

Manuel Lemos
Picture of Yousaf Syed
  Performance   Level  
Name: Yousaf Syed <contact>
Classes: 6 packages by
Country: Pakistan Pakistan
Age: 33
All time rank: 232530 in Pakistan Pakistan
Week rank: 180 Up2 in Pakistan Pakistan Up
Innovation award
Innovation award
Nominee: 4x

Winner: 1x

Example

#!/usr/bin/env php
<?php declare(strict_types=1);

if (!
ini_get('date.timezone')) {
   
ini_set('date.timezone', 'UTC');
}

foreach (array(
__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
    if (
file_exists($file)) {
       
define('BADGER_COMPOSER_INSTALL', $file);

        break;
    }
}

unset(
$file);

if (!
defined('BADGER_COMPOSER_INSTALL')) {
   
fwrite(
       
STDERR,
       
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
       
' composer install' . PHP_EOL . PHP_EOL .
       
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
   
);

    die(
1);
}

require
BADGER_COMPOSER_INSTALL;

use
Symfony\Component\Console\Application;
use
Badger\Commands\CoverageBadge;

$application = new Application();

$application->add(new CoverageBadge());

$application->run();


Details

badger

Badger is a small CLI utility for generating a shields.io compatible JSON from clover.xml report and uploading it to a badger-server, see github.com/crowphp/badger-server to read more about the server.

Installing badger from composer

composer require --dev crowphp/badger:dev-master

Notice: At the moment the badger is under development use it with caution.

Usage

Help Document

$ php vendor/bin/badger --help
Console Tool

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help             Displays help for a command
  list             Lists commands
 upload
  upload:coverage  Creates json for coverage badge shields.io and uploads it to a given badger server

Create badge schema on a badger server for a given branch

$ php upload:coverage <server> <branch> <secret-key>

Description:
  Creates json for coverage badge shields.io and uploads it to a given badger server

Usage:
  upload:coverage <server> <branch> <secret-key>

Arguments:
  server                URL for Badger Server
  branch                The branch name for the coverage
  secret-key            Secret api key for badger server

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug


  Files folder image Files (5)  
File Role Description
Files folder imagesrc (1 directory)
Accessible without login Plain text file badger Example Example script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  src  
File Role Description
Files folder imageBadger (1 directory)

  Files folder image Files (5)  /  src  /  Badger  
File Role Description
Files folder imageCommands (1 file)

  Files folder image Files (5)  /  src  /  Badger  /  Commands  
File Role Description
  Plain text file CoverageBadge.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:38
This week:0
All time:10,933
This week:206Up