Phalcon\Test\Unit\Logger\Adapter\FileTest::testLoggerAdapterFileSettingJsonFormatter PHP Method

testLoggerAdapterFileSettingJsonFormatter() public method

Tests setting Json formatter
Since: 2016-01-28
Author: Serghei Iakovlev ([email protected])
    public function testLoggerAdapterFileSettingJsonFormatter()
    {
        $this->specify("logging in a file does not create the file", function () {
            $I = $this->tester;
            $fileName = $I->getNewFileName('log', 'log');
            $logger = new File($this->logPath . $fileName);
            $logger->setFormatter(new Json());
            $logger->log('This is a message');
            $logger->log("This is an error", Logger::ERROR);
            $logger->error("This is another error");
            $I->amInPath($this->logPath);
            $I->openFile($fileName);
            $expected = sprintf('{"type":"DEBUG","message":"This is a message","timestamp":%s}' . PHP_EOL . '{"type":"ERROR","message":"This is an error","timestamp":%s}' . PHP_EOL . '{"type":"ERROR","message":"This is another error","timestamp":%s}', time(), time(), time());
            $I->seeInThisFile($expected);
            $I->deleteFile($fileName);
        });
    }
FileTest