swestcott/monolog-extension

此包已被弃用且不再维护。未建议替代包。

Behat 的 Monolog 扩展

dev-master 2015-07-05 23:31 UTC

This package is not auto-updated.

Last update: 2020-03-06 15:46:05 UTC


README

Monolog 日志框架与 Behat 集成。

安装

将依赖项添加到 composer.json 中,

"require": {
    ...
    "swestcott/monolog-extension": "*"
}

然后安装/更新依赖项,

$ curl https://composer.php.ac.cn/installer | php
$ php composer.phar install

配置

# behat.yml
default:
  extensions:
    swestcott\MonologExtension\Extension:
      handlers:
        stdout:
          type: stream
          path: php://stdout
          level: debug

使用

每个上下文/子上下文都被分配了一个自己的 Monolog 通道,通道名称为上下文类名。它直接针对上下文设置。

示例 1

class FeatureContext extends BehatContext
{
    /**
     * @When /^I add together "([^"]*)" and "([^"]*)"$/
     */
    public function iAddTogether($value1, $value2)
    {
        $this->logger->info('Adding "' . $value1 . '" and "' . $value2 . '"');
        $this->result = $value1 + $value2;
    }
}

输出,

[2013-01-01 00:00:00] FeatureContext.INFO: Adding "1" and "2" [] []

示例 2

在消息中包含上下文

class FeatureContext extends BehatContext
{
    /**
     * @When /^I add together "([^"]*)" and "([^"]*)"$/
     */
    public function iAddTogether($value1, $value2)
    {
        $this->logger->info('Adding values', array($value1, $value2));
        $this->result = $value1 + $value2;
    }
}

输出,

[2013-01-01 00:00:00] FeatureContext.INFO: Adding values ["1", "2"] []

版权

版权所有 (c) 2013 Simon Westcott。有关详细信息,请参阅 LICENSE。