Sort and Time class tests
This commit is contained in:
parent
007ebef6e6
commit
e9456600a7
4 changed files with 161 additions and 3 deletions
|
@ -116,7 +116,9 @@ class Time
|
||||||
* @static
|
* @static
|
||||||
* @param string $date birth / inception date
|
* @param string $date birth / inception date
|
||||||
* @return integer $age number of years old
|
* @return integer $age number of years old
|
||||||
* @todo Wondering if this really should live in the Date class since it's a Date function. Could flip the aliasing to preserve any older code.
|
* @todo Wondering if this really should live in the Date class since
|
||||||
|
* it's a Date function. Could flip the aliasing to preserve any
|
||||||
|
* older code.
|
||||||
*/
|
*/
|
||||||
public static function age($date)
|
public static function age($date)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,8 +13,6 @@ Object
|
||||||
Profiler
|
Profiler
|
||||||
Security
|
Security
|
||||||
Session
|
Session
|
||||||
Sort
|
|
||||||
Time
|
|
||||||
Validate
|
Validate
|
||||||
|
|
||||||
Stuff in API directory
|
Stuff in API directory
|
||||||
|
|
62
tests/classes/SortTest.php
Normal file
62
tests/classes/SortTest.php
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class SortTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testByNameASC()
|
||||||
|
{
|
||||||
|
$shuffled = [
|
||||||
|
['name' => 'epsilon'],
|
||||||
|
['name' => 'gamma'],
|
||||||
|
['name' => 'alpha'],
|
||||||
|
['name' => 'delta'],
|
||||||
|
['name' => 'beta'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$sorted = [
|
||||||
|
['name' => 'alpha'],
|
||||||
|
['name' => 'beta'],
|
||||||
|
['name' => 'delta'],
|
||||||
|
['name' => 'epsilon'],
|
||||||
|
['name' => 'gamma'],
|
||||||
|
];
|
||||||
|
|
||||||
|
Sort::by('name', $shuffled);
|
||||||
|
|
||||||
|
$this->assertEquals($sorted, $shuffled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testByNameDESC()
|
||||||
|
{
|
||||||
|
$shuffled = [
|
||||||
|
['name' => 'epsilon'],
|
||||||
|
['name' => 'gamma'],
|
||||||
|
['name' => 'alpha'],
|
||||||
|
['name' => 'delta'],
|
||||||
|
['name' => 'beta'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$sorted = [
|
||||||
|
['name' => 'gamma'],
|
||||||
|
['name' => 'epsilon'],
|
||||||
|
['name' => 'delta'],
|
||||||
|
['name' => 'beta'],
|
||||||
|
['name' => 'alpha'],
|
||||||
|
];
|
||||||
|
|
||||||
|
Sort::by('name', $shuffled, Sort::DESC);
|
||||||
|
|
||||||
|
$this->assertEquals($sorted, $shuffled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMissingField()
|
||||||
|
{
|
||||||
|
$shuffled = [['foo' => 'bar', 'bar' => 'foo']];
|
||||||
|
$sorted = [['foo' => 'bar', 'bar' => 'foo']];
|
||||||
|
|
||||||
|
Sort::by('name', $shuffled);
|
||||||
|
|
||||||
|
$this->assertEquals($sorted, $shuffled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
96
tests/classes/TimeTest.php
Normal file
96
tests/classes/TimeTest.php
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class TimeTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
date_default_timezone_set('GMT');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgePastTime()
|
||||||
|
{
|
||||||
|
$this->assertEquals(18, Time::age(date('Y-m-d', strtotime('-18 years'))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgeFutureTime()
|
||||||
|
{
|
||||||
|
$this->assertEquals(-18, Time::age(date('Y-m-d', strtotime('18 years'))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoPastTimeSeconds()
|
||||||
|
{
|
||||||
|
$this->assertEquals('seconds ago', Time::ago(strtotime('-30 seconds')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoPastTimeMinutes()
|
||||||
|
{
|
||||||
|
$this->assertEquals('5 minutes ago', Time::ago(strtotime('-5 minutes')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoPastTimeHours()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 hour ago', Time::ago(strtotime('-1 hour')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoPastTimeDays()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 day ago', Time::ago(strtotime('-1 day')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoPastTimeWeeks()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 week ago', Time::ago(strtotime('-1 week')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoPastTimeMonths()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 month ago', Time::ago(strtotime('-1 month')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoPastTimeYears()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 year ago', Time::ago(strtotime('-1 year')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoFutureTimeSeconds()
|
||||||
|
{
|
||||||
|
$this->assertEquals('seconds from now', Time::ago(strtotime('+30 seconds')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoFutureTimeMinutes()
|
||||||
|
{
|
||||||
|
$this->assertEquals('5 minutes from now', Time::ago(strtotime('+5 minutes')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoFutureTimeHours()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 hour from now', Time::ago(strtotime('+1 hour')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoFutureTimeDays()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 day from now', Time::ago(strtotime('+1 day')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoFutureTimeWeeks()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 week from now', Time::ago(strtotime('+1 week')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoFutureTimeMonths()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 month from now', Time::ago(strtotime('+1 month')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAgoFutureTimeYears()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 year from now', Time::ago(strtotime('+1 year')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTimestamp()
|
||||||
|
{
|
||||||
|
$this->assertEquals(gmdate('Y-m-d H:i:s'), Time::timestamp());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue