Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Add tests for the new DbFormatter
Browse files Browse the repository at this point in the history
Each Formatter should be covered by unit tests.
  • Loading branch information
b-durand committed Aug 23, 2012
1 parent 79a1d2f commit 9f0dce5
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/ZendTest/Log/Formatter/DbTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Formatter;

use DateTime;
use ZendTest\Log\TestAsset\StringObject;
use Zend\Log\Formatter\Db as DbFormatter;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class DbTest extends \PHPUnit_Framework_TestCase
{
public function testDefaultDateTimeFormat()
{
$formatter = new DbFormatter();
$this->assertEquals(DbFormatter::DEFAULT_DATETIME_FORMAT, $formatter->getDateTimeFormat());
}

/**
* @dataProvider provideDateTimeFormats
*/
public function testSetDateTimeFormat($dateTimeFormat)
{
$formatter = new DbFormatter();
$formatter->setDateTimeFormat($dateTimeFormat);

$this->assertEquals($dateTimeFormat, $formatter->getDateTimeFormat());
}

/**
* @return array
*/
public function provideDateTimeFormats()
{
return array(
array('r'),
array('U'),
array(DateTime::RSS),
);
}

/**
* @dataProvider provideDateTimeFormats
*/
public function testAllowsSpecifyingDateTimeFormatAsConstructorArgument($dateTimeFormat)
{
$formatter = new DbFormatter($dateTimeFormat);

$this->assertEquals($dateTimeFormat, $formatter->getDateTimeFormat());
}

public function testFormatDateTimeInEvent()
{
$datetime = new DateTime();
$event = array('timestamp' => $datetime);
$formatter = new DbFormatter();

$format = DbFormatter::DEFAULT_DATETIME_FORMAT;
$this->assertContains($datetime->format($format), $formatter->format($event));
}
}

0 comments on commit 9f0dce5

Please sign in to comment.