Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Change Log

All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]

### Added

- Executable .phar file for download
- `upload` command (PHAR only) - same as calling the tool without a command when installed via composer.
- `self-update` / `selfupdate` command (PHAR only)
- `rollback` command (PHAR only)
- [Installation / Usage](./README.md) / [Distribution instructions](./DEVELOPING.md) for the PHAR tool

[Unreleased]: https://github.com/codeclimate/php-test-reporter/compare/v0.3.2...HEAD
38 changes: 32 additions & 6 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
# Developing

- Get the source
## Get the source

$ git clone https://github.com/codeclimate/php-test-reporter

- Install dependencies
## Install dependencies

$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install --dev
$ php composer.phar update -o -v

- Run the tests
## Run the tests

$ ./vendor/bin/phpunit

### With HTML coverage output:

- Submit PRs to https://github.com/codeclimate/php-test-reporter
$ ./vendor/bin/phpunit --coverage-html=build/logs/coverage

*Note*: all changes and fixes must have appropriate test coverage.
## Build the PHAR tool

# Create a new git tag (optional)
$ git tag v1.x.x -m 'Version 1.x.x'
# Build the PHAR using box project
$ ./vendor/bin/box build

## Distribute the PHAR tool

### With verification and compatibility for phar.io / PhiVE

* [Create a GPG key](https://phar.io/howto/generate-gpg-key.html) (Should be the repositoy's maintainer one)
* [Create a signature and upload to Github](https://phar.io/howto/sign-and-upload-to-github.html)

### Without verification

* Go to the [releases section on Github](https://github.com/codeclimate/php-test-reporter/releases)
* Click "Edit" on the latest tag/release
* Add the `codeclimate-test-reporter.phar` in the "Attach binaries..." section
* Click "Update release"

## Contribute

* Submit PRs to: https://github.com/codeclimate/php-test-reporter
* *Note*: all changes and fixes must have appropriate test coverage.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,27 @@ This package requires a user, but not necessarily a paid account, on
Code Climate, so if you don't have one the first step is to signup at:
https://codeclimate.com.

### Via composer

To install php-test-reporter with Composer run the following command.

```shell
composer require codeclimate/php-test-reporter --dev
$ composer require codeclimate/php-test-reporter --dev
```

This will get you the latest version of the reporter and install it. If you do want the master, untagged, version you may use the command below:

```shell
composer require codeclimate/php-test-reporter:@dev --dev
$ composer require codeclimate/php-test-reporter:@dev --dev
```

### As PHAR tool

Checkout the [latest release here](https://github.com/codeclimate/php-test-reporter/releases) and replace `X.X.X` with the latest version.

```shell
$ RELEASE=X.X.X
$ wget -c "https://github.com/codeclimate/php-test-reporter/releases/download/$RELEASE/codeclimate-test-reporter.phar"
```

## Usage
Expand All @@ -77,15 +88,19 @@ Add the following to phpunit.xml.dist:

Or invoke `phpunit` as follows:

```
```shell
$ phpunit --coverage-clover build/logs/clover.xml
```

- Specifying your repo token as an environment variable, invoke the
test-reporter:

```
```shell
$ CODECLIMATE_REPO_TOKEN="..." vendor/bin/test-reporter

# ... or via PHAR ...

$ CODECLIMATE_REPO_TOKEN="..." codeclimate-test-reporter.phar upload
```

The `CODECLIMATE_REPO_TOKEN` value is provided after you add your repo
Expand Down
58 changes: 37 additions & 21 deletions box.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
{
"alias": "codeclimate-test-reporter.phar",
"chmod": "0755",
"directories": ["src"],
"compactors": [
"Herrera\\Box\\Compactor\\Php"
],
"extract": true,
"files": [
"LICENSE"
],
"finder": [
{
"name": ["*.php", "*.pem"],
"exclude": ["tests"],
"in": ["vendor"]
}
],
"git-version": "package_version",
"main": "composer/bin/test-reporter",
"output": "codeclimate-test-reporter.phar",
"stub": true
"chmod": "0755",
"compression": "GZ",
"alias": "codeclimate-test-reporter.phar",
"directories": [
"src"
],
"compactors": [
"Herrera\\Box\\Compactor\\Php"
],
"extract": false,
"intercept": true,
"files": [
"LICENSE"
],
"finder": [
{
"name": [
"*.php",
"*.pem"
],
"exclude": [
"bin",
"tests",
"phpunit",
"tm"
],
"in": [
"vendor"
]
}
],
"git-version": "package_version",
"main": "phar/bin/main.php",
"metadata": "The code climate php test reporter",
"output": "build/codeclimate-test-reporter.phar",
"shebang": "#!/usr/bin/env php",
"stub": true
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"php": ">=5.3",
"ext-curl": "*",
"satooshi/php-coveralls": "^1.0",
"symfony/console": "^2.0|^3.0"
"symfony/console": "^2.0|^3.0",
"psr/log": "^1.0",
"padraic/phar-updater": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.*@stable",
Expand Down
33 changes: 33 additions & 0 deletions phar/bin/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* @author hollodotme <[email protected]>
*/

namespace CodeClimate\PhpTestReporter;

use CodeClimate\PhpTestReporter\ConsoleCommands\RollbackCommand;
use CodeClimate\PhpTestReporter\ConsoleCommands\SelfUpdateCommand;
use CodeClimate\PhpTestReporter\ConsoleCommands\UploadCommand;
use Symfony\Component\Console\Application;

require(__DIR__ . '/../../vendor/autoload.php');

try {
$app = new Application('Code Climate PHP Test Reporter', '@package_version@');
$app->addCommands(
[
new UploadCommand('upload'),
new SelfUpdateCommand('self-update'),
new RollbackCommand('rollback'),
]
);

$code = $app->run();

exit($code);
} catch (\Exception $e) {
echo 'Uncaught Exception ' . get_class($e) . ' with message: ' . $e->getMessage() . PHP_EOL;
echo $e->getTraceAsString();

exit(1);
}
14 changes: 7 additions & 7 deletions src/Application.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace CodeClimate\PhpTestReporter;

use CodeClimate\PhpTestReporter\ConsoleCommands\TestReporterCommand;
use CodeClimate\PhpTestReporter\ConsoleCommands\UploadCommand;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Input\InputInterface;

Expand All @@ -19,7 +19,7 @@ class Application extends BaseApplication
*/
protected function getCommandName(InputInterface $input)
{
return 'test-reporter';
return 'upload';
}

/**
Expand All @@ -31,18 +31,18 @@ protected function getDefaultCommands()
// Keep the core default commands to have the HelpCommand
// which is used when using the --help option
$defaultCommands = parent::getDefaultCommands();
$defaultCommands[] = $this->createTestReporterCommand();
$defaultCommands[] = $this->createUploadCommand();

return $defaultCommands;
}

/**
* Create TestReporterCommand.
* @return TestReporterCommand
* Create UploadCommand.
* @return UploadCommand
*/
protected function createTestReporterCommand()
protected function createUploadCommand()
{
$command = new TestReporterCommand();
$command = new UploadCommand('upload');

return $command;
}
Expand Down
54 changes: 54 additions & 0 deletions src/ConsoleCommands/RollbackCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* @author hollodotme
*/

namespace CodeClimate\PhpTestReporter\ConsoleCommands;

use CodeClimate\PhpTestReporter\Constants\PharTool;
use Humbug\SelfUpdate\Strategy\GithubStrategy;
use Humbug\SelfUpdate\Updater;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class RollbackCommand
* @package CodeClimate\PhpTestReporter\ConsoleCommands
*/
class RollbackCommand extends Command
{
protected function configure()
{
$this->setDescription('Rolls back this PHAR to the previous version.');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$input->validate();
$logger = new ConsoleLogger($output);
$updater = new Updater(null, false, Updater::STRATEGY_GITHUB);

/** @var GithubStrategy $strategy */
$strategy = $updater->getStrategy();

$strategy->setPackageName(PharTool::PACKAGE_NAME);
$strategy->setPharName(PharTool::PHAR_NAME);
$strategy->setCurrentLocalVersion('@package_version@');

if ($updater->rollback()) {
$logger->info('Roll back successful!');
} else {
$logger->alert('Roll back failed.');
}

return 0;
}
}
Loading