Skip to content

Instantly share code, notes, and snippets.

@hungtrinh
Last active November 3, 2019 14:32
Show Gist options
  • Save hungtrinh/aa9771ae3e8f45a0f2c8f67b60a92f29 to your computer and use it in GitHub Desktop.
Save hungtrinh/aa9771ae3e8f45a0f2c8f67b60a92f29 to your computer and use it in GitHub Desktop.
Write Production Without Test
<?php
function discountRateByMembershipType($userId) {
//$date = getCurrentDateFromLocalTimeOrRemoteTimeServer(); //with remote time server, we can't fake date
//if (is_not_black_friday($date) return 0; // we can't not test CORE BUSINESS if add this spec
$membershipType = getMemberShipTypeFromDatabaseOrRemoteApi($userId);
//CORE BUSINESS need coverage by unit test or manual test 
if ('platinum' === $membershipType) return 0.15;
if ('gold' === $membershipType) return 0.1;
if ('slive' === $membershipType) return 0.05;
throw new UnknowMembershipTypeException('invalid membership type');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment