Skip to content

Commit

Permalink
[phalcon#13438] - Added more tests for formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
niden authored and CameronHall committed Dec 8, 2018
1 parent e9a74b3 commit b20f27c
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 9 deletions.
37 changes: 37 additions & 0 deletions tests/unit/Logger/Adapter/File/AddCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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\Adapter\File;

use UnitTester;

/**
* Class AddCest
*
* @package Phalcon\Test\Unit\Logger
*/
class AddCest
{
/**
* Tests Phalcon\Logger\Adapter\File :: add()
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function loggerAdapterFileAdd(UnitTester $I)
{
$I->wantToTest("Logger\Adapter\File - add()");
$I->skipTest("Need implementation");
}
}
8 changes: 4 additions & 4 deletions tests/unit/Logger/Formatter/Json/FormatCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FormatCest
public function loggerFormatterJsonFormat(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Json - format()");
$line = new Json();
$formatter = new Json();

$time = time();
$item = new Item('log message', 'debug', Logger::DEBUG, $time);
Expand All @@ -44,7 +44,7 @@ public function loggerFormatterJsonFormat(UnitTester $I)
'{"type":"debug","message":"log message","timestamp":"%s"}',
date('D, d M y H:i:s O', $time)
);
$actual = $line->format($item);
$actual = $formatter->format($item);
$I->assertEquals($expected, $actual);
}

Expand All @@ -59,7 +59,7 @@ public function loggerFormatterJsonFormat(UnitTester $I)
public function loggerFormatterJsonFormatCustom(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Json - format() - custom");
$line = new Json('YmdHis');
$formatter = new Json('YmdHis');

$time = time();
$item = new Item('log message', 'debug', Logger::DEBUG, $time);
Expand All @@ -68,7 +68,7 @@ public function loggerFormatterJsonFormatCustom(UnitTester $I)
'{"type":"debug","message":"log message","timestamp":"%s"}',
date('YmdHis', $time)
);
$actual = $line->format($item);
$actual = $formatter->format($item);
$I->assertEquals($expected, $actual);
}
}
78 changes: 78 additions & 0 deletions tests/unit/Logger/Formatter/Json/InterpolateCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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;
use Phalcon\Logger\Formatter\Json;
use Phalcon\Logger\Item;
use UnitTester;

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

$message = 'The sky is {color}';
$context = [
'color' => 'blue',
];

$expected = 'The sky is blue';
$actual = $formatter->interpolate($message, $context);
$I->assertEquals($expected, $actual);
}

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

$message = 'The sky is {color}';
$context = [
'color' => 'blue',
];

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

$expected = sprintf(
'{"type":"debug","message":"The sky is blue","timestamp":"%s"}',
date('D, d M y H:i:s O', $time)
);
$actual = $formatter->format($item);
$I->assertEquals($expected, $actual);
}
}
8 changes: 4 additions & 4 deletions tests/unit/Logger/Formatter/Line/FormatCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class FormatCest
public function loggerFormatterLineFormat(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Line - format()");
$line = new Line();
$formatter = 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);
$actual = $formatter->format($item);
$I->assertEquals($expected, $actual);
}

Expand All @@ -57,13 +57,13 @@ public function loggerFormatterLineFormat(UnitTester $I)
public function loggerFormatterLineFormatCustom(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Line - format() - custom");
$line = new Line('%message%-[%type%]-%date%');
$formatter = 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);
$actual = $formatter->format($item);
$I->assertEquals($expected, $actual);
}
}
40 changes: 39 additions & 1 deletion tests/unit/Logger/Formatter/Line/InterpolateCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

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

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

/**
Expand All @@ -32,6 +35,41 @@ class InterpolateCest
public function loggerFormatterLineInterpolate(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Line - interpolate()");
$I->skipTest("Need implementation");
$formatter = new Line();

$message = 'The sky is {color}';
$context = [
'color' => 'blue',
];

$expected = 'The sky is blue';
$actual = $formatter->interpolate($message, $context);
$I->assertEquals($expected, $actual);
}

/**
* Tests Phalcon\Logger\Formatter\Line :: interpolate() - format
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function loggerFormatterLineInterpolateFormat(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Line - interpolate() - format()");
$formatter = new Line();

$message = 'The sky is {color}';
$context = [
'color' => 'blue',
];

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

$expected = sprintf('[%s][debug] The sky is blue', date('D, d M y H:i:s O', $time)) . PHP_EOL;
$actual = $formatter->format($item);
$I->assertEquals($expected, $actual);
}
}
47 changes: 47 additions & 0 deletions tests/unit/Logger/Formatter/Syslog/FormatCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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\Syslog;

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

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

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

$expected = [Logger::DEBUG, 'log message'];
$actual = $formatter->format($item);
$I->assertEquals($expected, $actual);
}
}
75 changes: 75 additions & 0 deletions tests/unit/Logger/Formatter/Syslog/InterpolateCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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\Syslog;

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

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

$message = 'The sky is {color}';
$context = [
'color' => 'blue',
];

$expected = 'The sky is blue';
$actual = $formatter->interpolate($message, $context);
$I->assertEquals($expected, $actual);
}

/**
* Tests Phalcon\Logger\Formatter\Syslog :: interpolate() - format
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function loggerFormatterSyslogInterpolateFormat(UnitTester $I)
{
$I->wantToTest("Logger\Formatter\Syslog - interpolate() - format()");
$formatter = new Syslog();

$message = 'The sky is {color}';
$context = [
'color' => 'blue',
];

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

$expected = [Logger::DEBUG, 'The sky is blue'];
$actual = $formatter->format($item);
$I->assertEquals($expected, $actual);
}
}

0 comments on commit b20f27c

Please sign in to comment.