Skip to content

Commit

Permalink
[#13438] - Added more tests for the Json formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Dec 7, 2018
1 parent 19167c1 commit 86dea08
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 2 deletions.
39 changes: 38 additions & 1 deletion tests/unit/Logger/Formatter/Json/FormatCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace Phalcon\Test\Unit\Logger\Formatter\Json;

use Phalcon\Logger;
use Phalcon\Logger\Formatter\Json;
use Phalcon\Logger\Item;
use UnitTester;

/**
Expand All @@ -32,6 +35,40 @@ class FormatCest
public function loggerFormatterJsonFormat(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Json - format()");
$I->skipTest("Need implementation");
$line = new Json();

$time = time();
$item = new Item('log message', 'debug', Logger::DEBUG, $time);

$expected = sprintf(
'{"type":"debug", "message":"log message", "timestamp":"%s"}',
date('D, d M y H:i:s O', $time)
);
$actual = $line->format($item);
$I->assertEquals($expected, $actual);
}

/**
* Tests Phalcon\Logger\Formatter\Json :: format() -custom
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function loggerFormatterJsonFormatCustom(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Json - format() - custom");
$line = new Json('YmdHis');

$time = time();
$item = new Item('log message', 'debug', Logger::DEBUG, $time);

$expected = sprintf(
'{"type":"debug", "message":"log message", "timestamp":"%s"}',
date('YmdHis', $time)
);
$actual = $line->format($item);
$I->assertEquals($expected, $actual);
}
}
42 changes: 42 additions & 0 deletions tests/unit/Logger/Formatter/Json/GetDateFormatCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalconphp.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Logger\Formatter\Json;

use Phalcon\Logger\Formatter\Json;
use UnitTester;

/**
* Class GetDateFormatCest
*
* @package Phalcon\Test\Unit\Logger
*/
class GetDateFormatCest
{
/**
* Tests Phalcon\Logger\Formatter\Json :: getDateFormat()
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function loggerFormatterJsonGetDateFormat(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Json - getDateFormat()");
$formatter = new Json();

$expected = 'D, d M y H:i:s O';
$actual = $formatter->getDateFormat();
$I->assertEquals($expected, $actual);
}
}
45 changes: 45 additions & 0 deletions tests/unit/Logger/Formatter/Json/SetDateFormatCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalconphp.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Logger\Formatter\Json;

use Phalcon\Logger\Formatter\Json;
use UnitTester;

/**
* Class SetDateFormatCest
*
* @package Phalcon\Test\Unit\Logger
*/
class SetDateFormatCest
{
/**
* Tests Phalcon\Logger\Formatter\Json :: setDateFormat()
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function loggerFormatterJsonSetDateFormat(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Json - setDateFormat()");
$formatter = new Json();

$format = 'YmdHis';
$formatter->setDateFormat($format);

$expected = $format;
$actual = $formatter->getDateFormat();
$I->assertEquals($expected, $actual);
}
}
34 changes: 33 additions & 1 deletion tests/unit/Logger/Formatter/Line/FormatCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

namespace Phalcon\Test\Unit\Logger\Formatter\Line;

use Phalcon\Logger;
use Phalcon\Logger\Formatter\Line;
use Phalcon\Logger\Item;
use UnitTester;
use const PHP_EOL;

/**
* Class FormatCest
Expand All @@ -32,6 +36,34 @@ class FormatCest
public function loggerFormatterLineFormat(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Line - format()");
$I->skipTest("Need implementation");
$line = new Line();

$time = time();
$item = new Item('log message', 'debug', Logger::DEBUG, $time);

$expected = sprintf('[%s][debug] log message', date('D, d M y H:i:s O', $time)) . PHP_EOL;
$actual = $line->format($item);
$I->assertEquals($expected, $actual);
}

/**
* Tests Phalcon\Logger\Formatter\Line :: format() -custom
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function loggerFormatterLineFormatCustom(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Line - format() - custom");
$line = new Line('%message%-[%type%]-%date%');

$time = time();
$item = new Item('log message', 'debug', Logger::DEBUG, $time);

$expected = sprintf('log message-[debug]-%s', date('D, d M y H:i:s O', $time)) . PHP_EOL;
$actual = $line->format($item);
$I->assertEquals($expected, $actual);
}
}

0 comments on commit 86dea08

Please sign in to comment.