From 9919e4be9eec16c9c2de74c85d6d926d06e621a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Mon, 22 May 2017 19:01:53 +0200 Subject: [PATCH] apply and enforce kdyby/coding-standard --- .travis.yml | 6 +- composer.json | 8 +- ruleset.xml | 4 + src/CustomChannel.php | 150 +++++++----------- src/DI/MonologExtension.php | 71 ++++----- src/Handler/FallbackNetteHandler.php | 28 +--- src/Handler/NewRelicHandler.php | 15 +- src/Logger.php | 15 +- src/Processor/PriorityProcessor.php | 14 +- src/Processor/TracyExceptionProcessor.php | 12 +- src/Processor/TracyUrlProcessor.php | 10 +- src/Tracy/BlueScreenRenderer.php | 13 +- src/Tracy/MonologAdapter.php | 41 ++--- src/exceptions.php | 7 +- ...derer.phpt => BlueScreenRendererTest.phpt} | 15 +- .../{Extension.phpt => ExtensionTest.phpt} | 70 ++++---- ...ler.phpt => FallbackNetteHandlerTest.phpt} | 80 ++++------ ...ogAdapter.phpt => MonologAdapterTest.phpt} | 53 +++---- ...cessor.phpt => PriorityProcessorTest.phpt} | 16 +- ....phpt => TracyExceptionProcessorTest.phpt} | 21 +-- ...cessor.phpt => TracyUrlProcessorTest.phpt} | 25 +-- tests/KdybyTests/bootstrap.php | 22 ++- 22 files changed, 246 insertions(+), 450 deletions(-) create mode 100644 ruleset.xml rename tests/KdybyTests/Monolog/{BlueScreenRenderer.phpt => BlueScreenRendererTest.phpt} (56%) rename tests/KdybyTests/Monolog/{Extension.phpt => ExtensionTest.phpt} (66%) rename tests/KdybyTests/Monolog/{FallbackNetteHandler.phpt => FallbackNetteHandlerTest.phpt} (64%) rename tests/KdybyTests/Monolog/{MonologAdapter.phpt => MonologAdapterTest.phpt} (63%) rename tests/KdybyTests/Monolog/{PriorityProcessor.phpt => PriorityProcessorTest.phpt} (88%) rename tests/KdybyTests/Monolog/{TracyExceptionProcessor.phpt => TracyExceptionProcessorTest.phpt} (84%) rename tests/KdybyTests/Monolog/{TracyUrlProcessor.phpt => TracyUrlProcessorTest.phpt} (79%) diff --git a/.travis.yml b/.travis.yml index 84e3af6..16fee3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,8 @@ matrix: env: COMPOSER_EXTRA_ARGS="--prefer-stable" COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg" - php: 7.1 env: COMPOSER_EXTRA_ARGS="--prefer-stable" PHPSTAN=1 + - php: 7.1 + env: COMPOSER_EXTRA_ARGS="--prefer-stable" CODING_STANDARD=1 exclude: - php: 7.1 env: COMPOSER_EXTRA_ARGS="--prefer-stable" @@ -30,17 +32,17 @@ matrix: - env: install: + - if [ "$CODING_STANDARD" = "1" ]; then composer require --dev --no-update kdyby/coding-standard:^1.0@dev; fi - if [ "$PHPSTAN" = "1" ]; then composer require --dev --no-update phpstan/phpstan-shim:^0.7; fi - travis_retry composer update --no-interaction --no-suggest --no-progress --prefer-dist $COMPOSER_EXTRA_ARGS - travis_retry composer create-project --no-interaction jakub-onderka/php-parallel-lint /tmp/php-parallel-lint - - travis_retry composer create-project --no-interaction kdyby/code-checker /tmp/code-checker - if [ "$COVERAGE" != "" ]; then travis_retry wget -O /tmp/coveralls.phar https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar; fi script: - vendor/bin/tester $COVERAGE -s -p ${TESTER_RUNTIME:-php} -c ./tests/php.ini-unix ./tests/KdybyTests/ - php /tmp/php-parallel-lint/parallel-lint.php -e php,phpt --exclude vendor . - - php /tmp/code-checker/src/code-checker.php --short-arrays - if [ "$PHPSTAN" = "1" ]; then php vendor/phpstan/phpstan-shim/phpstan.phar analyse --ansi --no-progress -l7 -c phpstan.neon src tests/KdybyTests; fi + - if [ "$CODING_STANDARD" = "1" ]; then php vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 -sp src tests; fi after_script: - if [ "$COVERAGE" != "" ]; then php /tmp/coveralls.phar --verbose --config tests/.coveralls.yml || true; fi diff --git a/composer.json b/composer.json index e798125..8de9b70 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,9 @@ "require": { "php": "^5.6 || ^7.0", "nette/di": "^2.4@dev", - "tracy/tracy": "^2.4@dev", - "monolog/monolog": "^1.10" + "kdyby/strict-objects": "^1.0", + "monolog/monolog": "^1.10", + "tracy/tracy": "^2.4@dev" }, "require-dev": { "nette/application": "^2.4@dev", @@ -43,6 +44,9 @@ ] }, "autoload-dev": { + "psr-4": { + "KdybyTests\\": "tests/KdybyTests/" + }, "classmap": [ "tests/KdybyTests" ] diff --git a/ruleset.xml b/ruleset.xml new file mode 100644 index 0000000..bb0e2d8 --- /dev/null +++ b/ruleset.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/CustomChannel.php b/src/CustomChannel.php index ac0da6d..236f1a8 100644 --- a/src/CustomChannel.php +++ b/src/CustomChannel.php @@ -10,34 +10,25 @@ namespace Kdyby\Monolog; -use Kdyby; -use Monolog; +use Kdyby\Monolog\Logger as KdybyLogger; use Monolog\Handler\HandlerInterface; -use Nette; - - -/** - * @author Filip Procházka - */ -class CustomChannel extends Monolog\Logger +class CustomChannel extends \Monolog\Logger { + use \Kdyby\StrictObjects\Scream; + /** - * @var Logger + * @var \Kdyby\Monolog\Logger */ private $parentLogger; - - - public function __construct($name, Logger $parentLogger) + public function __construct($name, KdybyLogger $parentLogger) { parent::__construct($name, [], []); $this->parentLogger = $parentLogger; } - - /** * {@inheritdoc} */ @@ -46,30 +37,22 @@ public function pushHandler(HandlerInterface $handler) $this->parentLogger->pushHandler($handler); } - - /** * {@inheritdoc} - * @return HandlerInterface */ public function popHandler() { return $this->parentLogger->popHandler(); } - - /** * {@inheritdoc} - * @return HandlerInterface[] */ public function getHandlers() { return $this->parentLogger->getHandlers(); } - - /** * {@inheritdoc} */ @@ -78,10 +61,9 @@ public function pushProcessor($callback) $this->parentLogger->pushProcessor($callback); } - - /** * {@inheritdoc} + * * @return callable */ public function popProcessor() @@ -89,10 +71,9 @@ public function popProcessor() return $this->parentLogger->popProcessor(); } - - /** * {@inheritdoc} + * * @return callable[] */ public function getProcessors() @@ -100,253 +81,230 @@ public function getProcessors() return $this->parentLogger->getProcessors(); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addRecord($level, $message, array $context = []) { return $this->parentLogger->addRecord($level, $message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addDebug($message, array $context = []) { return $this->parentLogger->addDebug($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addInfo($message, array $context = []) { return $this->parentLogger->addInfo($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addNotice($message, array $context = []) { return $this->parentLogger->addNotice($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addWarning($message, array $context = []) { return $this->parentLogger->addWarning($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addError($message, array $context = []) { return $this->parentLogger->addError($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addCritical($message, array $context = []) { return $this->parentLogger->addCritical($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addAlert($message, array $context = []) { return $this->parentLogger->addAlert($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function addEmergency($message, array $context = []) { return $this->parentLogger->addEmergency($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function isHandling($level) { return $this->parentLogger->isHandling($level); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function log($level, $message, array $context = []) { return $this->parentLogger->log($level, $message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function debug($message, array $context = []) { return $this->parentLogger->debug($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function info($message, array $context = []) { return $this->parentLogger->info($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function notice($message, array $context = []) { return $this->parentLogger->notice($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function warn($message, array $context = []) { return $this->parentLogger->warn($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function warning($message, array $context = []) { return $this->parentLogger->warning($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function err($message, array $context = []) { return $this->parentLogger->err($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function error($message, array $context = []) { return $this->parentLogger->error($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function crit($message, array $context = []) { return $this->parentLogger->crit($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function critical($message, array $context = []) { return $this->parentLogger->critical($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function alert($message, array $context = []) { return $this->parentLogger->alert($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function emerg($message, array $context = []) { return $this->parentLogger->emerg($message, ['channel' => $this->name] + $context); } - - /** * {@inheritdoc} - * @return Boolean Whether the record has been processed + * + * @return bool Whether the record has been processed */ public function emergency($message, array $context = []) { diff --git a/src/DI/MonologExtension.php b/src/DI/MonologExtension.php index 2607dbb..0f3fc1c 100644 --- a/src/DI/MonologExtension.php +++ b/src/DI/MonologExtension.php @@ -10,31 +10,37 @@ namespace Kdyby\Monolog\DI; -use Nette; +use Kdyby\Monolog\Handler\FallbackNetteHandler; +use Kdyby\Monolog\Logger as KdybyLogger; +use Kdyby\Monolog\Processor\PriorityProcessor; +use Kdyby\Monolog\Processor\TracyExceptionProcessor; +use Kdyby\Monolog\Processor\TracyUrlProcessor; +use Kdyby\Monolog\Tracy\BlueScreenRenderer; +use Kdyby\Monolog\Tracy\MonologAdapter; use Nette\Configurator; use Nette\DI\Compiler; -use Nette\DI\CompilerExtension; +use Nette\DI\Helpers as DIHelpers; use Nette\DI\Statement; -use Nette\PhpGenerator as Code; -use Kdyby; +use Nette\PhpGenerator\ClassType as ClassTypeGenerator; +use Nette\PhpGenerator\PhpLiteral; use Psr\Log\LoggerAwareInterface; use Tracy\Debugger; - - /** * Integrates the Monolog seamlessly into your Nette Framework application. - * - * @author Martin Bažík - * @author Filip Procházka */ -class MonologExtension extends CompilerExtension +class MonologExtension extends \Nette\DI\CompilerExtension { + use \Kdyby\StrictObjects\Scream; + const TAG_HANDLER = 'monolog.handler'; const TAG_PROCESSOR = 'monolog.processor'; const TAG_PRIORITY = 'monolog.priority'; + /** + * @var mixed[] + */ private $defaults = [ 'handlers' => [], 'processors' => [], @@ -45,8 +51,6 @@ class MonologExtension extends CompilerExtension // 'registerFallback' => TRUE, ]; - - public function loadConfiguration() { $builder = $this->getContainerBuilder(); @@ -65,11 +69,11 @@ public function loadConfiguration() } $builder->addDefinition($this->prefix('logger')) - ->setClass(Kdyby\Monolog\Logger::class, [$config['name']]); + ->setClass(KdybyLogger::class, [$config['name']]); // Tracy adapter $builder->addDefinition($this->prefix('adapter')) - ->setClass(Kdyby\Monolog\Tracy\MonologAdapter::class, [ + ->setClass(MonologAdapter::class, [ 'monolog' => $this->prefix('@logger'), 'blueScreenRenderer' => $this->prefix('@blueScreenRenderer'), 'email' => Debugger::$email, @@ -78,7 +82,7 @@ public function loadConfiguration() // The renderer has to be separate, to solve circural service dependencies $builder->addDefinition($this->prefix('blueScreenRenderer')) - ->setClass(Kdyby\Monolog\Tracy\BlueScreenRenderer::class, [ + ->setClass(BlueScreenRenderer::class, [ 'directory' => $config['logDir'], ]) ->setAutowired(FALSE) @@ -94,8 +98,6 @@ public function loadConfiguration() $this->loadProcessors($config); } - - protected function loadHandlers(array $config) { $builder = $this->getContainerBuilder(); @@ -111,8 +113,6 @@ protected function loadHandlers(array $config) } } - - protected function loadProcessors(array $config) { $builder = $this->getContainerBuilder(); @@ -120,13 +120,13 @@ protected function loadProcessors(array $config) if ($config['usePriorityProcessor'] === TRUE) { // change channel name to priority if available $builder->addDefinition($this->prefix('processor.priorityProcessor')) - ->setClass(Kdyby\Monolog\Processor\PriorityProcessor::class) + ->setClass(PriorityProcessor::class) ->addTag(self::TAG_PROCESSOR) ->addTag(self::TAG_PRIORITY, 20); } $builder->addDefinition($this->prefix('processor.tracyException')) - ->setClass(Kdyby\Monolog\Processor\TracyExceptionProcessor::class, [ + ->setClass(TracyExceptionProcessor::class, [ 'blueScreenRenderer' => $this->prefix('@blueScreenRenderer'), ]) ->addTag(self::TAG_PROCESSOR) @@ -134,7 +134,7 @@ protected function loadProcessors(array $config) if ($config['tracyBaseUrl'] !== NULL) { $builder->addDefinition($this->prefix('processor.tracyBaseUrl')) - ->setClass(Kdyby\Monolog\Processor\TracyUrlProcessor::class, [ + ->setClass(TracyUrlProcessor::class, [ 'baseUrl' => $config['tracyBaseUrl'], 'blueScreenRenderer' => $this->prefix('@blueScreenRenderer'), ]) @@ -153,8 +153,6 @@ protected function loadProcessors(array $config) } } - - public function beforeCompile() { $builder = $this->getContainerBuilder(); @@ -172,10 +170,10 @@ public function beforeCompile() if ($config['registerFallback']) { $logger->addSetup('pushHandler', [ - new Statement(Kdyby\Monolog\Handler\FallbackNetteHandler::class, [ + new Statement(FallbackNetteHandler::class, [ 'appName' => $config['name'], - 'logDir' => $config['logDir'] - ]) + 'logDir' => $config['logDir'], + ]), ]); } @@ -184,8 +182,6 @@ public function beforeCompile() } } - - protected function findByTagSorted($tag) { $builder = $this->getContainerBuilder(); @@ -200,20 +196,15 @@ protected function findByTagSorted($tag) return $services; } - - - public function afterCompile(Code\ClassType $class) + public function afterCompile(ClassTypeGenerator $class) { - $builder = $this->getContainerBuilder(); $initialize = $class->getMethod('initialize'); if (empty(Debugger::$logDirectory)) { - $initialize->addBody('?::$logDirectory = ?;', [new Code\PhpLiteral(Debugger::class), $this->config['logDir']]); + $initialize->addBody('?::$logDirectory = ?;', [new PhpLiteral(Debugger::class), $this->config['logDir']]); } } - - public static function register(Configurator $configurator) { $configurator->onCompile[] = function ($config, Compiler $compiler) { @@ -221,26 +212,22 @@ public static function register(Configurator $configurator) }; } - - /** * @return string */ private static function resolveLogDir(array $parameters) { if (isset($parameters['logDir'])) { - return Nette\DI\Helpers::expand('%logDir%', $parameters); + return DIHelpers::expand('%logDir%', $parameters); } if (Debugger::$logDirectory !== NULL) { return Debugger::$logDirectory; } - return Nette\DI\Helpers::expand('%appDir%/../log', $parameters); + return DIHelpers::expand('%appDir%/../log', $parameters); } - - /** * @param string $logDir */ diff --git a/src/Handler/FallbackNetteHandler.php b/src/Handler/FallbackNetteHandler.php index 60aab1e..40ecb22 100644 --- a/src/Handler/FallbackNetteHandler.php +++ b/src/Handler/FallbackNetteHandler.php @@ -10,24 +10,18 @@ namespace Kdyby\Monolog\Handler; -use Kdyby; -use Monolog; use Monolog\Formatter\LineFormatter; -use Monolog\Handler\ErrorLogHandler; -use Nette; - - +use Monolog\Logger as MonologLogger; /** * If you have no custom handlers that will write and/or send your messages somewhere, * this one will just write them to the log/ directory, just like the default Tracy logger does. - * - * @author Elan Ruusamäe - * @author Filip Procházka */ -class FallbackNetteHandler extends ErrorLogHandler +class FallbackNetteHandler extends \Monolog\Handler\ErrorLogHandler { + use \Kdyby\StrictObjects\Scream; + /** * @var string */ @@ -39,18 +33,16 @@ class FallbackNetteHandler extends ErrorLogHandler private $logDir; /** - * @var LineFormatter + * @var \Monolog\Formatter\LineFormatter */ private $defaultFormatter; /** - * @var LineFormatter + * @var \Monolog\Formatter\LineFormatter */ private $priorityFormatter; - - - public function __construct($appName, $logDir, $expandNewlines = FALSE, $level = Monolog\Logger::DEBUG) + public function __construct($appName, $logDir, $expandNewlines = FALSE, $level = MonologLogger::DEBUG) { parent::__construct(self::SAPI, $level, TRUE, $expandNewlines); $this->appName = $appName; @@ -60,8 +52,6 @@ public function __construct($appName, $logDir, $expandNewlines = FALSE, $level = $this->priorityFormatter = new LineFormatter('[%datetime%] %level_name%: %message% %context% %extra%'); } - - public function handle(array $record) { if ($record['channel'] === $this->appName) { @@ -76,8 +66,6 @@ public function handle(array $record) return parent::handle($record); } - - /** * {@inheritdoc} */ @@ -95,7 +83,7 @@ protected function write(array $record) $file = $this->logDir . '/' . strtolower($record['filename'] ?: 'info') . '.log'; if (!@file_put_contents($file, $entry, FILE_APPEND | LOCK_EX)) { - throw new \RuntimeException("Unable to write to log file '$file'. Is directory writable?"); + throw new \RuntimeException(sprintf('Unable to write to log file %s. Is directory writable?', $file)); } } diff --git a/src/Handler/NewRelicHandler.php b/src/Handler/NewRelicHandler.php index 0cf2e1e..5255274 100644 --- a/src/Handler/NewRelicHandler.php +++ b/src/Handler/NewRelicHandler.php @@ -10,18 +10,11 @@ namespace Kdyby\Monolog\Handler; -use Kdyby; -use Monolog; -use Nette; - - - -/** - * @author Filip Procházka - */ -class NewRelicHandler extends Monolog\Handler\NewRelicHandler +class NewRelicHandler extends \Monolog\Handler\NewRelicHandler { + use \Kdyby\StrictObjects\Scream; + /** * {@inheritdoc} */ @@ -34,8 +27,6 @@ protected function write(array $record) parent::write($record); } - - /** * {@inheritdoc} */ diff --git a/src/Logger.php b/src/Logger.php index c12db6c..2959d3d 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -10,21 +10,14 @@ namespace Kdyby\Monolog; -use Kdyby; -use Monolog; -use Nette; - - - -/** - * @author Filip Procházka - */ -class Logger extends Monolog\Logger +class Logger extends \Monolog\Logger { + use \Kdyby\StrictObjects\Scream; + /** * @param string $channel - * @return CustomChannel + * @return \Kdyby\Monolog\CustomChannel */ public function channel($channel) { diff --git a/src/Processor/PriorityProcessor.php b/src/Processor/PriorityProcessor.php index 6e14252..05c17dc 100644 --- a/src/Processor/PriorityProcessor.php +++ b/src/Processor/PriorityProcessor.php @@ -10,21 +10,17 @@ namespace Kdyby\Monolog\Processor; -use Kdyby; -use Monolog\Logger; -use Nette; - - +use Monolog\Logger as MonologLogger; /** * Helps you change the channel name of the record, * when you wanna have multiple log files coming out of your application. - * - * @author Filip Procházka */ -class PriorityProcessor extends Nette\Object +class PriorityProcessor { + use \Kdyby\StrictObjects\Scream; + public function __invoke($record) { if (isset($record['context']['channel'])) { @@ -33,7 +29,7 @@ public function __invoke($record) } elseif (isset($record['context']['priority'])) { $rename = strtoupper($record['context']['priority']); - if (!array_key_exists($rename, Logger::getLevels())) { + if (!array_key_exists($rename, MonologLogger::getLevels())) { $record['channel'] = strtolower($rename); } unset($record['context']['priority']); diff --git a/src/Processor/TracyExceptionProcessor.php b/src/Processor/TracyExceptionProcessor.php index bb97a9d..c2ad54a 100644 --- a/src/Processor/TracyExceptionProcessor.php +++ b/src/Processor/TracyExceptionProcessor.php @@ -12,25 +12,21 @@ use Kdyby\Monolog\Tracy\BlueScreenRenderer; - - class TracyExceptionProcessor { + use \Kdyby\StrictObjects\Scream; + /** * @var \Kdyby\Monolog\Tracy\BlueScreenRenderer */ private $blueScreenRenderer; - - public function __construct(BlueScreenRenderer $blueScreenRenderer) { $this->blueScreenRenderer = $blueScreenRenderer; } - - public function __invoke(array $record) { if (!$this->isHandling($record)) { @@ -43,14 +39,12 @@ public function __invoke(array $record) if (!file_exists($filename)) { $this->blueScreenRenderer->renderToFile($exception, $filename); - $record['context']['tracy_created'] = true; + $record['context']['tracy_created'] = TRUE; } return $record; } - - public function isHandling(array $record) { return !isset($record['context']['tracy']) diff --git a/src/Processor/TracyUrlProcessor.php b/src/Processor/TracyUrlProcessor.php index 6a799c8..3734e9e 100644 --- a/src/Processor/TracyUrlProcessor.php +++ b/src/Processor/TracyUrlProcessor.php @@ -12,11 +12,11 @@ use Kdyby\Monolog\Tracy\BlueScreenRenderer; - - class TracyUrlProcessor { + use \Kdyby\StrictObjects\Scream; + /** * @var string */ @@ -27,16 +27,12 @@ class TracyUrlProcessor */ private $blueScreenRenderer; - - public function __construct($baseUrl, BlueScreenRenderer $blueScreenRenderer) { $this->baseUrl = rtrim($baseUrl, '/'); $this->blueScreenRenderer = $blueScreenRenderer; } - - public function __invoke(array $record) { if ($this->isHandling($record)) { @@ -47,8 +43,6 @@ public function __invoke(array $record) return $record; } - - public function isHandling(array $record) { return isset($record['context']['exception']) diff --git a/src/Tracy/BlueScreenRenderer.php b/src/Tracy/BlueScreenRenderer.php index cf8618c..1583584 100644 --- a/src/Tracy/BlueScreenRenderer.php +++ b/src/Tracy/BlueScreenRenderer.php @@ -11,20 +11,17 @@ namespace Kdyby\Monolog\Tracy; use Tracy\BlueScreen; -use Tracy\Logger; - - -class BlueScreenRenderer extends Logger +class BlueScreenRenderer extends \Tracy\Logger { + use \Kdyby\StrictObjects\Scream; + public function __construct($directory, BlueScreen $blueScreen) { parent::__construct($directory, NULL, $blueScreen); } - - /** * @param \Exception|\Throwable $exception * @param string $file @@ -35,8 +32,6 @@ public function renderToFile($exception, $file) return parent::logException($exception, $file); } - - /** * @internal * @deprecated @@ -46,8 +41,6 @@ public function log($message, $priority = self::INFO) throw new \Kdyby\Monolog\NotSupportedException('This class is only for rendering exceptions'); } - - /** * @internal * @deprecated diff --git a/src/Tracy/MonologAdapter.php b/src/Tracy/MonologAdapter.php index 7114832..2269a60 100644 --- a/src/Tracy/MonologAdapter.php +++ b/src/Tracy/MonologAdapter.php @@ -10,34 +10,30 @@ namespace Kdyby\Monolog\Tracy; -use Monolog; +use Monolog\Logger as MonologLogger; use Tracy\Helpers; -use Tracy\Logger; - - /** * Replaces the default Tracy logger, * which allows to preprocess all messages and pass then to Monolog for processing. - * - * @author Martin Bažík - * @author Filip Procházka */ -class MonologAdapter extends Logger +class MonologAdapter extends \Tracy\Logger { + use \Kdyby\StrictObjects\Scream; + const ACCESS = 'access'; /** - * @var array + * @var int[] */ private $priorityMap = [ - self::DEBUG => Monolog\Logger::DEBUG, - self::INFO => Monolog\Logger::INFO, - self::WARNING => Monolog\Logger::WARNING, - self::ERROR => Monolog\Logger::ERROR, - self::EXCEPTION => Monolog\Logger::CRITICAL, - self::CRITICAL => Monolog\Logger::CRITICAL + self::DEBUG => MonologLogger::DEBUG, + self::INFO => MonologLogger::INFO, + self::WARNING => MonologLogger::WARNING, + self::ERROR => MonologLogger::ERROR, + self::EXCEPTION => MonologLogger::CRITICAL, + self::CRITICAL => MonologLogger::CRITICAL, ]; /** @@ -50,10 +46,8 @@ class MonologAdapter extends Logger */ private $blueScreenRenderer; - - public function __construct( - Monolog\Logger $monolog, + MonologLogger $monolog, BlueScreenRenderer $blueScreenRenderer, $email = NULL ) @@ -63,8 +57,6 @@ public function __construct( $this->blueScreenRenderer = $blueScreenRenderer; } - - /** * {@inheritdoc} */ @@ -73,8 +65,6 @@ public function getExceptionFile($exception) return $this->blueScreenRenderer->getExceptionFile($exception); } - - public function log($originalMessage, $priority = self::INFO) { $message = $this->formatMessage($originalMessage); @@ -96,7 +86,7 @@ public function log($originalMessage, $priority = self::INFO) @date('[Y-m-d H-i-s]'), $message, ' @ ' . Helpers::getSource(), - ($exceptionFile !== NULL) ? ' @@ ' . basename($exceptionFile) : NULL + ($exceptionFile !== NULL) ? ' @@ ' . basename($exceptionFile) : NULL, ])); } @@ -116,7 +106,6 @@ public function log($originalMessage, $priority = self::INFO) return $exceptionFile; } - /** * @param string $priority * @return int @@ -127,8 +116,8 @@ protected function getLevel($priority) return $this->priorityMap[$priority]; } - $levels = Monolog\Logger::getLevels(); - return isset($levels[$uPriority = strtoupper($priority)]) ? $levels[$uPriority] : Monolog\Logger::INFO; + $levels = MonologLogger::getLevels(); + return isset($levels[$uPriority = strtoupper($priority)]) ? $levels[$uPriority] : MonologLogger::INFO; } } diff --git a/src/exceptions.php b/src/exceptions.php index 485641c..f3fba66 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -15,12 +15,7 @@ interface Exception } - - -/** - * @author Filip Procházka - */ -class NotSupportedException extends \LogicException implements Exception +class NotSupportedException extends \LogicException implements \Kdyby\Monolog\Exception { } diff --git a/tests/KdybyTests/Monolog/BlueScreenRenderer.phpt b/tests/KdybyTests/Monolog/BlueScreenRendererTest.phpt similarity index 56% rename from tests/KdybyTests/Monolog/BlueScreenRenderer.phpt rename to tests/KdybyTests/Monolog/BlueScreenRendererTest.phpt index fbbad27..57a6999 100644 --- a/tests/KdybyTests/Monolog/BlueScreenRenderer.phpt +++ b/tests/KdybyTests/Monolog/BlueScreenRendererTest.phpt @@ -3,27 +3,18 @@ /** * Test: Kdyby\Monolog\MonologAdapter. * - * @testCase KdybyTests\Monolog\MonologAdapterTest - * @author Filip Procházka - * @package Kdyby\Monolog + * @testCase */ namespace KdybyTests\Monolog; -use Kdyby; use Kdyby\Monolog\Tracy\BlueScreenRenderer; -use Tester; use Tester\Assert; use Tracy\BlueScreen; require_once __DIR__ . '/../bootstrap.php'; - - -/** - * @author Filip Procházka - */ -class BlueScreenRendererTest extends Tester\TestCase +class BlueScreenRendererTest extends \Tester\TestCase { public function testLogginIsNotSupported() @@ -32,7 +23,7 @@ class BlueScreenRendererTest extends Tester\TestCase Assert::exception(function () use ($renderer) { $renderer->log('message'); - }, Kdyby\Monolog\NotSupportedException::class, 'This class is only for rendering exceptions'); + }, \Kdyby\Monolog\NotSupportedException::class, 'This class is only for rendering exceptions'); } } diff --git a/tests/KdybyTests/Monolog/Extension.phpt b/tests/KdybyTests/Monolog/ExtensionTest.phpt similarity index 66% rename from tests/KdybyTests/Monolog/Extension.phpt rename to tests/KdybyTests/Monolog/ExtensionTest.phpt index 59ccb38..249d3ab 100644 --- a/tests/KdybyTests/Monolog/Extension.phpt +++ b/tests/KdybyTests/Monolog/ExtensionTest.phpt @@ -3,31 +3,29 @@ /** * Test: Kdyby\Monolog\Extension. * - * @testCase KdybyTests\Monolog\ExtensionTest - * @author Filip Procházka - * @package Kdyby\Monolog + * @testCase */ namespace KdybyTests\Monolog; -use Kdyby; -use KdybyTests; -use Monolog; -use Nette; -use Tester; +use Kdyby\Monolog\DI\MonologExtension; +use Kdyby\Monolog\Processor\PriorityProcessor; +use Kdyby\Monolog\Processor\TracyExceptionProcessor; +use Kdyby\Monolog\Processor\TracyUrlProcessor; +use Monolog\Handler\BrowserConsoleHandler; +use Monolog\Handler\ChromePHPHandler; +use Monolog\Handler\NewRelicHandler; +use Monolog\Logger as MonologLogger; +use Monolog\Processor\GitProcessor; +use Monolog\Processor\ProcessIdProcessor; +use Monolog\Processor\WebProcessor; +use Nette\Configurator; use Tester\Assert; use Tracy\Debugger; - - require_once __DIR__ . '/../bootstrap.php'; - - -/** - * @author Filip Procházka - */ -class ExtensionTest extends Tester\TestCase +class ExtensionTest extends \Tester\TestCase { /** @@ -35,9 +33,9 @@ class ExtensionTest extends Tester\TestCase */ protected function createContainer($configName = NULL) { - $config = new Nette\Configurator(); + $config = new Configurator(); $config->setTempDirectory(TEMP_DIR); - Kdyby\Monolog\DI\MonologExtension::register($config); + MonologExtension::register($config); $config->addConfig(__DIR__ . '/../nette-reset.neon'); if ($configName !== NULL) { @@ -47,16 +45,12 @@ class ExtensionTest extends Tester\TestCase return $config->createContainer(); } - - public function testServices() { $dic = $this->createContainer(); - Assert::true($dic->getService('monolog.logger') instanceof Monolog\Logger); + Assert::true($dic->getService('monolog.logger') instanceof MonologLogger); } - - public function testFunctional() { foreach (array_merge(glob(TEMP_DIR . '/*.log'), glob(TEMP_DIR . '/*.html')) as $logFile) { @@ -66,8 +60,8 @@ class ExtensionTest extends Tester\TestCase Debugger::$logDirectory = TEMP_DIR; $dic = $this->createContainer(); - /** @var Monolog\Logger $logger */ - $logger = $dic->getByType(Monolog\Logger::class); + /** @var \Monolog\Logger $logger */ + $logger = $dic->getByType(MonologLogger::class); Debugger::log('tracy message 1'); Debugger::log('tracy message 2', 'error'); @@ -111,33 +105,29 @@ class ExtensionTest extends Tester\TestCase Assert::count(3, glob(TEMP_DIR . '/exception-*.html')); } - - public function testHandlersSorting() { $dic = $this->createContainer('handlers'); - $logger = $dic->getByType(Monolog\Logger::class); + $logger = $dic->getByType(MonologLogger::class); $handlers = $logger->getHandlers(); Assert::count(3, $handlers); - Assert::type(Monolog\Handler\NewRelicHandler::class, array_shift($handlers)); - Assert::type(Monolog\Handler\ChromePHPHandler::class, array_shift($handlers)); - Assert::type(Monolog\Handler\BrowserConsoleHandler::class, array_shift($handlers)); + Assert::type(NewRelicHandler::class, array_shift($handlers)); + Assert::type(ChromePHPHandler::class, array_shift($handlers)); + Assert::type(BrowserConsoleHandler::class, array_shift($handlers)); } - - public function testProcessorsSorting() { $dic = $this->createContainer('processors'); - $logger = $dic->getByType(Monolog\Logger::class); + $logger = $dic->getByType(MonologLogger::class); $processors = $logger->getProcessors(); Assert::count(6, $processors); - Assert::type(Kdyby\Monolog\Processor\TracyExceptionProcessor::class, array_shift($processors)); - Assert::type(Kdyby\Monolog\Processor\PriorityProcessor::class, array_shift($processors)); - Assert::type(Kdyby\Monolog\Processor\TracyUrlProcessor::class, array_shift($processors)); - Assert::type(Monolog\Processor\WebProcessor::class, array_shift($processors)); - Assert::type(Monolog\Processor\ProcessIdProcessor::class, array_shift($processors)); - Assert::type(Monolog\Processor\GitProcessor::class, array_shift($processors)); + Assert::type(TracyExceptionProcessor::class, array_shift($processors)); + Assert::type(PriorityProcessor::class, array_shift($processors)); + Assert::type(TracyUrlProcessor::class, array_shift($processors)); + Assert::type(WebProcessor::class, array_shift($processors)); + Assert::type(ProcessIdProcessor::class, array_shift($processors)); + Assert::type(GitProcessor::class, array_shift($processors)); } } diff --git a/tests/KdybyTests/Monolog/FallbackNetteHandler.phpt b/tests/KdybyTests/Monolog/FallbackNetteHandlerTest.phpt similarity index 64% rename from tests/KdybyTests/Monolog/FallbackNetteHandler.phpt rename to tests/KdybyTests/Monolog/FallbackNetteHandlerTest.phpt index db6c25e..ce6a7bb 100644 --- a/tests/KdybyTests/Monolog/FallbackNetteHandler.phpt +++ b/tests/KdybyTests/Monolog/FallbackNetteHandlerTest.phpt @@ -3,33 +3,23 @@ /** * Test: Kdyby\Monolog\FallbackNetteHandler. * - * @testCase KdybyTests\Monolog\FallbackNetteHandlerTest - * @author Filip Procházka - * @package Kdyby\Monolog + * @testCase */ namespace KdybyTests\Monolog; -use Kdyby; +use DateTime; use Kdyby\Monolog\Handler\FallbackNetteHandler; -use Monolog; -use Monolog\Formatter\NormalizerFormatter; -use Nette; -use Tester; +use Monolog\Logger as MonologLogger; use Tester\Assert; require_once __DIR__ . '/../bootstrap.php'; - - -/** - * @author Filip Procházka - */ -class FallbackNetteHandlerTest extends Tester\TestCase +class FallbackNetteHandlerTest extends \Tester\TestCase { /** - * @var FallbackNetteHandler + * @var \Kdyby\Monolog\Handler\FallbackNetteHandler */ private $handler; @@ -43,8 +33,6 @@ class FallbackNetteHandlerTest extends Tester\TestCase */ private $logDir; - - protected function setUp() { $this->logDir = TEMP_DIR . '/log_' . getmypid() . '_' . number_format(microtime(TRUE), 6, '+', ''); @@ -56,34 +44,30 @@ class FallbackNetteHandlerTest extends Tester\TestCase $this->handler = new FallbackNetteHandler('kdyby', $this->logDir); - $this->now = new \DateTime(); + $this->now = new DateTime(); } - - - public function dataWrite_standardLevels() + public function dataWriteStandardLevels() { return [ - [Monolog\Logger::DEBUG, 'debug'], - [Monolog\Logger::INFO, 'info'], - [Monolog\Logger::NOTICE, 'notice'], - [Monolog\Logger::WARNING, 'warning'], - [Monolog\Logger::ERROR, 'error'], - [Monolog\Logger::CRITICAL, 'critical'], - [Monolog\Logger::ALERT, 'alert'], - [Monolog\Logger::EMERGENCY, 'emergency'], + [MonologLogger::DEBUG, 'debug'], + [MonologLogger::INFO, 'info'], + [MonologLogger::NOTICE, 'notice'], + [MonologLogger::WARNING, 'warning'], + [MonologLogger::ERROR, 'error'], + [MonologLogger::CRITICAL, 'critical'], + [MonologLogger::ALERT, 'alert'], + [MonologLogger::EMERGENCY, 'emergency'], ]; } - - /** - * @dataProvider dataWrite_standardLevels + * @dataProvider dataWriteStandardLevels */ - public function testWrite_standardLevels($level, $levelName) + public function testWriteStandardLevels($level, $levelName) { $this->handler->handle([ - 'message' => "test message", + 'message' => 'test message', 'context' => [], 'level' => $level, 'level_name' => strtoupper($levelName), @@ -98,14 +82,12 @@ class FallbackNetteHandlerTest extends Tester\TestCase ); } - - - public function testWrite_customChannel() + public function testWriteCustomChannel() { $this->handler->handle([ - 'message' => "test message", + 'message' => 'test message', 'context' => [], - 'level' => Monolog\Logger::INFO, + 'level' => MonologLogger::INFO, 'level_name' => 'INFO', 'channel' => 'nemam', 'datetime' => $this->now, @@ -113,9 +95,9 @@ class FallbackNetteHandlerTest extends Tester\TestCase ]); $this->handler->handle([ - 'message' => "test message", + 'message' => 'test message', 'context' => [], - 'level' => Monolog\Logger::WARNING, + 'level' => MonologLogger::WARNING, 'level_name' => 'WARNING', 'channel' => 'nemam', 'datetime' => $this->now, @@ -129,14 +111,12 @@ class FallbackNetteHandlerTest extends Tester\TestCase ); } - - - public function testWrite_contextAsJson() + public function testWriteContextAsJson() { $this->handler->handle([ - 'message' => "test message", + 'message' => 'test message', 'context' => ['at' => 'http://www.kdyby.org', 'tracy' => 'exception-2014-08-14-11-11-26-88167e58be9dc0dfd12a61b3d8d33838.html'], - 'level' => Monolog\Logger::INFO, + 'level' => MonologLogger::INFO, 'level_name' => 'INFO', 'channel' => 'custom', 'datetime' => $this->now, @@ -149,14 +129,12 @@ class FallbackNetteHandlerTest extends Tester\TestCase ); } - - - public function testWrite_extraAsJson() + public function testWriteExtraAsJson() { $this->handler->handle([ - 'message' => "test message", + 'message' => 'test message', 'context' => [], - 'level' => Monolog\Logger::INFO, + 'level' => MonologLogger::INFO, 'level_name' => 'INFO', 'channel' => 'custom', 'datetime' => $this->now, diff --git a/tests/KdybyTests/Monolog/MonologAdapter.phpt b/tests/KdybyTests/Monolog/MonologAdapterTest.phpt similarity index 63% rename from tests/KdybyTests/Monolog/MonologAdapter.phpt rename to tests/KdybyTests/Monolog/MonologAdapterTest.phpt index d92b946..868371b 100644 --- a/tests/KdybyTests/Monolog/MonologAdapter.phpt +++ b/tests/KdybyTests/Monolog/MonologAdapterTest.phpt @@ -3,64 +3,51 @@ /** * Test: Kdyby\Monolog\MonologAdapter. * - * @testCase KdybyTests\Monolog\MonologAdapterTest - * @author Filip Procházka - * @package Kdyby\Monolog + * @testCase */ namespace KdybyTests\Monolog; -use Kdyby; +use DateTimeInterface; +use Kdyby\Monolog\Tracy\BlueScreenRenderer; use Kdyby\Monolog\Tracy\MonologAdapter; use Monolog\Handler\TestHandler; -use Monolog\Logger; -use Nette; -use Tester; +use Monolog\Logger as MonologLogger; use Tester\Assert; use Tracy\BlueScreen; - - require_once __DIR__ . '/../bootstrap.php'; - - -/** - * @author Filip Procházka - */ -class MonologAdapterTest extends Tester\TestCase +class MonologAdapterTest extends \Tester\TestCase { /** - * @var MonologAdapter + * @var \Kdyby\Monolog\Tracy\MonologAdapter */ protected $adapter; /** - * @var Logger + * @var \Monolog\Logger */ protected $monolog; /** - * @var TestHandler + * @var \Monolog\Handler\TestHandler */ protected $testHandler; - - protected function setUp() { - $this->monolog = new Logger('kdyby', [$this->testHandler = new TestHandler()]); - $blueScreenRenderer = new Kdyby\Monolog\Tracy\BlueScreenRenderer(TEMP_DIR, new BlueScreen()); + $this->testHandler = new TestHandler(); + $this->monolog = new MonologLogger('kdyby', [$this->testHandler]); + $blueScreenRenderer = new BlueScreenRenderer(TEMP_DIR, new BlueScreen()); $this->adapter = new MonologAdapter($this->monolog, $blueScreenRenderer); } - - /** * @return array */ - public function dataLog_standard() + public function dataLogStandard() { return [ ['test message 1', 'debug'], @@ -74,12 +61,10 @@ class MonologAdapterTest extends Tester\TestCase ]; } - - /** - * @dataProvider dataLog_standard + * @dataProvider dataLogStandard */ - public function testLog_standard($message, $priority) + public function testLogStandard($message, $priority) { Assert::count(0, $this->testHandler->getRecords()); $this->adapter->log($message, $priority); @@ -90,13 +75,11 @@ class MonologAdapterTest extends Tester\TestCase Assert::same($message, $record['message']); Assert::same(strtoupper($priority), $record['level_name']); Assert::same($priority, $record['context']['priority']); - Assert::type(\DateTimeInterface::class, $record['datetime']); - Assert::match('CLI%a%: %a%/MonologAdapter.phpt%a%', $record['context']['at']); + Assert::type(DateTimeInterface::class, $record['datetime']); + Assert::match('CLI%a%: %a%/MonologAdapterTest.phpt%a%', $record['context']['at']); } - - - public function testLog_withCustomPriority() + public function testLogWithCustomPriority() { $this->adapter->log('test message', 'nemam'); Assert::count(1, $this->testHandler->getRecords()); @@ -106,7 +89,7 @@ class MonologAdapterTest extends Tester\TestCase Assert::same('test message', $record['message']); Assert::same('INFO', $record['level_name']); Assert::same('nemam', $record['context']['priority']); - Assert::match('CLI%a%: %a%/MonologAdapter.phpt%a%', $record['context']['at']); + Assert::match('CLI%a%: %a%/MonologAdapterTest.phpt%a%', $record['context']['at']); } } diff --git a/tests/KdybyTests/Monolog/PriorityProcessor.phpt b/tests/KdybyTests/Monolog/PriorityProcessorTest.phpt similarity index 88% rename from tests/KdybyTests/Monolog/PriorityProcessor.phpt rename to tests/KdybyTests/Monolog/PriorityProcessorTest.phpt index 4132431..ee5fd98 100644 --- a/tests/KdybyTests/Monolog/PriorityProcessor.phpt +++ b/tests/KdybyTests/Monolog/PriorityProcessorTest.phpt @@ -3,27 +3,17 @@ /** * Test: Kdyby\Monolog\PriorityProcessor. * - * @testCase KdybyTests\Monolog\PriorityProcessorTest - * @author Filip Procházka - * @package Kdyby\Monolog + * @testCase */ namespace KdybyTests\Monolog; -use Kdyby; use Kdyby\Monolog\Processor\PriorityProcessor; -use Nette; -use Tester; use Tester\Assert; require_once __DIR__ . '/../bootstrap.php'; - - -/** - * @author Filip Procházka - */ -class PriorityProcessorTest extends Tester\TestCase +class PriorityProcessorTest extends \Tester\TestCase { public function dataFunctional() @@ -86,8 +76,6 @@ class PriorityProcessorTest extends Tester\TestCase ]; } - - /** * @dataProvider dataFunctional */ diff --git a/tests/KdybyTests/Monolog/TracyExceptionProcessor.phpt b/tests/KdybyTests/Monolog/TracyExceptionProcessorTest.phpt similarity index 84% rename from tests/KdybyTests/Monolog/TracyExceptionProcessor.phpt rename to tests/KdybyTests/Monolog/TracyExceptionProcessorTest.phpt index a83e961..b7caacf 100644 --- a/tests/KdybyTests/Monolog/TracyExceptionProcessor.phpt +++ b/tests/KdybyTests/Monolog/TracyExceptionProcessorTest.phpt @@ -3,30 +3,19 @@ /** * Test: Kdyby\Monolog\Processor\TracyExceptionProcessor. * - * @testCase KdybyTests\Monolog\TracyExceptionProcessor - * @author Filip Procházka - * @package Kdyby\Monolog + * @testCase */ namespace KdybyTests\Monolog; -use Kdyby; use Kdyby\Monolog\Processor\TracyExceptionProcessor; use Kdyby\Monolog\Tracy\BlueScreenRenderer; -use Tester; use Tester\Assert; use Tracy\BlueScreen; - - require_once __DIR__ . '/../bootstrap.php'; - - -/** - * @author Filip Procházka - */ -class TracyExceptionProcessorTest extends Tester\TestCase +class TracyExceptionProcessorTest extends \Tester\TestCase { /** @@ -34,15 +23,11 @@ class TracyExceptionProcessorTest extends Tester\TestCase */ private $processor; - - protected function setUp() { $this->processor = new TracyExceptionProcessor(new BlueScreenRenderer(TEMP_DIR, new BlueScreen())); } - - public function testIgnoreAlreadyProcessed() { $exception = new \RuntimeException('ignore me please'); @@ -57,8 +42,6 @@ class TracyExceptionProcessorTest extends Tester\TestCase Assert::same($record, $updatedRecord); } - - public function testLogBlueScreenFromContext() { $exception = new \RuntimeException('message'); diff --git a/tests/KdybyTests/Monolog/TracyUrlProcessor.phpt b/tests/KdybyTests/Monolog/TracyUrlProcessorTest.phpt similarity index 79% rename from tests/KdybyTests/Monolog/TracyUrlProcessor.phpt rename to tests/KdybyTests/Monolog/TracyUrlProcessorTest.phpt index 2b6ad0a..ff709b0 100644 --- a/tests/KdybyTests/Monolog/TracyUrlProcessor.phpt +++ b/tests/KdybyTests/Monolog/TracyUrlProcessorTest.phpt @@ -3,50 +3,37 @@ /** * Test: Kdyby\Monolog\Processor\TracyUrlProcessor. * - * @testCase KdybyTests\Monolog\TracyUrlProcessor - * @author Filip Procházka - * @package Kdyby\Monolog + * @testCase */ namespace KdybyTests\Monolog; -use Kdyby; use Kdyby\Monolog\Processor\TracyUrlProcessor; use Kdyby\Monolog\Tracy\BlueScreenRenderer; -use Tester; use Tester\Assert; use Tracy\BlueScreen; require_once __DIR__ . '/../bootstrap.php'; - - -/** - * @author Filip Procházka - */ -class TracyUrlProcessorTest extends Tester\TestCase +class TracyUrlProcessorTest extends \Tester\TestCase { /** - * @var Kdyby\Monolog\Tracy\BlueScreenRenderer + * @var \Kdyby\Monolog\Tracy\BlueScreenRenderer */ private $blueScreenRenderer; /** - * @var Kdyby\Monolog\Processor\TracyUrlProcessor + * @var \Kdyby\Monolog\Processor\TracyUrlProcessor */ private $processor; - - protected function setUp() { $this->blueScreenRenderer = new BlueScreenRenderer(TEMP_DIR, new BlueScreen()); $this->processor = new TracyUrlProcessor('https://exceptions.kdyby.org', $this->blueScreenRenderer); } - - public function testProcessWithException() { $exception = new \RuntimeException(__FUNCTION__); @@ -62,8 +49,6 @@ class TracyUrlProcessorTest extends Tester\TestCase Assert::same('https://exceptions.kdyby.org/' . $exceptionFile, $processed['context']['tracyUrl']); } - - public function testIgnoreProcessWithoutException() { $record = [ @@ -78,6 +63,4 @@ class TracyUrlProcessorTest extends Tester\TestCase } - - (new TracyUrlProcessorTest())->run(); diff --git a/tests/KdybyTests/bootstrap.php b/tests/KdybyTests/bootstrap.php index 462b896..76347ce 100755 --- a/tests/KdybyTests/bootstrap.php +++ b/tests/KdybyTests/bootstrap.php @@ -8,22 +8,34 @@ * For the full copyright and license information, please view the file license.md that was distributed with this source code. */ +use Tester\Environment; +use Tester\Helpers; +use Tracy\Debugger; + if (@!include __DIR__ . '/../../vendor/autoload.php') { echo 'Install Nette Tester using `composer update --dev`'; exit(1); } // configure environment -Tester\Environment::setup(); +Environment::setup(); date_default_timezone_set('Europe/Prague'); // create temporary directory define('TEMP_DIR', __DIR__ . '/../tmp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid())); -Tester\Helpers::purge(TEMP_DIR); -Tracy\Debugger::$logDirectory = TEMP_DIR; - +Helpers::purge(TEMP_DIR); +Debugger::$logDirectory = TEMP_DIR; $_SERVER = array_intersect_key($_SERVER, array_flip([ - 'PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv'])); + 'PHP_SELF', + 'SCRIPT_NAME', + 'SERVER_ADDR', + 'SERVER_SOFTWARE', + 'HTTP_HOST', + 'DOCUMENT_ROOT', + 'OS', + 'argc', + 'argv', +])); $_SERVER['REQUEST_TIME'] = 1234567890; $_ENV = $_GET = $_POST = [];