The company your work for starts the fiscal year on the last day of February. So
ID: 3664746 • Letter: T
Question
The company your work for starts the fiscal year on the last day of February. So, 2/27/2015 is in fiscal year 2014 because the 2015 fiscal year has not yet started. 2/28/2015 is in the 2015 fiscal year. Obviously, this is complicated by leap years.
Choose the class.php tab and do Load>fiscal.php to load in a class that computes the fiscal year. This version is correct. Then choose the test.php tab and create unit tests for the class Fiscal. Since Fiscal is correct, all of your tests should pass. Be sure you tests have 100% coverage.
When you click Check, the checker will feed different versions of Fiscal to your tests. Some will be broken and your tests should detect that. Note that I may break any part of the code! In those cases, PHPUnit will say FAILURE, but that is what it should say.
Whenever the checker detects an error, the last tested class will be in class.php.
Fiscal.php contents:
<?php
class Fiscal {
public static function year($dateStr) {
// Parse the supplied date
$date = new DateTime($dateStr);
// Year from the date
$year = $date->format("Y");
// Is this a leap year?
$leap = ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));
// First day of the fiscal year
$firstDay = new DateTime($leap ? "$year/2/29" : "$year/2/28");
if($date < $firstDay) {
return $year - 1;
} else {
return $year;
}
}
}
Essentially have to create a test case class.
Explanation / Answer
(or)
using the new function to do the fiscal year