Skip to content

Commit

Permalink
bump dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
schnittstabil committed Mar 31, 2018
1 parent c106aba commit 69e2ee5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 36 deletions.
21 changes: 15 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@ language: php
php:
- 5.6
- 7
- 7.0
- 7.1
- 7.2
- hhvm

sudo: false

install:
- composer selfupdate
- composer install
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then composer global require --update-no-dev codeclimate/php-test-reporter fabpot/php-cs-fixer satooshi/php-coveralls sugared-rim/php_codesniffer:dev-master@dev; fi
- export PATH=$PATH:`composer global config bin-dir --absolute`
- |
if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then
composer require 'codeclimate/php-test-reporter:*' 'satooshi/php-coveralls:*'
else
composer install
fi
script:
- composer travis
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then composer lint; fi

after_success:
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then test-reporter; fi
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then coveralls -v; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then vendor/bin/test-reporter; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then vendor/bin/coveralls -v; fi

matrix:
allow_failures:
- php: hhvm

addons:
code_climate:
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
},
"require": {
"php": ">=5.6.0",
"schnittstabil/composer-extra": "^1.0",
"phpmd/phpmd": "^2.3",
"fool/echolog": "^1.0"
"psr/log": "^1.0",
"schnittstabil/composer-extra": "^1.0 || ^2.0"
},
"require-dev": {
"sugared-rim/phpunit": "^2.0",
"gamez/psr-testlogger": "^1.0"
"sugared-rim/phpunit": "^2.0 || ^6.0 || ^7.0"
},
"extra": {
"sugared-rim/phpmd invalid inputfile": {
Expand Down
25 changes: 18 additions & 7 deletions src/TextUI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@

namespace SugaredRim\PHPMD\TextUI;

use fool\echolog\Echolog;
use PHPMD\RuleSetFactory;
use PHPMD\TextUI\Command;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Schnittstabil\ComposerExtra\ComposerExtra;

class Application
{
protected $defaultNamespace = 'sugared-rim/phpmd';
protected $defaultConfig;
/**
* @var LoggerInterface
*/
protected $logger;

public function __construct(LoggerInterface $logger = null)
{
// @codeCoverageIgnoreStart
if ($logger === null) {
$logger = new Echolog();
}
// @codeCoverageIgnoreEnd
$this->logger = $logger;
$this->defaultConfig = new \stdClass();
$this->defaultConfig->presets = [
Expand Down Expand Up @@ -70,12 +68,25 @@ protected function runCommand(array $args)
return $command->run($options, $ruleSetFactory);
}

protected function log($level, $message)
{
// @codeCoverageIgnoreStart
if ($this->logger === null) {
$message = sprintf('[%s] %s %s', date('Y-m-d H:i:s'), strtoupper($level), $message);
echo $message;
flush();
return;
}
// @codeCoverageIgnoreEnd
$this->logger->log($level, $message);
}

public function main(array $args)
{
try {
$exitCode = $this->runCommand($args);
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
$this->log(LogLevel::ERROR, $e->getMessage());
$exitCode = Command::EXIT_EXCEPTION;
}

Expand Down
37 changes: 19 additions & 18 deletions tests/TextUI/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,50 @@

namespace SugaredRim\PHPMD\TextUI;

use Gamez\Psr\Log\TestLoggerTrait;
use Psr\Log\LogLevel;
use Psr\Log\LoggerInterface;
use PHPMD\TextUI\Command;
use VladaHejda\AssertException;

class ApplicationTest extends \PHPUnit_Framework_TestCase
class ApplicationTest extends \PHPUnit\Framework\TestCase
{
use TestLoggerTrait;

protected $logger;

protected function setUp()
{
$this->logger = $this->getTestLogger();
}

public function testMainShouldReturnNonZeroOnInvalidInputfile()
{
$sut = new Application($this->logger);
$logger = $this->createMock(LoggerInterface::class);

$logger->expects($this->once())
->method('log')
->withConsecutive([
$this->identicalTo(LogLevel::ERROR),
$this->matchesRegularExpression('/Input file \'.*\' not exists/i')
]);

$sut = new Application($logger);
$exitCode = $sut->main([
'-',
'--namespace=sugared-rim/phpmd invalid inputfile',
'tests/Fixtures/empty',
'text',
'cleancode',
]);
$log = implode(PHP_EOL, $this->logger->getRecords());

$this->assertSame(Command::EXIT_EXCEPTION, $exitCode);
$this->assertRegexp('/error Input file \'.*\' not exists/i', $log);
}

public function testMainShouldReturnSuccessOnDefaults()
{
$sut = new Application($this->logger);
$logger = $this->createMock(LoggerInterface::class);

$logger->expects($this->never())
->method('log');

$sut = new Application($logger);
$exitCode = $sut->main([
'-',
'tests/Fixtures/empty',
'text',
'cleancode',
]);
$log = implode(PHP_EOL, $this->logger->getRecords());

$this->assertSame(Command::EXIT_SUCCESS, $exitCode);
$this->assertSame('', $log);
}
}
4 changes: 3 additions & 1 deletion tests/TextUI/CommandLineOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use SugaredRim\PHPMD\DefaultPreset;

class CommandLineOptionsTest extends \PHPUnit_Framework_TestCase
class CommandLineOptionsTest extends \PHPUnit\Framework\TestCase
{
public function testCommandLineOptionsShouldThrowOnMissingRulesets()
{
Expand Down Expand Up @@ -34,6 +34,7 @@ public function testCommandLineOptionsShouldNotThrowOnValidInputFileOption()
$defaults->inputfile = __DIR__.'/../Fixtures/inputfile.txt';

new CommandLineOptions(['-', 'text', 'cleancode'], [], $defaults);
$this->assertTrue(true);
}

/**
Expand All @@ -42,5 +43,6 @@ public function testCommandLineOptionsShouldNotThrowOnValidInputFileOption()
public function testCommandLineOptionsShouldNotThrowOnDefaultOptions()
{
new CommandLineOptions(['-'], [], DefaultPreset::get());
$this->assertTrue(true);
}
}

0 comments on commit 69e2ee5

Please sign in to comment.