Skip to content

Commit

Permalink
bump dependencies, remove fool/echolog dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
schnittstabil committed Mar 18, 2018
1 parent db951a8 commit ca85b29
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 141 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ php:
- 7
- 7.0
- 7.1
- 7.2
- hhvm

sudo: false

install:
- composer selfupdate
- composer install
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then composer require johnkary/phpunit-speedtrap codeclimate/php-test-reporter satooshi/php-coveralls; fi
- |
if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then
composer require 'johnkary/phpunit-speedtrap:*' 'codeclimate/php-test-reporter:*' 'satooshi/php-coveralls:*'
else
composer install
fi
script:
- composer travis
Expand Down
40 changes: 40 additions & 0 deletions Command6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace SugaredRim\PHPUnit\TextUI;

use Schnittstabil\Get\Get;

class Command extends BaseCommand
{
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function handleArguments(array $argv)
{
parent::handleArguments($argv);

if (Get::value('sugaredDebug', $this->arguments, false)) {
$this->logDebug('Parsed arguments', $this->arguments);
}

$this->addListeners();
}

/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function run(array $argv, $exit = true)
{
$argv = $this->preprocessArgv($argv);

if (in_array('--sugared-debug', $argv)) {
$this->logDebug('Arguments', $argv);
}

return parent::run($argv, $exit);
}
}
40 changes: 40 additions & 0 deletions Command7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace SugaredRim\PHPUnit\TextUI;

use Schnittstabil\Get\Get;

class Command extends BaseCommand
{
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function handleArguments(array $argv): void
{
parent::handleArguments($argv);

if (Get::value('sugaredDebug', $this->arguments, false)) {
$this->logDebug('Parsed arguments', $this->arguments);
}

$this->addListeners();
}

/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function run(array $argv, $exit = true): int
{
$argv = $this->preprocessArgv($argv);

if (in_array('--sugared-debug', $argv)) {
$this->logDebug('Arguments', $argv);
}

return parent::run($argv, $exit);
}
}
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
"psr-4": { "SugaredRim\\PHPUnit\\": "tests" }
},
"require": {
"fool/echolog": "^1.0",
"phpunit/phpunit": "^5.0|^6.0",
"phpunit/phpunit": "^5.0 || ^6.0 || ^7.0",
"schnittstabil/composer-extra": "^2.0",
"schnittstabil/get": "^2.0"
"schnittstabil/get": "^2.0 || ^3.0"
},
"require-dev": {
"gamez/psr-testlogger": "^1.0",
"schnittstabil/phpunit-starter": "^6.0"
"gamez/psr-testlogger": "^1.0 || ^2.0",
"schnittstabil/phpunit-starter": "^6.0 || ^7.0"
},
"bin": [
"sugared-rim-phpunit"
Expand Down
98 changes: 98 additions & 0 deletions src/TextUI/BaseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace SugaredRim\PHPUnit\TextUI;

use Psr\Log\LoggerInterface;
use Schnittstabil\ComposerExtra\ComposerExtra;
use Schnittstabil\Get\Get;

class BaseCommand extends \PHPUnit\TextUI\Command
{
protected $argvRendererClass = Argv::class;
protected $namespace = 'sugared-rim/phpunit';
protected $defaultConfig;
protected $logger;
protected $config;

/**
* {@inheritdoc}
*/
public function __construct(LoggerInterface $logger = null)
{
$this->defaultConfig = new \stdClass();
$this->defaultConfig->presets = ['SugaredRim\\PHPUnit\\DefaultPreset::get'];

$this->logger = $logger;

$this->longOptions['sugared-coverage-text-show-uncovered-files']
= 'sugaredCoverageTextShowUncoveredFilesHandler';
$this->longOptions['sugared-debug'] = 'sugaredDebugHandler';
$this->longOptions['sugared-namespace='] = 'sugaredNamespaceHandler';
}

protected function logDebug($title, $value)
{
if ($this->logger !== null) {
$this->logger->debug($title.': '.json_encode($value, JSON_PRETTY_PRINT));
}
}

protected function sugaredCoverageTextShowUncoveredFilesHandler()
{
$this->arguments['coverageTextShowUncoveredFiles'] = true;
}

protected function sugaredDebugHandler()
{
$this->arguments['sugaredDebug'] = true;
}

protected function sugaredNamespaceHandler($namespace)
{
$this->namespace = $namespace;
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
protected function addListeners()
{
foreach ((array) $this->getConfig('sugared.listeners', []) as $listener) {
$class = Get::value('class', $listener);
$listenerClass = new \ReflectionClass($class);
$arguments = json_decode(json_encode(Get::value('arguments', $listener, [])), true);

$this->arguments['listeners'][] = $listenerClass->newInstanceArgs($arguments);
}
}

protected function getConfig($path = null, $default = null)
{
if ($this->config === null) {
$this->config = new ComposerExtra(
$this->namespace,
$this->defaultConfig,
'presets'
);
}

if ($path === null) {
$path = array();
}

return $this->config->get($path, $default);
}

protected function preprocessArgv(array $argv)
{
$config = $this->getConfig();

if (in_array('--sugared-debug', $argv)) {
$this->logDebug('Config', $config);
}

$argvRenderer = new $this->argvRendererClass($config);

return $argvRenderer($argv);
}
}
134 changes: 5 additions & 129 deletions src/TextUI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,134 +2,10 @@

namespace SugaredRim\PHPUnit\TextUI;

use Psr\Log\LoggerInterface;
use fool\echolog\Echolog;
use Schnittstabil\ComposerExtra\ComposerExtra;
use Schnittstabil\Get\Get;
use PHPUnit\Runner\Version;

class Command extends \PHPUnit\TextUI\Command
{
protected $argvRendererClass = Argv::class;
protected $namespace = 'sugared-rim/phpunit';
protected $defaultConfig;
protected $logger;
protected $config;

/**
* {@inheritdoc}
*/
public function __construct(LoggerInterface $logger = null)
{
// @codeCoverageIgnoreStart
if ($logger === null) {
$logger = new Echolog();
}
// @codeCoverageIgnoreEnd

$this->defaultConfig = new \stdClass();
$this->defaultConfig->presets = ['SugaredRim\\PHPUnit\\DefaultPreset::get'];

$this->logger = $logger;

$this->longOptions['sugared-coverage-text-show-uncovered-files']
= 'sugaredCoverageTextShowUncoveredFilesHandler';
$this->longOptions['sugared-debug'] = 'sugaredDebugHandler';
$this->longOptions['sugared-namespace='] = 'sugaredNamespaceHandler';
}

protected function logDebug($title, $value)
{
$this->logger->debug($title.': '.json_encode($value, JSON_PRETTY_PRINT));
}

protected function sugaredCoverageTextShowUncoveredFilesHandler()
{
$this->arguments['coverageTextShowUncoveredFiles'] = true;
}

protected function sugaredDebugHandler()
{
$this->arguments['sugaredDebug'] = true;
}

protected function sugaredNamespaceHandler($namespace)
{
$this->namespace = $namespace;
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
protected function addListeners()
{
foreach ((array) $this->getConfig('sugared.listeners', []) as $listener) {
$class = Get::value('class', $listener);
$listenerClass = new \ReflectionClass($class);
$arguments = json_decode(json_encode(Get::value('arguments', $listener, [])), true);

$this->arguments['listeners'][] = $listenerClass->newInstanceArgs($arguments);
}
}

/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function handleArguments(array $argv)
{
parent::handleArguments($argv);

if (Get::value('sugaredDebug', $this->arguments, false)) {
$this->logDebug('Parsed arguments', $this->arguments);
}

$this->addListeners();
}

protected function getConfig($path = null, $default = null)
{
if ($this->config === null) {
$this->config = new ComposerExtra(
$this->namespace,
$this->defaultConfig,
'presets'
);
}

if ($path === null) {
$path = array();
}

return $this->config->get($path, $default);
}

protected function preprocessArgv(array $argv)
{
$config = $this->getConfig();

if (in_array('--sugared-debug', $argv)) {
$this->logDebug('Config', $config);
}

$argvRenderer = new $this->argvRendererClass($config);

return $argvRenderer($argv);
}

/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function run(array $argv, $exit = true)
{
$argv = $this->preprocessArgv($argv);

if (in_array('--sugared-debug', $argv)) {
$this->logDebug('Arguments', $argv);
}

parent::run($argv, $exit);
}
if (version_compare(Version::id(), '7.0', '>=')) {
require_once __DIR__.'/../../Command7.php';
} else {
require_once __DIR__.'/../../Command6.php';
}
6 changes: 5 additions & 1 deletion sugared-rim-phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ foreach ([

unset($file);

require PHPUNIT_COMPOSER_INSTALL;
$loader = require PHPUNIT_COMPOSER_INSTALL;

if (!class_exists(\PHPUnit\TextUI\Command::class)) {
class_alias(\PHPUnit_TextUI_Command::class, \PHPUnit\TextUI\Command::class);
}

if (!class_exists(\PHPUnit\Runner\Version::class)) {
class_alias(\PHPUnit_Runner_Version::class, \PHPUnit\Runner\Version::class);
}

SugaredRim\PHPUnit\TextUI\Command::main();
Loading

0 comments on commit ca85b29

Please sign in to comment.