mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added influxdb library
This commit is contained in:
12
lib/influxdb-php/vendor/codeclimate/php-test-reporter/.travis.yml
vendored
Normal file
12
lib/influxdb-php/vendor/codeclimate/php-test-reporter/.travis.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
language: php
|
||||
php:
|
||||
- 5.5
|
||||
env:
|
||||
global:
|
||||
secure: Yc+Xohkr/iEUU7FCQuSLXAE9ywNW9g6CfrM1Ki0Hl+fS15F3AXT7dFY8EyCJ4dP1/oI0dBmwrGWrltXV0XWIjGV1Ms3tefCgQpBBAqwT+hImzVP3RbpZW8Iyo2d0VgiDemQF1LWYD/pKu6d8WljTnv5D77NIMdEJjQ0uzeTLWdw=
|
||||
install: composer install --dev
|
||||
before_script:
|
||||
- git config --global user.email "travis-ci@codeclimate.com"
|
||||
- git config --global user.name "Travis CI"
|
||||
after_script:
|
||||
- php composer/bin/test-reporter
|
18
lib/influxdb-php/vendor/codeclimate/php-test-reporter/DEVELOPING.md
vendored
Normal file
18
lib/influxdb-php/vendor/codeclimate/php-test-reporter/DEVELOPING.md
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# Developing
|
||||
|
||||
- Get the source
|
||||
|
||||
$ git clone https://github.com/codeclimate/php-test-reporter
|
||||
|
||||
- Install dependencies
|
||||
|
||||
$ curl -sS https://getcomposer.org/installer | php
|
||||
$ php composer.phar install --dev
|
||||
|
||||
- Run the tests
|
||||
|
||||
$ ./vendor/bin/phpunit
|
||||
|
||||
- Submit PRs to https://github.com/codeclimate/php-test-reporter
|
||||
|
||||
*Note*: all changes and fixes must have appropriate test coverage.
|
40
lib/influxdb-php/vendor/codeclimate/php-test-reporter/LICENSE
vendored
Normal file
40
lib/influxdb-php/vendor/codeclimate/php-test-reporter/LICENSE
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
Copyright (c) 2014 Code Climate LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
This package includes code by Kitamura Satoshi, distributed under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
135
lib/influxdb-php/vendor/codeclimate/php-test-reporter/README.md
vendored
Normal file
135
lib/influxdb-php/vendor/codeclimate/php-test-reporter/README.md
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
[](https://codeclimate.com/github/codeclimate/php-test-reporter) [](https://travis-ci.org/codeclimate/php-test-reporter)
|
||||
|
||||
# codeclimate-test-reporter
|
||||
|
||||
Collects test coverage data from your PHP test suite and sends it to
|
||||
Code Climate's hosted, automated code review service.
|
||||
|
||||
Code Climate - https://codeclimate.com
|
||||
|
||||
**Important:** If you encounter an error involving SSL certificates, see the **Known Issue: SSL Certificate Error** section below.
|
||||
|
||||
# Important FYIs
|
||||
|
||||
Across the many different testing frameworks, setups, and environments, there are lots of variables at play. Before setting up test coverage, it's important to understand what we do and do not currently support:
|
||||
|
||||
* **Default branch only:** We only support test coverage for your [default branch](http://docs.codeclimate.com/article/151-glossary-default-branch). Be sure to check out this branch before running your tests.
|
||||
* **Single payload:** We currently only support a single test coverage payload per commit. If you run your tests in multiple steps, or via parallel tests, Code Climate will only process the first payload that we receive. If you are using a CI, be sure to check if you are running your tests in a parallel mode.
|
||||
|
||||
**Note:** There is one exception to this rule. We've specifically built an integration with [Solano Labs](https://www.solanolabs.com/) to support parallel tests.
|
||||
|
||||
**Note:** If you've configured Code Climate to analyze multiple languages in the same repository (e.g., Ruby and JavaScript), we can nonetheless only process test coverage information for one of these languages. We'll process the first payload that we receive.
|
||||
* **Invalid File Paths:** By default, our test reporters expect your application to exist at the root of your repository. If this is not the case, the file paths in your test coverage payload will not match the file paths that Code Climate expects.
|
||||
|
||||
## Requirements
|
||||
|
||||
There are several requirements you'll need in order to use the PHP test reporter on your system:
|
||||
|
||||
- [PHPUnit](http://phpunit.de)
|
||||
- [Xdebug](http://xdebug.org)
|
||||
- [Composer](http://getcomposer.org)
|
||||
|
||||
The test reporter uses the [PHPUnit](http://phpunit.de) testing tool to generate [code coverage](http://en.wikipedia.org/wiki/Code_coverage) information. These results show how much of your application's code is being executed by your unit tests. PHPUnit can't generate this information on it's own though - it needs another tool, [Xdebug](http://xdebug.org). This is *not* included as a part of the PHPUnit (or PHP) install by default so you'll need to install it yourself.
|
||||
|
||||
Xdebug is installed as an extension to PHP, not a library. You can find more information about installing the tool via PECL [on the project website](http://xdebug.org/docs/install).
|
||||
|
||||
If you execute your PHPUnit tests with the `--coverage-clover` option and receive the message "The Xdebug extension is not loaded. No code coverage will be generated." you will need to visit the Xdebug website and install the extension. If you do not, you'll most likely get an error something like this:
|
||||
|
||||
```
|
||||
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "[...]/build/logs/clover.xml" in [...]/vendor/satooshi/php-coveralls/src/Contrib/Bundle/CoverallsV1Bundle/Api/Jobs.php on line 52
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
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.
|
||||
|
||||
To install php-test-reporter with Composer run the following command.
|
||||
|
||||
```shell
|
||||
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
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
- Generate coverage data to `build/logs/clover.xml`
|
||||
|
||||
Add the following to phpunit.dist.xml:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit ...>
|
||||
<logging>
|
||||
...
|
||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||
...
|
||||
</logging>
|
||||
</phpunit>
|
||||
```
|
||||
|
||||
Or invoke `phpunit` as follows:
|
||||
|
||||
```
|
||||
$ phpunit --coverage-clover build/logs/clover.xml
|
||||
```
|
||||
|
||||
- Specifying your repo token as an environment variable, invoke the
|
||||
test-reporter:
|
||||
|
||||
```
|
||||
$ CODECLIMATE_REPO_TOKEN="..." vendor/bin/test-reporter
|
||||
```
|
||||
|
||||
The `CODECLIMATE_REPO_TOKEN` value is provided after you add your repo
|
||||
to your Code Climate account by clicking on "Setup Test Coverage" on the
|
||||
right hand side of your feed.
|
||||
|
||||
Please contact hello@codeclimate.com if you need any assistance setting
|
||||
this up.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you're having trouble setting up or working with our test coverage feature, [see our detailed help doc](http://docs.codeclimate.com/article/220-help-im-having-trouble-with-test-coverage), which covers the most common issues encountered.
|
||||
|
||||
## Known Issue: SSL Certificate Error
|
||||
|
||||
If you encounter an error involving SSL certificates when trying to report
|
||||
coverage data from your CI server, you can work around it by manually posting
|
||||
the data via `curl`:
|
||||
|
||||
```yaml
|
||||
after_script:
|
||||
- CODECLIMATE_REPO_TOKEN="..." bin/test-reporter --stdout > codeclimate.json
|
||||
- "curl -X POST -d @codeclimate.json -H 'Content-Type: application/json' -H 'User-Agent: Code Climate (PHP Test Reporter v0.1.1)' https://codeclimate.com/test_reports"
|
||||
```
|
||||
|
||||
**Note:** In the command above, you may need to change `bin/test-reporter` to `vendor/bin/test-reporter`, depending on your project's directory structure.
|
||||
|
||||
More details can be found in [this issue][issue].
|
||||
|
||||
[issue]: https://github.com/codeclimate/php-test-reporter/issues/3
|
||||
|
||||
|
||||
## Contributions
|
||||
|
||||
Patches, bug fixes, feature requests, and pull requests are welcome on
|
||||
the GitHub page for this project:
|
||||
|
||||
https://github.com/codeclimate/php-test-reporter
|
||||
|
||||
This package is maintained by Bryan Helmkamp (bryan@codeclimate.com).
|
||||
|
||||
## Copyright
|
||||
|
||||
See LICENSE.txt
|
||||
|
||||
Portions of the implementation were inspired by the php-coveralls
|
||||
project.
|
||||
|
37
lib/influxdb-php/vendor/codeclimate/php-test-reporter/composer.json
vendored
Normal file
37
lib/influxdb-php/vendor/codeclimate/php-test-reporter/composer.json
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "codeclimate/php-test-reporter",
|
||||
"description": "PHP client for reporting test coverage to Code Climate",
|
||||
"keywords": ["codeclimate", "coverage"],
|
||||
"homepage": "https://github.com/codeclimate/php-test-reporter",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Code Climate",
|
||||
"email": "hello@codeclimate.com",
|
||||
"homepage": "https://codeclimate.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3",
|
||||
"ext-curl": "*",
|
||||
"satooshi/php-coveralls": "0.6.*",
|
||||
"symfony/console": ">=2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*@stable",
|
||||
"ext-xdebug": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"CodeClimate\\Component": "src/",
|
||||
"CodeClimate\\Bundle": "src/"
|
||||
}
|
||||
},
|
||||
"bin": ["composer/bin/test-reporter"],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "0.1.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
33
lib/influxdb-php/vendor/codeclimate/php-test-reporter/composer/bin/test-reporter
vendored
Executable file
33
lib/influxdb-php/vendor/codeclimate/php-test-reporter/composer/bin/test-reporter
vendored
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
$files = array(
|
||||
__DIR__ . '/../../vendor/autoload.php',
|
||||
__DIR__ . '/../../../../autoload.php'
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (file_exists($file)) {
|
||||
include_once $file;
|
||||
|
||||
define('PHP_TEST_REPORTER_COMPOSER_INSTALL', $file);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined('PHP_TEST_REPORTER_COMPOSER_INSTALL')) {
|
||||
die(
|
||||
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
|
||||
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
|
||||
'php composer.phar install' . PHP_EOL
|
||||
);
|
||||
}
|
||||
|
||||
use CodeClimate\Bundle\TestReporterBundle\Version;
|
||||
use CodeClimate\Bundle\TestReporterBundle\Console\Application;
|
||||
|
||||
$rootDir = realpath(dirname(PHP_TEST_REPORTER_COMPOSER_INSTALL) . '/..');
|
||||
|
||||
$app = new Application($rootDir, 'Code Climate PHP Test Reporter', Version::VERSION);
|
||||
$app->run();
|
33
lib/influxdb-php/vendor/codeclimate/php-test-reporter/phpunit.xml.dist
vendored
Normal file
33
lib/influxdb-php/vendor/codeclimate/php-test-reporter/phpunit.xml.dist
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="tests/bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="PHP test reporter test suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||
</logging>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./src</directory>
|
||||
<exclude>
|
||||
<directory>./composer</directory>
|
||||
<directory>./tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
namespace CodeClimate\Bundle\TestReporterBundle;
|
||||
|
||||
class ApiClient
|
||||
{
|
||||
protected $apiHost;
|
||||
|
||||
/**
|
||||
* Init the API client and set the hostname
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->apiHost = "https://codeclimate.com";
|
||||
|
||||
if (isset($_SERVER["CODECLIMATE_API_HOST"])) {
|
||||
$this->apiHost = $_SERVER["CODECLIMATE_API_HOST"];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the given JSON as a request to the CodeClimate Server
|
||||
*
|
||||
* @param object $json JSON data
|
||||
* @return \stdClass Response object with (code, message, headers & body properties)
|
||||
*/
|
||||
public function send($json)
|
||||
{
|
||||
$response = new \stdClass;
|
||||
$payload = (string)$json;
|
||||
$options = array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => array(
|
||||
'Host: codeclimate.com',
|
||||
'Content-Type: application/json',
|
||||
'User-Agent: Code Climate (PHP Test Reporter v'.Version::VERSION.')',
|
||||
'Content-Length: '.strlen($payload)
|
||||
),
|
||||
'content' => $payload,
|
||||
"timeout" => 10
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($options);
|
||||
$url = $this->apiHost.'/test_reports';
|
||||
|
||||
if ($stream = @fopen($url, 'r', false, $context)) {
|
||||
$meta = stream_get_meta_data($stream);
|
||||
$raw_response = implode("\r\n", $meta['wrapper_data'])."\r\n\r\n".stream_get_contents($stream);
|
||||
fclose($stream);
|
||||
|
||||
if (!empty($raw_response)) {
|
||||
$response = $this->buildResponse($response, $raw_response);
|
||||
}
|
||||
} else {
|
||||
$error = error_get_last();
|
||||
preg_match('/([0-9]{3})/', $error['message'], $match);
|
||||
$errorCode = (isset($match[1])) ? $match[1] : 500;
|
||||
|
||||
$response->code = $errorCode;
|
||||
$response->message = $error['message'];
|
||||
$response->headers = array();
|
||||
$response->body = NULL;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the response object from the HTTP results
|
||||
*
|
||||
* @param \stdClass $response Standard object
|
||||
* @param string $body HTTP response contents
|
||||
* @return \stcClass Populated class object
|
||||
*/
|
||||
private function buildResponse($response, $body)
|
||||
{
|
||||
list($response->headers, $response->body) = explode("\r\n\r\n", $body, 2);
|
||||
$response->headers = explode("\r\n", $response->headers);
|
||||
list(, $response->code, $response->message) = explode(' ', $response->headers[0], 3);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace CodeClimate\Bundle\TestReporterBundle\Command;
|
||||
|
||||
use CodeClimate\Bundle\TestReporterBundle\CoverageCollector;
|
||||
use CodeClimate\Bundle\TestReporterBundle\ApiClient;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Test reporter command
|
||||
*/
|
||||
class TestReporterCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Path to project root directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rootDir;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Component\Console\Command\Command::configure()
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('test-reporter')
|
||||
->setDescription('Code Climate PHP Test Reporter')
|
||||
->addOption(
|
||||
'stdout',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Do not upload, print JSON payload to stdout'
|
||||
)
|
||||
->addOption(
|
||||
'coverage-report',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'Location of clover style CodeCoverage report, as produced by PHPUnit\'s --coverage-clover option.',
|
||||
array('build/logs/clover.xml')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Component\Console\Command\Command::execute()
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ret = 0;
|
||||
$collector = new CoverageCollector($input->getOption('coverage-report'));
|
||||
$json = $collector->collectAsJson();
|
||||
|
||||
if ($input->getOption('stdout')) {
|
||||
$output->writeln((string)$json);
|
||||
} else {
|
||||
$client = new ApiClient();
|
||||
$response = $client->send($json);
|
||||
switch ($response->code) {
|
||||
case 200:
|
||||
$output->writeln("Test coverage data sent.");
|
||||
break;
|
||||
|
||||
case 401:
|
||||
$output->writeln("Invalid CODECLIMATE_REPO_TOKEN.");
|
||||
$ret = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
$output->writeln("Unexpected response: ".$response->code." ".$response->message);
|
||||
$output->writeln($response->body);
|
||||
$ret = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// accessor
|
||||
|
||||
/**
|
||||
* Set root directory.
|
||||
*
|
||||
* @param string $rootDir Path to project root directory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setRootDir($rootDir)
|
||||
{
|
||||
$this->rootDir = $rootDir;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace CodeClimate\Bundle\TestReporterBundle\Console;
|
||||
|
||||
use CodeClimate\Bundle\TestReporterBundle\Command\TestReporterCommand;
|
||||
use Symfony\Component\Console\Application as BaseApplication;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Coveralls API application.
|
||||
*
|
||||
* @author Kitamura Satoshi <with.no.parachute@gmail.com>
|
||||
*/
|
||||
class Application extends BaseApplication
|
||||
{
|
||||
/**
|
||||
* Path to project root directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $rootDir;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $rootDir Path to project root directory.
|
||||
* @param string $name The name of the application
|
||||
* @param string $version The version of the application
|
||||
*/
|
||||
public function __construct($rootDir, $name = 'UNKNOWN', $version = 'UNKNOWN')
|
||||
{
|
||||
$this->rootDir = $rootDir;
|
||||
|
||||
parent::__construct($name, $version);
|
||||
}
|
||||
|
||||
// internal method
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Component\Console\Application::getCommandName()
|
||||
*/
|
||||
protected function getCommandName(InputInterface $input)
|
||||
{
|
||||
return 'test-reporter';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Component\Console\Application::getDefaultCommands()
|
||||
*/
|
||||
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();
|
||||
|
||||
return $defaultCommands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create TestReporterCommand.
|
||||
*
|
||||
* @return \CodeClimate\Bundle\TestReporterBundle\Command\TestReporterCommand
|
||||
*/
|
||||
protected function createTestReporterCommand()
|
||||
{
|
||||
$command = new TestReporterCommand();
|
||||
$command->setRootDir($this->rootDir);
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
// accessor
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Component\Console\Application::getDefinition()
|
||||
*/
|
||||
public function getDefinition()
|
||||
{
|
||||
$inputDefinition = parent::getDefinition();
|
||||
// clear out the normal first argument, which is the command name
|
||||
$inputDefinition->setArguments();
|
||||
|
||||
return $inputDefinition;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace CodeClimate\Bundle\TestReporterBundle;
|
||||
|
||||
use CodeClimate\Component\System\Git\GitCommand;
|
||||
use CodeClimate\Bundle\TestReporterBundle\Entity\JsonFile;
|
||||
use Contrib\Bundle\CoverallsV1Bundle\Api\Jobs;
|
||||
use Contrib\Bundle\CoverallsV1Bundle\Config\Configuration;
|
||||
|
||||
class CoverageCollector
|
||||
{
|
||||
protected $api;
|
||||
|
||||
/**
|
||||
* Array that holds list of relative paths to Clover XML files
|
||||
* @var array
|
||||
*/
|
||||
protected $cloverPaths = array();
|
||||
|
||||
public function __construct($paths)
|
||||
{
|
||||
$rootDir = getcwd();
|
||||
$config = new Configuration();
|
||||
$config->setSrcDir($rootDir);
|
||||
$this->setCloverPaths($paths);
|
||||
foreach ($this->getCloverPaths() as $path) {
|
||||
if (file_exists($path)) {
|
||||
$config->addCloverXmlPath($path);
|
||||
} else {
|
||||
$config->addCloverXmlPath($rootDir . DIRECTORY_SEPARATOR . $path);
|
||||
}
|
||||
}
|
||||
|
||||
$this->api = new Jobs($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a list of Clover XML paths
|
||||
* @param array $paths Array of relative paths to Clovers XML files
|
||||
*/
|
||||
public function setCloverPaths($paths)
|
||||
{
|
||||
$this->cloverPaths = $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of Clover XML paths
|
||||
* @return array Array of relative Clover XML file locations
|
||||
*/
|
||||
public function getCloverPaths()
|
||||
{
|
||||
return $this->cloverPaths;
|
||||
}
|
||||
public function collectAsJson()
|
||||
{
|
||||
$cloverJsonFile = $this->api->collectCloverXml()->getJsonFile();
|
||||
|
||||
$jsonFile = new JsonFile();
|
||||
$jsonFile->setRunAt($cloverJsonFile->getRunAt());
|
||||
|
||||
foreach ($cloverJsonFile->getSourceFiles() as $sourceFile) {
|
||||
$jsonFile->addSourceFile($sourceFile);
|
||||
}
|
||||
|
||||
return $jsonFile;
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
namespace CodeClimate\Bundle\TestReporterBundle\Entity;
|
||||
|
||||
class CiInfo
|
||||
{
|
||||
public function toArray()
|
||||
{
|
||||
if (isset($_SERVER["TRAVIS"])) {
|
||||
return $this->travisProperties();
|
||||
}
|
||||
|
||||
if (isset($_SERVER["CIRCLECI"])) {
|
||||
return $this->circleProperties();
|
||||
}
|
||||
|
||||
if (isset($_SERVER["SEMAPHORE"])) {
|
||||
return $this->semaphoreProperties();
|
||||
}
|
||||
|
||||
if (isset($_SERVER["JENKINS_URL"])) {
|
||||
return $this->jenkinsProperties();
|
||||
}
|
||||
|
||||
if (isset($_SERVER["TDDIUM"])) {
|
||||
return $this->tddiumProperties();
|
||||
}
|
||||
|
||||
if (isset($_SERVER["CI_NAME"]) && preg_match('/codeship/i', $_SERVER["CI_NAME"])) {
|
||||
return $this->codeshipProperties();
|
||||
}
|
||||
|
||||
if (isset($_SERVER["BUILDBOX"])) {
|
||||
return $this->buildboxProperties();
|
||||
}
|
||||
|
||||
if (isset($_SERVER["WERCKER"])) {
|
||||
return $this->werckerProperties();
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function travisProperties()
|
||||
{
|
||||
return array(
|
||||
"name" => "travis-ci",
|
||||
"branch" => $_SERVER["TRAVIS_BRANCH"],
|
||||
"build_identifier" => $_SERVER["TRAVIS_JOB_ID"],
|
||||
"pull_request" => $_SERVER["TRAVIS_PULL_REQUEST"]
|
||||
);
|
||||
}
|
||||
|
||||
protected function circleProperties()
|
||||
{
|
||||
return array(
|
||||
"name" => "circleci",
|
||||
"build_identifier" => $_SERVER["CIRCLE_BUILD_NUM"],
|
||||
"branch" => $_SERVER["CIRCLE_BRANCH"],
|
||||
"commit_sha" => $_SERVER["CIRCLE_SHA1"]
|
||||
);
|
||||
}
|
||||
|
||||
protected function semaphoreProperties()
|
||||
{
|
||||
return array(
|
||||
"name" => "semaphore",
|
||||
"branch" => $_SERVER["BRANCH_NAME"],
|
||||
"build_identifier" => $_SERVER["SEMAPHORE_BUILD_NUMBER"]
|
||||
);
|
||||
}
|
||||
|
||||
protected function jenkinsProperties()
|
||||
{
|
||||
return array(
|
||||
"name" => "jenkins",
|
||||
"build_identifier" => $_SERVER["BUILD_NUMBER"],
|
||||
"build_url" => $_SERVER["BUILD_URL"],
|
||||
"branch" => $_SERVER["GIT_BRANCH"],
|
||||
"commit_sha" => $_SERVER["GIT_COMMIT"]
|
||||
);
|
||||
}
|
||||
|
||||
protected function tddiumProperties()
|
||||
{
|
||||
return array(
|
||||
"name" => "tddium",
|
||||
"build_identifier" => $_SERVER["TDDIUM_SESSION_ID"],
|
||||
"worker_id" => $_SERVER["TDDIUM_TID"]
|
||||
);
|
||||
}
|
||||
|
||||
protected function codeshipProperties()
|
||||
{
|
||||
return array(
|
||||
"name" => "codeship",
|
||||
"build_identifier" => $_SERVER["CI_BUILD_NUMBER"],
|
||||
"build_url" => $_SERVER["CI_BUILD_URL"],
|
||||
"branch" => $_SERVER["CI_BRANCH"],
|
||||
"commit_sha" => $_SERVER["CI_COMMIT_ID"]
|
||||
);
|
||||
}
|
||||
|
||||
protected function buildboxProperties()
|
||||
{
|
||||
return array(
|
||||
"name" => "buildbox",
|
||||
"build_identifier" => $_SERVER["BUILDBOX_BUILD_ID"],
|
||||
"build_url" => $_SERVER["BUILDBOX_BUILD_URL"],
|
||||
"branch" => $_SERVER["BUILDBOX_BRANCH"],
|
||||
"commit_sha" => $_SERVER["BUILDBOX_COMMIT"],
|
||||
"pull_request" => $_SERVER["BUILDBOX_PULL_REQUEST"]
|
||||
);
|
||||
}
|
||||
|
||||
protected function werckerProperties()
|
||||
{
|
||||
return array(
|
||||
"name" => "wercker",
|
||||
"build_identifier" => $_SERVER["WERCKER_BUILD_ID"],
|
||||
"build_url" => $_SERVER["WERCKER_BUILD_URL"],
|
||||
"branch" => $_SERVER["WERCKER_GIT_BRANCH"],
|
||||
"commit_sha" => $_SERVER["WERCKER_GIT_COMMIT"]
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
namespace CodeClimate\Bundle\TestReporterBundle\Entity;
|
||||
|
||||
use CodeClimate\Component\System\Git\GitCommand;
|
||||
use CodeClimate\Bundle\TestReporterBundle\Entity\CiInfo;
|
||||
use CodeClimate\Bundle\TestReporterBundle\Version;
|
||||
use Contrib\Bundle\CoverallsV1Bundle\Entity\JsonFile as SatooshiJsonFile;
|
||||
|
||||
class JsonFile extends SatooshiJsonFile
|
||||
{
|
||||
public function toArray()
|
||||
{
|
||||
return array(
|
||||
"partial" => false,
|
||||
"run_at" => $this->getRunAt(),
|
||||
"repo_token" => $this->getRepoToken(),
|
||||
"environment" => $this->getEnvironment(),
|
||||
"git" => $this->collectGitInfo(),
|
||||
"ci_service" => $this->collectCiServiceInfo(),
|
||||
"source_files" => $this->collectSourceFiles()
|
||||
);
|
||||
}
|
||||
|
||||
public function getRunAt()
|
||||
{
|
||||
return strtotime(parent::getRunAt());
|
||||
}
|
||||
|
||||
public function getRepoToken()
|
||||
{
|
||||
return $_SERVER["CODECLIMATE_REPO_TOKEN"];
|
||||
}
|
||||
|
||||
protected function getEnvironment()
|
||||
{
|
||||
return array(
|
||||
"pwd" => getcwd(),
|
||||
"package_version" => Version::VERSION
|
||||
);
|
||||
}
|
||||
|
||||
protected function collectGitInfo()
|
||||
{
|
||||
$command = new GitCommand();
|
||||
|
||||
return array(
|
||||
"head" => $command->getHead(),
|
||||
"branch" => $command->getBranch(),
|
||||
"committed_at" => $command->getCommittedAt()
|
||||
);
|
||||
}
|
||||
|
||||
protected function collectCiServiceInfo()
|
||||
{
|
||||
$ciInfo = new CiInfo();
|
||||
|
||||
return $ciInfo->toArray();
|
||||
}
|
||||
|
||||
protected function collectSourceFiles()
|
||||
{
|
||||
$sourceFiles = array();
|
||||
|
||||
foreach ($this->getSourceFiles() as $sourceFile) {
|
||||
array_push($sourceFiles, array(
|
||||
"name" => $sourceFile->getName(),
|
||||
"coverage" => json_encode($sourceFile->getCoverage()),
|
||||
"blob_id" => $this->calculateBlobId($sourceFile)
|
||||
));
|
||||
}
|
||||
|
||||
return $sourceFiles;
|
||||
}
|
||||
|
||||
protected function calculateBlobId($sourceFile)
|
||||
{
|
||||
$content = file_get_contents($sourceFile->getPath());
|
||||
$header = "blob ".strlen($content)."\0";
|
||||
|
||||
return sha1($header.$content);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace CodeClimate\Bundle\TestReporterBundle;
|
||||
|
||||
/**
|
||||
* TestReporterBundle version.
|
||||
*/
|
||||
final class Version
|
||||
{
|
||||
/**
|
||||
* TestReporter version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION = '0.1.2';
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace CodeClimate\Component\System\Git;
|
||||
|
||||
use Contrib\Component\System\SystemCommand;
|
||||
|
||||
class GitCommand extends SystemCommand
|
||||
{
|
||||
protected $commandPath = 'git';
|
||||
|
||||
public function getHead()
|
||||
{
|
||||
$command = $this->createCommand("log -1 --pretty=format:'%H'");
|
||||
|
||||
return current($this->executeCommand($command));
|
||||
}
|
||||
|
||||
public function getBranch()
|
||||
{
|
||||
$command = $this->createCommand("branch");
|
||||
$branches = $this->executeCommand($command);
|
||||
|
||||
foreach ($branches as $branch) {
|
||||
if ($branch[0] == "*") {
|
||||
return str_replace("* ", "", $branch);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCommittedAt()
|
||||
{
|
||||
$command = $this->createCommand("log -1 --pretty=format:'%ct'");
|
||||
|
||||
return (int)current($this->executeCommand($command));
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace CodeClimate\Bundle\TestReporterBundle\Console;
|
||||
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
|
||||
class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const PROJECT_DIR = "/tmp/php-test-reporter-example-project";
|
||||
|
||||
protected $srcDir;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->srcDir = realpath(__DIR__ . '/../../../../..');
|
||||
$this->setupProject();
|
||||
$this->setupEnvironment();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldExecuteSuccessfully()
|
||||
{
|
||||
$app = new Application($this->srcDir, 'PHP Test Reporter', '1.0.0');
|
||||
$app->setAutoExit(false);
|
||||
$tester = new ApplicationTester($app);
|
||||
|
||||
$status = $tester->run(array('--stdout' => true));
|
||||
|
||||
$this->assertEquals(0, $status);
|
||||
}
|
||||
|
||||
private function setupProject()
|
||||
{
|
||||
shell_exec("rm -rf ".static::PROJECT_DIR);
|
||||
mkdir(static::PROJECT_DIR."/build/logs", 0755, true);
|
||||
copy("tests/files/test.php", static::PROJECT_DIR."/test.php");
|
||||
copy("tests/files/test.php", static::PROJECT_DIR."/test2.php");
|
||||
copy("tests/files/clover.xml", static::PROJECT_DIR."/build/logs/clover.xml");
|
||||
|
||||
chdir(static::PROJECT_DIR);
|
||||
|
||||
shell_exec("git init");
|
||||
shell_exec("git add test.php test2.php");
|
||||
shell_exec("git commit -m 'Initial commit'");
|
||||
shell_exec("git remote add origin git@github.com:foo/bar.git");
|
||||
}
|
||||
|
||||
private function setupEnvironment()
|
||||
{
|
||||
$_SERVER["CODECLIMATE_REPO_TOKEN"] = 'abc123';
|
||||
$_SERVER["TRAVIS"] = "1";
|
||||
$_SERVER["TRAVIS_BRANCH"] = "master";
|
||||
$_SERVER["TRAVIS_JOB_ID"] = "1";
|
||||
$_SERVER["TRAVIS_PULL_REQUEST"] = "fb-feature";
|
||||
}
|
||||
}
|
4
lib/influxdb-php/vendor/codeclimate/php-test-reporter/tests/bootstrap.php
vendored
Normal file
4
lib/influxdb-php/vendor/codeclimate/php-test-reporter/tests/bootstrap.php
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
$loader = require realpath(__DIR__ . '/../vendor/autoload.php');
|
||||
$loader->add('CodeClimate', __DIR__);
|
21
lib/influxdb-php/vendor/codeclimate/php-test-reporter/tests/files/clover.xml
vendored
Normal file
21
lib/influxdb-php/vendor/codeclimate/php-test-reporter/tests/files/clover.xml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<coverage generated="1365848893">
|
||||
<project timestamp="1365848893">
|
||||
<file name="/tmp/php-test-reporter-example-project/test.php">
|
||||
<class name="TestFile" namespace="global">
|
||||
<metrics methods="1" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="0" elements="2" coveredelements="0"/>
|
||||
</class>
|
||||
<line num="5" type="method" name="__construct" crap="1" count="0"/>
|
||||
<line num="7" type="stmt" count="0"/>
|
||||
</file>
|
||||
<package name="Hoge">
|
||||
<file name="/tmp/php-test-reporter-example-project/test2.php">
|
||||
<class name="TestFile" namespace="Hoge">
|
||||
<metrics methods="1" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="0" elements="2" coveredelements="0"/>
|
||||
</class>
|
||||
<line num="6" type="method" name="__construct" crap="1" count="0"/>
|
||||
<line num="8" type="stmt" count="0"/>
|
||||
</file>
|
||||
</package>
|
||||
</project>
|
||||
</coverage>
|
8
lib/influxdb-php/vendor/codeclimate/php-test-reporter/tests/files/test.php
vendored
Normal file
8
lib/influxdb-php/vendor/codeclimate/php-test-reporter/tests/files/test.php
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
class TestFile
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'hoge';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user