This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Each Formatter should be covered by unit tests.
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |