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

Commit

Permalink
zendframework/zendframework#6058 - Adding tests to verify that messag…
Browse files Browse the repository at this point in the history
…es without a datetime are discarded
  • Loading branch information
Ocramius committed May 3, 2014
1 parent a703f96 commit 9a644cb
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions test/Filter/TimestampTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace ZendTest\Log\Filter;

use ArrayObject;
use DateTime;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Log\Filter\Timestamp as TimestampFilter;

Expand Down Expand Up @@ -39,13 +40,13 @@ public function testComparisonWhenValueIsSuppliedAsDateTimeObject($timestamp, $d
public function dateTimeDataProvider()
{
return array(
array(new \DateTime('2014-03-03'), new \DateTime('2014-03-03'), '>=', true),
array(new \DateTime('2014-10-10'), new \DateTime('2014-03-03'),'>=', true),
array(new \DateTime('2014-03-03'), new \DateTime('2014-10-10'), 'gt', false),
array(new \DateTime('2013-03-03'), new \DateTime('2014-03-03'), 'ge', false),
array(new \DateTime('2014-03-03'), new \DateTime('2014-03-03'), '==', true),
array(new \DateTime('2014-02-02'), new \DateTime('2014-03-03'), '<', true),
array(new \DateTime('2014-03-03'), new \DateTime('2014-03-03'), 'lt', false),
array(new DateTime('2014-03-03'), new DateTime('2014-03-03'), '>=', true),
array(new DateTime('2014-10-10'), new DateTime('2014-03-03'),'>=', true),
array(new DateTime('2014-03-03'), new DateTime('2014-10-10'), 'gt', false),
array(new DateTime('2013-03-03'), new DateTime('2014-03-03'), 'ge', false),
array(new DateTime('2014-03-03'), new DateTime('2014-03-03'), '==', true),
array(new DateTime('2014-02-02'), new DateTime('2014-03-03'), '<', true),
array(new DateTime('2014-03-03'), new DateTime('2014-03-03'), 'lt', false),
);
}

Expand All @@ -65,19 +66,6 @@ public function testComparisonWhenValueIsSuppliedAsDatePartValue($timestamp, $da
}
}

public function datePartDataProvider()
{
return array(
array(new \DateTime('2014-03-03 10:15:00'), 10, 'H', '==', true),
array(new \DateTime('2013-03-03 22:00:00'), 10, 'H', '=', false),
array(new \DateTime('2014-03-04 10:15:00'), 3, 'd', 'gt', true),
array(new \DateTime('2014-03-04 10:15:00'), 10, 'd', '<', true),
array(new \DateTime('2014-03-03 10:15:00'), 1, 'm', 'eq', false),
array(new \DateTime('2014-03-03 10:15:00'), 2, 'm', 'ge', true),
array(new \DateTime('2014-03-03 10:15:00'), 20, 'H', '!=', true),
);
}

/**
* @expectedException \Zend\Log\Exception\InvalidArgumentException
*/
Expand Down Expand Up @@ -129,4 +117,26 @@ public function testFilterCreatedFromTraversable()
$this->assertAttributeEquals($config['dateFormatChar'], 'dateFormatChar', $filter);
$this->assertAttributeEquals($config['operator'], 'operator', $filter);
}

public function testIgnoresMessagesWithoutTimestamp()
{
$filter = new TimestampFilter(new DateTime('-10 years'));

$this->assertFalse($filter->filter(array()));
$this->assertFalse($filter->filter(array('timestamp' => null)));
$this->assertFalse($filter->filter(array('timestamp' => 'hello world')));
}

public function datePartDataProvider()
{
return array(
array(new DateTime('2014-03-03 10:15:00'), 10, 'H', '==', true),
array(new DateTime('2013-03-03 22:00:00'), 10, 'H', '=', false),
array(new DateTime('2014-03-04 10:15:00'), 3, 'd', 'gt', true),
array(new DateTime('2014-03-04 10:15:00'), 10, 'd', '<', true),
array(new DateTime('2014-03-03 10:15:00'), 1, 'm', 'eq', false),
array(new DateTime('2014-03-03 10:15:00'), 2, 'm', 'ge', true),
array(new DateTime('2014-03-03 10:15:00'), 20, 'H', '!=', true),
);
}
}

0 comments on commit 9a644cb

Please sign in to comment.