Skip to content

Instantly share code, notes, and snippets.

@yuya-matsushima
Created October 3, 2011 02:58
Show Gist options
  • Save yuya-matsushima/1258339 to your computer and use it in GitHub Desktop.
Save yuya-matsushima/1258339 to your computer and use it in GitHub Desktop.
nice_date() test
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Nice_date_test extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('unit_test');
$this->load->helper('date');
}
//Do test onetime
public function index()
{
foreach(get_class_methods($this) as $method)
{
if( ! preg_match('/^_|set_up|tear_down|index/u', $method))
{
call_user_func(array($this, $method));
}
}
echo $this->unit->report();
}
//First sample code in date_helper.html
public function sample_199605()
{
$test = nice_date(199605, 'Y-m-d');
$expected = '1996-05-01';
$this->unit->run($test, $expected, '199605', 'return 1996-05-01. Result:' . $test);
//1996-05-01 => Passed
}
//Second sample code in date_helper.html
public function sample_9_11_2001()
{
$test = nice_date('9-11-2001', 'Y-m-d');
$expected = '2001-09-11';
$this->unit->run($test, $expected, '9-11-2001', 'return 2001-09-11. Result:' . $test);
//2011-09-11 => Passed
}
//Second parameter is option.
//The nice_date() will return Unix timestamp in default.
public function unix_199605()
{
$test = nice_date(199605);
$expected = 830876400;
$this->unit->run($test, $expected, 'unix_199605', 'return 830876400. Result:' . $test);
//'' => Failed
}
//The nice_date() also accept well-formed date.
//If first parameter is 'YYYYMMDD', returned result is...
public function YYYYMMDD()
{
$test = nice_date(20010911, 'Y-m-d');
$expected = '2001-09-11';
$this->unit->run($test, $expected, 'YYYYMMDD', 'return 2001-09-11. Result:' . $test);
//1970-01-01 => Failed
}
}
/* End of file nice_date.php */
/* Location: ./application/controllers/nice_date.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment