Open zeleniy opened 1 year ago
Unit, Functional or Acceptance Tests?
Unit. When i run tests i see that \Codeception\Lib\Connector\Yii2\Logger
used which produce no output. And i am trying to replace it, but in most cases this is doesn't help:
protected function _before() {
/*
* Replace \Codeception\Lib\Connector\Yii2\Logger which supress messages with Yii2 standard logger.
*/
\Yii::setLogger(\Yii::createObject(\yii\log\Logger::class));
...
@zeleniy Try to add Yii::$app->log->setLogger(Yii::getLogger()); after \Yii::setLogger...
@DplusG, no it doesn't help. If to modify BaseYii::info
in such way:
public static function info($message, $category = 'application')
{
(new Output([]))->debug([ __METHOD__, get_class(static::getLogger()) ]);
static::getLogger()->log($message, Logger::LEVEL_INFO, $category);
}
It will produce next output:
Array
(
[0] => yii\BaseYii::info
[1] => yii\log\Logger
)
Array
(
[0] => yii\BaseYii::info
[1] => yii\log\Logger
)
Array
(
[0] => yii\BaseYii::info
[1] => Codeception\Lib\Connector\Yii2\Logger
)
Array
(
[0] => yii\BaseYii::info
[1] => Codeception\Lib\Connector\Yii2\Logger
)
...
on test run:
./vendor/bin/codecept run common/tests/unit/components/counting/HandlerBillTest.php
Where do you expect the logs to be written (file, db, stdout, ...)?
Mostly part to files:
...
[
'class' => 'yii\log\FileTarget',
'categories' => ['1c-put-bill'],
'logFile' => '@app_root/logs/1c/put-bill.log',
'logVars' => [],
],
...
Do you see any errors, warnings when running unit tests in STDOUT?
You might try an absolute path, in case aliases are not set-up properly.
No, i don't.
Just for the test. Try to change category to default when log method is called. Yii::info('hi') and remove 'categories' => ['1c-put-bill'], I think that may not working with custom categories
@zeleniy
Mostly part to files ...
Are you completely sure that this config is not ignored in test environment?
Also ensure file @app_root/logs/1c/put-bill.log
is writable by OS user which run $ ./vendor/bin/codecept
No logs written while testing with codecept.