aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-01-14 17:46:51 +0100
committerChristian Weiske <cweiske@cweiske.de>2014-01-14 17:46:51 +0100
commit441c72bbf3d29be5c7f5eb0fd43ac267fe059c2f (patch)
treeadaf976068ed80a424f5acf64a754a52ce21c4e7 /tests
downloadbdrem-441c72bbf3d29be5c7f5eb0fd43ac267fe059c2f.tar.gz
bdrem-441c72bbf3d29be5c7f5eb0fd43ac267fe059c2f.zip
first version that reads birthday reminder files
Diffstat (limited to 'tests')
-rw-r--r--tests/bdrem/EventTest.php139
-rw-r--r--tests/bootstrap.php5
-rw-r--r--tests/phpunit.xml8
3 files changed, 152 insertions, 0 deletions
diff --git a/tests/bdrem/EventTest.php b/tests/bdrem/EventTest.php
new file mode 100644
index 0000000..3b6c903
--- /dev/null
+++ b/tests/bdrem/EventTest.php
@@ -0,0 +1,139 @@
+<?php
+namespace bdrem;
+
+class EventTest extends \PHPUnit_Framework_TestCase
+{
+ public function testIsWithinSameDaySameYear()
+ {
+ $event = new Event('Amy', 'birthday', '1995-02-24');
+ $this->assertTrue($event->isWithin('1995-02-24', 0, 0));
+ $this->assertTrue($event->isWithin('1995-02-24', 3, 7));
+ }
+
+ public function testIsWithinSameDayDifferentYear()
+ {
+ $event = new Event('Amy', 'birthday', '1995-02-24');
+ $this->assertTrue($event->isWithin('2019-02-24', 0, 0));
+ $this->assertTrue($event->isWithin('1996-02-24', 3, 7));
+ }
+
+ public function testIsWithinOneDayAfterSameYear()
+ {
+ $event = new Event('Amy', 'birthday', '1995-02-24');
+ $this->assertFalse($event->isWithin('1995-02-23', 0, 0));
+ $this->assertTrue($event->isWithin('1995-02-23', 3, 7));
+ }
+
+ public function testIsWithinOneDayBeforeSameYear()
+ {
+ $event = new Event('Amy', 'birthday', '1995-02-24');
+ $this->assertFalse($event->isWithin('1995-02-25', 0, 0));
+ $this->assertTrue($event->isWithin('1995-02-25', 3, 7));
+ }
+
+ public function testIsWithinOneDayBeforeDifferentYear()
+ {
+ $event = new Event('Amy', 'birthday', '1995-02-24');
+ $this->assertFalse($event->isWithin('1999-02-25', 0, 0));
+ $this->assertTrue($event->isWithin('1990-02-25', 3, 7));
+ }
+
+ public function testIsWithinThreeDaysBeforeSameYear()
+ {
+ $event = new Event('Amy', 'birthday', '1995-02-24');
+ $this->assertFalse($event->isWithin('1999-02-27', 0, 0));
+ $this->assertFalse($event->isWithin('1999-02-27', 1, 0));
+ $this->assertFalse($event->isWithin('1999-02-27', 2, 0));
+ $this->assertTrue( $event->isWithin('1990-02-27', 3, 0));
+
+ $this->assertFalse($event->isWithin('1999-02-27', 0, 3));
+ }
+
+ public function testIsWithinYearOverflowAfter()
+ {
+ $event = new Event('Amy', 'birthday', '1995-01-01');
+ $this->assertTrue($event->isWithin('2019-12-31', 0, 1));
+ $this->assertFalse($event->isWithin('1996-12-30', 0, 1));
+ }
+
+ public function testIsWithinYearOverflowBefore()
+ {
+ $event = new Event('Amy', 'birthday', '1995-12-30');
+ $this->assertTrue($event->isWithin('2019-01-02', 3, 0));
+ $this->assertFalse($event->isWithin('1996-01-02', 2, 0));
+ $this->assertTrue($event->isWithin('1996-01-01', 2, 0));
+ }
+
+ public function testCompareDifferentMonths()
+ {
+ $this->assertLessThan(
+ 0,
+ Event::compare(
+ new Event('Amy', 'birthday', '2013-05-10'),
+ new Event('Bob', 'birthday', '2013-06-10')
+ )
+ );
+ $this->assertGreaterThan(
+ 0,
+ Event::compare(
+ new Event('Amy', 'birthday', '2013-10-10'),
+ new Event('Bob', 'birthday', '2013-08-10')
+ )
+ );
+ }
+
+ public function testCompareDifferentMonthsYearOverflow()
+ {
+ $this->assertGreaterThan(
+ 0,
+ Event::compare(
+ new Event('Amy', 'birthday', '2013-01-10'),
+ new Event('Bob', 'birthday', '2013-12-10')
+ )
+ );
+ $this->assertLessThan(
+ 0,
+ Event::compare(
+ new Event('Amy', 'birthday', '2013-12-10'),
+ new Event('Bob', 'birthday', '2013-02-10')
+ )
+ );
+ }
+
+ public function testCompareDifferentDays()
+ {
+ $this->assertLessThan(
+ 0,
+ Event::compare(
+ new Event('Amy', 'birthday', '1950-05-10'),
+ new Event('Bob', 'birthday', '2013-05-11')
+ )
+ );
+ $this->assertGreaterThan(
+ 0,
+ Event::compare(
+ new Event('Amy', 'birthday', '2013-10-20'),
+ new Event('Bob', 'birthday', '1992-10-02')
+ )
+ );
+ }
+
+ public function testCompareSameDay()
+ {
+ $this->assertLessThan(
+ 0,
+ Event::compare(
+ new Event('Amy', 'birthday', '1950-05-10'),
+ new Event('Bob', 'birthday', '2013-05-10')
+ )
+ );
+ $this->assertGreaterThan(
+ 0,
+ Event::compare(
+ new Event('Bob', 'birthday', '1992-10-02'),
+ new Event('Amy', 'birthday', '2013-10-02')
+ )
+ );
+ }
+}
+?>
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..9c19b2a
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,5 @@
+<?php
+namespace bdrem;
+require_once __DIR__ . '/../src/bdrem/Autoloader.php';
+Autoloader::register();
+?>
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644
index 0000000..a1dc208
--- /dev/null
+++ b/tests/phpunit.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<phpunit strict="true" colors="true" bootstrap="bootstrap.php">
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../src/</directory>
+ </whitelist>
+ </filter>
+</phpunit>