Esempio n. 1
0
 /**
  * Dates should be randomly generated in the format YYYY-MM-DD.
  *
  * We do this one hundred times to make sure the dates are valid.
  */
 public function testRandomDate()
 {
     for ($i = 0; $i < 100; $i++) {
         // Generate a random date
         $random_date = Fluffer::fluffDate();
         // Break the generated date into pieces
         $parts = explode("-", $random_date);
         $random_year = $parts[0];
         $random_month = $parts[1];
         $random_day = $parts[2];
         // Make sure the first four digits are a year (0-9999)
         $this->assertTrue(is_numeric($random_year), "The year is a number");
         $this->assertGreaterThan(0, $random_year, "The year is greater than zero");
         // Make sure the six and seventh digits a month (01-12)
         $this->assertTrue(is_numeric($random_month), "The month must be a number");
         $this->assertGreaterThan(0, $random_month, "The month is always greater than zero.");
         $this->assertLessThanOrEqual(12, $random_month, "The month is always less or equal to 12");
         // Make sure the ninth and tenth digits are a day
         // Use a lookup table to figure out how many days should be in each month
         $days_in_month = array("01" => 31, "02" => 28, "03" => 31, "04" => 30, "05" => 31, "06" => 30, "07" => 31, "08" => 31, "09" => 30, "10" => 31, "11" => 30, "12" => 31);
         $this->assertTrue(is_numeric($random_day), "The day must be a number");
         $this->assertGreaterThan(0, $random_day);
         $days_in_random_month = $days_in_month[$random_month];
         $this->assertLessThanOrEqual($days_in_random_month, $random_day, "{$random_day} is to high.  The {$random_month} month doesn\\'t have more than {$days_in_random_month} days in it!");
     }
 }
Esempio n. 2
0
 /**
  * Dates should be randomly generated in the format YYYY-MM-DD.
  *
  * We do this one hundred times to make sure the dates are valid.
  */
 public function testRandomDate()
 {
     for ($i = 0; $i < 100; $i++) {
         // Generate a random date
         $random_date = Fluffer::fluffDate();
         $this->assertIsDate($random_date);
     }
 }