Skip to content

Instantly share code, notes, and snippets.

@tchalko
Last active May 6, 2019 17:44
Show Gist options
  • Save tchalko/e8c23aae6a1e2283b74e685dbd709df3 to your computer and use it in GitHub Desktop.
Save tchalko/e8c23aae6a1e2283b74e685dbd709df3 to your computer and use it in GitHub Desktop.
<?php
class Car {
public $make;
public $year;
public $mileage;
public $coverage_name;
public $coverage_terms;
public $coverage_miles;
public $condition;
public $suffix1;
public $suffix2;
public $base_warranty_term;
public $base_warranty_miles;
public $validation_result;
public $errors;
//=====================
// public functions
//=====================
// Retrieve json file by simulating API call
public function getCoverageArray($url) {
$results = $this->apiCall($url);
return $results;
}
// Validate make input from the command line
public function validateMake($make, $base_warranty, &$valid_makes){
foreach ($base_warranty as $item) {
if ($item["make"] == $make) {
return true;
}
array_push($valid_makes,$item["make"]);
}
return false;
}
// Validate year input from the command line
public function validateYear($year, $years, &$valid_years){
foreach ($years as $item) {
if ($item["modelyear"] == $year) {
return true;
}
array_push($valid_years,$item["modelyear"]);
}
return false;
}
// Validate mileage input from the command line
public function validateMileage($mileage){
return (($mileage>MIN_INPUT_MILEAGE) &&
($mileage<MAX_INPUT_MILEAGE) &&
($mileage%INC_MILEAGE==0)) ? true : false;
}
// Get basic info from the command line
public function getCarInputValues($base_warranty, $years){
return $this->getInputValues($base_warranty, $years);
}
// Set base warranty info for the car
public function getBaseWarrantyInfo($base_warranty)
{
foreach ($base_warranty as $item) {
if ($item["make"] != $this->make)
continue;
else {
$this->base_warranty_miles = $item["miles"];
$this->base_warranty_term = $item["term"];
return true;
}
}
}
// Checks the age condition of the car
public function getCondition(){
return ($this->mileage < $this->base_warranty_miles) ? "NEW" : "USED";
}
// Sets the correct suffix1 for the car
public function getSuffix1($years) {
foreach ($years as $item) {
if ($item["modelyear"]== $this->year) {
$formatted_suffix1 = sprintf("%02d", $item["suffix1"]);
return $formatted_suffix1;
}
}
array_push($this->errors, "Car model year is not on our list");
return "--";
}
// Sets the correct suffix2 for the car
public function getSuffix2($issue_mileage) {
foreach ($issue_mileage as $item) {
if ($this->mileage > $item["max"])
continue;
else
return $item["suffix2"];
}
array_push($this->errors, "Car mileage is not on our list");
return "-";
}
// Checks if the miles of the coverage contract expire before the base warranty miles of the
// vehicle has expired.
public function checkContractMileage($coverage){
if ($coverage['miles'] <= $this->base_warranty_miles) {
array_push($this->errors, "Miles expires before warranty");
return false;
}
return true;
}
// Checks if the term of the coverage contract expire before the base warranty term of the
// vehicle has expired.
public function checkContractTerms($coverage){
if ($coverage['terms'] <= $this->base_warranty_term) {
array_push($this->errors, "Term expires before warranty");
return false;
}
return true;
}
// Checks if car will be too old before contract expires
public function checkAge($coverage){
$current_year = date("Y");
// Get future age of car, in months, at the end of the term
$future_age = (12*($current_year - $this->year)) + $coverage['terms'];
// if future age is > 147 months, this car will be too old
if ($future_age > 147){
array_push($this->errors, "Vehicle age will be too old before contract ends");
return false;
}
return true;
}
// Checks if car will have too many miles before contract expires
public function checkMileage($coverage){
$current_year = date("Y");
$current_month = date("m");
// first get car current average miles per month
if ($this->year < $current_year)
$average_monthly_miles = $this->mileage / (12*($current_year - $this->year));
else
$average_monthly_miles = $this->mileage / $current_month;
// next get mileage expected during the term
$miles_expected_during_contract = $average_monthly_miles * $coverage["terms"];
// finally get total miles expected
$total_expected_miles = $miles_expected_during_contract + $this->mileage;
// if total expected miles is > MAX_MILEAGE miles, this car will be too high mileage
if ($total_expected_miles > MAX_MILEAGE) {
array_push($this->errors, "Vehicle mileage will be too high before contract ends");
return false;
}
return true;
}
// Returns values to print of general car information,
public function getPrintValues(){
$string_to_output =
$this->make.' '.$this->year.' '.$this->mileage.' '.$this->condition.' "'.$this->coverage_name.'" suffix1:'.$this->suffix1.' suffix2:'.$this->suffix2.' ';
return $string_to_output;
}
// Returns values to print of validation results
public function getPrintValidationResults(){
$num_errors = count($this->errors);
if ($num_errors == 0)
$string_to_output = "RESULT: SUCCESS";
else {
$string_to_output = "RESULT: FAILURE array('";
$cnt=0;
foreach($this->errors as $value) {
$string_to_output = $string_to_output.((++$cnt == $num_errors) ? "$value')" : "$value', '");
}
}
return $string_to_output;
}
//=====================
// private functions
//=====================
// simulate API call to get json file.
private function apiCall($url) {
$strJson = file_get_contents($url); //implemented with file_get_contents since file is in same directory
$result = json_decode($strJson, true);
return $result;
}
// Retrieve car's make from the command line
private function getCarMake($base_warranty){
$valid_input = false;
$valid_makes = array();
while (!$valid_input) {
echo "Enter car make: ";
$make = rtrim(fgets(STDIN), "\r\n");
$valid_input = $this->validateMake($make, $base_warranty, $valid_makes);
if (!$valid_input) {
echo "Invalid car make input, select from [ ";
while (count($valid_makes) > 0) {
echo array_shift($valid_makes) . " ";
}
echo "]. Please try again\n";
}
}
return $make;
}
// Retrieve car's year from the command line
private function getCarYear($years){
$valid_input = false;
$valid_years = array();
while (!$valid_input) {
echo "Enter car year: ";
$year = rtrim(fgets(STDIN), "\r\n");
$valid_input = $this->validateYear($year, $years, $valid_years);
if (!$valid_input){
echo "Invalid car year input, select from [ ";
while (count($valid_years) > 0) {
echo array_shift($valid_years) . " ";
}
echo "]. Please try again\n";
}
}
return $year;
}
// Retrieve car's issue mileage from the command line
private function getCarMileage(){
$valid_input = false;
while (!$valid_input) {
echo "Enter car issue mileage: ";
$mileage = rtrim(fgets(STDIN), "\r\n");
$valid_input = $this->validateMileage($mileage);
if (!$valid_input)
echo "Invalid car issue mileage input, select from [ ".MIN_INPUT_MILEAGE."-".MAX_INPUT_MILEAGE." ] in ".INC_MILEAGE." mile increments. Please try again\n";
}
return $mileage;
}
// Retrieve car make, year, and issue mileage from the command line
private function getInputValues($base_warranty, $years){
$this->make = $this->getCarMake($base_warranty);
$this->year = $this->getCarYear($years);
$this->mileage = $this->getCarMileage();
return true;
}
}
<?php
use PHPUnit\Framework\TestCase;
const MAX_INPUT_MILEAGE = 150000;
const MIN_INPUT_MILEAGE = 0;
const INC_MILEAGE = 1000;
const MAX_MILEAGE = 153000;
class CarTest extends TestCase
{
public $years = array(
array("modelyear" => 2003, "suffix1" => 15),
array("modelyear" => 2004, "suffix1" => 14),
array("modelyear" => 2005, "suffix1" => 13),
array("modelyear" => 2006, "suffix1" => 12),
array("modelyear" => 2007, "suffix1" => 11),
array("modelyear" => 2008, "suffix1" => 10),
array("modelyear" => 2009, "suffix1" => 9),
array("modelyear" => 2010, "suffix1" => 8),
array("modelyear" => 2011, "suffix1" => 7),
array("modelyear" => 2012, "suffix1" => 6),
array("modelyear" => 2013, "suffix1" => 5),
array("modelyear" => 2014, "suffix1" => 4),
array("modelyear" => 2015, "suffix1" => 3),
array("modelyear" => 2016, "suffix1" => 2),
array("modelyear" => 2017, "suffix1" => 1),
array("modelyear" => 2018, "suffix1" => 0),
array("modelyear" => 2019, "suffix1" => 0));
// mileage of the vehicle at the time the contract is rated
public $issue_mileage = array(
array("min" => 0, "max" => 12000, "suffix2" => "A"),
array("min" => 12001, "max" => 24000, "suffix2" => "A"),
array("min" => 24001, "max" => 36000, "suffix2" => "B"),
array("min" => 36001, "max" => 48000, "suffix2" => "C"),
array("min" => 48001, "max" => 60000, "suffix2" => "D"),
array("min" => 60001, "max" => 72000, "suffix2" => "E"),
array("min" => 72001, "max" => 84000, "suffix2" => "F"),
array("min" => 84001, "max" => 96000, "suffix2" => "G"),
array("min" => 96001, "max" => 108000, "suffix2" => "H"),
array("min" => 108001, "max" => 120000, "suffix2" => "I"),
array("min" => 120001, "max" => 132000, "suffix2" => "J"),
array("min" => 132001, "max" => 144000, "suffix2" => "K"),
array("min" => 144001, "max" => 150000, "suffix2" => "L")
);
public $base_warranty = array(
array("make" => "BMW", "term" => 36, "miles" => 48000),
array("make" => "Volkswagen", "term" => 72, "miles" => 100000)
);
public $coverage = array(
array("name" => "3 Months/3,000 Miles", "terms" => 3, "miles" => 3000),
array("name" => "6 Months/12,000 Miles", "terms" => 6, "miles" => 12000),
array("name" => "12 Months/24,000 Miles", "terms" => 12, "miles" => 24000),
array("name" => "24 Months/30,000 Miles", "terms" => 24, "miles" => 30000),
array("name" => "24 Months/36,000 Miles", "terms" => 24, "miles" => 36000),
array("name" => "36 Months/36,000 Miles", "terms" => 36, "miles" => 36000),
array("name" => "36 Months/45,000 Miles", "terms" => 36, "miles" => 45000),
array("name" => "36 Months/50,000 Miles", "terms" => 36, "miles" => 50000),
array("name" => "48 Months/50,000 Miles", "terms" => 48, "miles" => 50000),
array("name" => "48 Months/60,000 Miles", "terms" => 48, "miles" => 60000),
array("name" => "60 Months/72,000 Miles", "terms" => 60, "miles" => 72000),
array("name" => "60 Months/75,000 Miles", "terms" => 60, "miles" => 75000),
array("name" => "72 Months/100,000 Miles", "terms" => 72, "miles" => 100000),
array("name" => "84 Months/84,000 Miles", "terms" => 84, "miles" => 84000),
array("name" => "84 Months/96,000 Miles", "terms" => 84, "miles" => 96000),
array("name" => "100 Months/100,000 Miles", "terms" => 100, "miles" => 100000),
array("name" => "100 Months/120,000 Miles", "terms" => 100, "miles" => 120000),
array("name" => "120 Months/120,000 Miles", "terms" => 120, "miles" => 120000)
);
protected $car;
protected function setUp(): void {
$this->car = new Car;
}
public function testCoverageArrayReturnedCorrectly(){
$url = "src/devTest.json";
$this->assertEquals($this->coverage, $this->car->getCoverageArray($url));
}
public function testCarMakeIsValid(){
$make = "BMC";
$valid_makes = array();
$this->assertEquals(false, $this->car->validateMake($make, $this->base_warranty, $valid_makes));
$this->assertEquals(2, count($valid_makes));
$make = "BMW";
$valid_makes = array();
$this->assertEquals(true, $this->car->validateMake($make, $this->base_warranty, $valid_makes));
}
public function testCarYearIsValid(){
$valid_years = array();
$year = 2002;
$this->assertEquals(false, $this->car->validateYear($year, $this->years, $valid_years));
$this->assertEquals(17, count($valid_years));
$valid_years = array();
$year = 2018;
$this->assertEquals(true, $this->car->validateYear($year, $this->years, $valid_years));
}
public function testCarMileageIsValid(){
$mileage = 90000;
$this->assertEquals(true, $this->car->validateMileage($mileage));
$mileage = 90500;
$this->assertEquals(false, $this->car->validateMileage($mileage));
}
public function testRetrievalOfBaseWarrantyInformation(){
$this->car->make = "BMW" ;
$this->assertEquals(true, $this->car->getBaseWarrantyInfo($this->base_warranty));
$this->assertEquals(48000, $this->car->base_warranty_miles);
$this->assertEquals(36, $this->car->base_warranty_term);
}
public function testConditionReturnsNewAndUsed(){
$this->car->mileage = 52000 ;
$this->car->base_warranty_miles= 48000;
$this->assertEquals("USED", $this->car->getCondition());
$this->car->mileage = 44000 ;
$this->assertEquals("NEW", $this->car->getCondition());
}
public function testSuffix1returnsValidValue() {
$this->car->year = 2019;
$this->assertEquals("00", $this->car->getSuffix1($this->years));
$this->car->year = 2012;
$this->assertEquals("06", $this->car->getSuffix1($this->years));
$this->car->year = 2007;
$this->assertEquals("11", $this->car->getSuffix1($this->years));
}
public function testSuffix2returnsValidValue() {
$this->car->mileage = 44000 ;
$this->assertEquals("C", $this->car->getSuffix2($this->issue_mileage));
}
public function testCheckIfContractMilesExpiresBeforeBaseWarrantyMiles() {
$this->car->errors = [];
$this->car->base_warranty_miles= 48000;
$this->assertEquals(true, $this->car->checkContractMileage($this->coverage[7]));
$this->assertEquals(0, count($this->car->errors));
$this->assertEquals(false, $this->car->checkContractMileage($this->coverage[6]));
$this->assertEquals(1, count($this->car->errors));
}
public function testCheckIfContractTermExpiresBeforeBaseWarrantyTerm() {
$this->car->errors = [];
$this->car->base_warranty_term= 36;
$this->assertEquals(true, $this->car->checkContractTerms($this->coverage[8]));
$this->assertEquals(0, count($this->car->errors));
$this->assertEquals(false, $this->car->checkContractTerms($this->coverage[7]));
$this->assertEquals(1, count($this->car->errors));
}
public function testCheckIfCarWillBeTooOldBeforeContractExpires() {
$this->car->errors = [];
$this->car->year = 2018;
$this->assertEquals(true, $this->car->checkAge($this->coverage[8]));
$this->assertEquals(0, count($this->car->errors));
$this->car->year = 2010;
$this->assertEquals(false, $this->car->checkAge($this->coverage[8]));
$this->assertEquals(1, count($this->car->errors));
}
public function testCheckIfCarWillHaveTooManyMilesBeforeContractExpires() {
$this->car->errors = [];
$this->car->year = 2018;
$this->car->mileage = 1000;
$this->assertEquals(true, $this->car->checkMileage($this->coverage[8]));
$this->assertEquals(0, count($this->car->errors));
$this->car->errors = [];
$this->car->year = 2010;
$this->car->mileage = 80000;
$this->assertEquals(false, $this->car->checkMileage($this->coverage[17]));
$this->assertEquals(1, count($this->car->errors));
}
public function testPrintedOutputIsValid(){
$this->car->make = "BMW";
$this->car->year ="2018";
$this->car->mileage = "1000";
$this->car->condition ="NEW";
$this->car->coverage_name = "3 Months/3,000 Miles";
$this->car->suffix1 = "00";
$this->car->suffix2 = "A";
$this->expectOutputString($this->car->getPrintValues());
print 'BMW 2018 1000 NEW "3 Months/3,000 Miles" suffix1:00 suffix2:A ';
}
public function testPrintedValidationOutputIsValidSuccess(){
$this->car->errors = array();
$this->expectOutputString($this->car->getPrintValidationResults());
print 'RESULT: SUCCESS';
}
public function testPrintedValidationOutputIsValidFailure(){
$this->car->errors = array();
array_push($this->car->errors,'Term expires before warranty');
$this->expectOutputString($this->car->getPrintValidationResults());
print "RESULT: FAILURE array('Term expires before warranty')";
}
}
{
"require-dev": {
"phpunit/phpunit": "^8.1"
},
"autoload": {
"psr-4": {
"": "src/"
}
}
}

to run the developer test / unit tests: NOTE: I ran with PHP 7.2.11 and PHPUnit 8.1.3

  1. Create an upper level directory called devTest
  2. Create a subdirectory in devTest called src
  3. Create another subdirectory in devTest called tests
  4. Place devTest.php, devTest.json, and Car.php in the subdirectory src created in step 2
  5. Place CarTest.php in the subdirectory tests created in step 3
  6. Place phpunit.xml and composer.json in directory devTest created in step 1
  7. You need to copy a vendor folder into the devTest folder (needs to contain usual folders including phpunit and autoload.php)
  8. cd to folder devTest
  9. Run developer test as follows (Type in the command line): php src/devTest.php and follow the prompts

NOTE: if you run PHPUnit in a separate environment, please remove or modify my phpunit.xml file 8. Create an alias of phpunit to point to vendor/phpunit/phpunit/phpunit 9. Run unit tests as follows (Type in the command line): phpunit

[
{
"name": "3 Months\/3,000 Miles",
"terms": 3,
"miles": 3000
},
{
"name": "6 Months\/12,000 Miles",
"terms": 6,
"miles": 12000
},
{
"name": "12 Months\/24,000 Miles",
"terms": 12,
"miles": 24000
},
{
"name": "24 Months\/30,000 Miles",
"terms": 24,
"miles": 30000
},
{
"name": "24 Months\/36,000 Miles",
"terms": 24,
"miles": 36000
},
{
"name": "36 Months\/36,000 Miles",
"terms": 36,
"miles": 36000
},
{
"name": "36 Months\/45,000 Miles",
"terms": 36,
"miles": 45000
},
{
"name": "36 Months\/50,000 Miles",
"terms": 36,
"miles": 50000
},
{
"name": "48 Months\/50,000 Miles",
"terms": 48,
"miles": 50000
},
{
"name": "48 Months\/60,000 Miles",
"terms": 48,
"miles": 60000
},
{
"name": "60 Months\/72,000 Miles",
"terms": 60,
"miles": 72000
},
{
"name": "60 Months\/75,000 Miles",
"terms": 60,
"miles": 75000
},
{
"name": "72 Months\/100,000 Miles",
"terms": 72,
"miles": 100000
},
{
"name": "84 Months\/84,000 Miles",
"terms": 84,
"miles": 84000
},
{
"name": "84 Months\/96,000 Miles",
"terms": 84,
"miles": 96000
},
{
"name": "100 Months\/100,000 Miles",
"terms": 100,
"miles": 100000
},
{
"name": "100 Months\/120,000 Miles",
"terms": 100,
"miles": 120000
},
{
"name": "120 Months\/120,000 Miles",
"terms": 120,
"miles": 120000
}
]
<?php
/**
* PHP Developer Test 17
*
* Test a developers ability to create a class along with supporting methods.
* Test a developers ability to create unit tests to validate each methods logic.
*
* INSTRUCTIONS:
* --------------------------------------------------------------------
* Write a class which will validate if a vehicle can carry any of the warranty coverages in the $coverage array
*
* Rules:
* Book of Contracts should not have active contracts on vehicles where the mileage on the vehicle is > 153,000 miles before contract expires.
* Book of Contracts should not have active contracts on vehicles who's age is more than 12 years old + 3 months (147 months) before contract expires.
* Contract coverage should not be available if the term and miles of the coverage expire before the base warranty of the vehicle has expired.
*
* Test will validate each vehicle make in the $base_warranty array, each model year of the make in the $years array, and every issue mileage
* between 0 and 150,000 in 1,000 mile increments.
*
* Additionally, a "New" or "Used" flag will be assigned to the output based on the vehicle issue mileage where if the issue mileage falls within the
* base warranty, "New" value is assigned, otherwise a "Used" value is assigned.
*
* Output the following: make, model year, issue mileage, New or Used, coverage name, suffix1 (as a 2 digit zero fill left padded number),
* suffix2 and success/failure, indicating the reason for the failure. Failure message should include all validation failures.
*
* Example (for demonstration purposes):
* Test Values: make: BMW, model year: 2018, issue mileage: 1000; testing coverage: "3 Months/3,000 Miles"
* Example Output: BMW 2018 1000 NEW "3 Months/3,000 Miles" suffix1:00 suffix2:A RESULT: FAILURE array('Term expires before warranty', 'Miles expires before warranty');
*
* Test Values: make: BMW, model year: 2018, issue mileage: 1000; testing coverage: "100 Months/120,000 Miles"
* Example Output: BMW 2018 1000 NEW "100 Months/120,000 Miles" suffix1:00 suffix2:A RESULT: SUCCESS
*
* Convert the $coverage array to a json file, simulate an API call in a private method to pull the json file to create the coverage array.
*
* Make this a self contained script executable from a linux command line.
*
* phpunit test should be included as a separate file.
*
* Do not use built-in libraries or frameworks.
*
*/
date_default_timezone_set( "America/Chicago" );
const MAX_INPUT_MILEAGE = 150000;
const MIN_INPUT_MILEAGE = 0;
const INC_MILEAGE = 1000;
const MAX_MILEAGE = 153000;
// Class Car properties and methods
require "Car.php";
// Vehicle classification code based on make/model.
$classes = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
// Assumed base warranty of the vehicle make being tested. Both makes should be tested
$base_warranty = array(
array("make" => "BMW", "term" => 36, "miles" => 48000),
array("make" => "Volkswagen", "term" => 72, "miles" => 100000)
);
// vehicle model years to test
$years = array(
array("modelyear" => 2003, "suffix1" => 15),
array("modelyear" => 2004, "suffix1" => 14),
array("modelyear" => 2005, "suffix1" => 13),
array("modelyear" => 2006, "suffix1" => 12),
array("modelyear" => 2007, "suffix1" => 11),
array("modelyear" => 2008, "suffix1" => 10),
array("modelyear" => 2009, "suffix1" => 9),
array("modelyear" => 2010, "suffix1" => 8),
array("modelyear" => 2011, "suffix1" => 7),
array("modelyear" => 2012, "suffix1" => 6),
array("modelyear" => 2013, "suffix1" => 5),
array("modelyear" => 2014, "suffix1" => 4),
array("modelyear" => 2015, "suffix1" => 3),
array("modelyear" => 2016, "suffix1" => 2),
array("modelyear" => 2017, "suffix1" => 1),
array("modelyear" => 2018, "suffix1" => 0),
array("modelyear" => 2019, "suffix1" => 0));
// mileage of the vehicle at the time the contract is rated
$issue_mileage = array(
array("min" => 0, "max" => 12000, "suffix2" => "A"),
array("min" => 12001, "max" => 24000, "suffix2" => "A"),
array("min" => 24001, "max" => 36000, "suffix2" => "B"),
array("min" => 36001, "max" => 48000, "suffix2" => "C"),
array("min" => 48001, "max" => 60000, "suffix2" => "D"),
array("min" => 60001, "max" => 72000, "suffix2" => "E"),
array("min" => 72001, "max" => 84000, "suffix2" => "F"),
array("min" => 84001, "max" => 96000, "suffix2" => "G"),
array("min" => 96001, "max" => 108000, "suffix2" => "H"),
array("min" => 108001, "max" => 120000, "suffix2" => "I"),
array("min" => 120001, "max" => 132000, "suffix2" => "J"),
array("min" => 132001, "max" => 144000, "suffix2" => "K"),
array("min" => 144001, "max" => 150000, "suffix2" => "L")
);
// warranty coverage options
// terms = maximum length of time (in months) the contract is in force from the time of sale
// miles = maximum number of miles the warranty is in effect from the time of sale
//
// NOTE: This info will be read from a JSON file
//
/*$coverage = array(
array("name" => "3 Months/3,000 Miles", "terms" => 3, "miles" => 3000),
array("name" => "6 Months/12,000 Miles", "terms" => 6, "miles" => 12000),
array("name" => "12 Months/24,000 Miles", "terms" => 12, "miles" => 24000),
array("name" => "24 Months/30,000 Miles", "terms" => 24, "miles" => 30000),
array("name" => "24 Months/36,000 Miles", "terms" => 24, "miles" => 36000),
array("name" => "36 Months/36,000 Miles", "terms" => 36, "miles" => 36000),
array("name" => "36 Months/45,000 Miles", "terms" => 36, "miles" => 45000),
array("name" => "36 Months/50,000 Miles", "terms" => 36, "miles" => 50000),
array("name" => "48 Months/50,000 Miles", "terms" => 48, "miles" => 50000),
array("name" => "48 Months/60,000 Miles", "terms" => 48, "miles" => 60000),
array("name" => "60 Months/72,000 Miles", "terms" => 60, "miles" => 72000),
array("name" => "60 Months/75,000 Miles", "terms" => 60, "miles" => 75000),
array("name" => "72 Months/100,000 Miles", "terms" => 72, "miles" => 100000),
array("name" => "84 Months/84,000 Miles", "terms" => 84, "miles" => 84000),
array("name" => "84 Months/96,000 Miles", "terms" => 84, "miles" => 96000),
array("name" => "100 Months/100,000 Miles", "terms" => 100, "miles" => 100000),
array("name" => "100 Months/120,000 Miles", "terms" => 100, "miles" => 120000),
array("name" => "120 Months/120,000 Miles", "terms" => 120, "miles" => 120000)
);
*/
// Create a new instance of Car
$covered_car = new Car();
// This calls a method which simulates an API call to
// get devTest.json file and convert to $coverage array.
$url = "src/devTest.json"; //json data created from $coverage array
$coverage = $covered_car->getCoverageArray($url);
// Read and validate the input car make, car year, and car mileage from the command line
$covered_car->getCarInputValues($base_warranty,$years);
// Get base warranty info to be used in later calculations and validations
$covered_car->getBaseWarrantyInfo($base_warranty);
// Loop through the $coverage array to find which contracts can be successfully offered for this car
foreach ($coverage as $item) {
// Initialize some values, including those input
$covered_car->coverage_name = $item["name"];
$covered_car->coverage_terms = $item["terms"];
$covered_car->coverage_miles = $item["miles"];
$covered_car->errors = [];
// Calculate the following values for later output
$covered_car->condition = $covered_car->getCondition();
$covered_car->suffix1 = $covered_car->getSuffix1($years);
$covered_car->suffix2 = $covered_car->getSuffix2($issue_mileage);
// Run validations
$covered_car->checkContractTerms($item);
$covered_car->checkContractMileage($item);
$covered_car->checkAge($item);
$covered_car->checkMileage($item);
// Print car information
$output_values = $covered_car->getPrintValues();
echo $output_values;
// Print results of validation
$output_validation_results = $covered_car->getPrintValidationResults();
echo $output_validation_results."\r\n";
}
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
verbose="true"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment