Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix devision by zero PHP notice #27

Merged
merged 2 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/UseCases/ValidateMembershipFee/ValidateFeeResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class ValidateFeeResult {

public const ERROR_TOO_LOW = 'error-too-low';
public const ERROR_INTERVAL_INVALID = 'error-interval-invalid';

private $errorCode;

Expand All @@ -18,6 +19,10 @@ public static function newTooLowResponse(): self {
return self::newErrorResponse( self::ERROR_TOO_LOW );
}

public static function newIntervalInvalidResponse(): self {
return self::newErrorResponse( self::ERROR_INTERVAL_INVALID );
}

private static function newErrorResponse( string $errorCode ): self {
$result = new self();
$result->errorCode = $errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public function validate( ValidateFeeRequest $request ): ValidateFeeResult {
$this->paymentIntervalInMonths = $request->getPaymentIntervalInMonths();
$this->applicantType = $request->getApplicantType();

if ( $this->paymentIntervalInMonths < 1 ) {
return ValidateFeeResult::newIntervalInvalidResponse();
}

if ( $this->getYearlyPaymentAmount() < $this->getYearlyPaymentRequirement() ) {
return ValidateFeeResult::newTooLowResponse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,30 @@ public function testGivenInvalidCompanyAmount_validationFails(): void {
);
}

public function testGivenInvalidInterval_zero_validationFails() {
$useCase = $this->newUseCase();

$response = $useCase->validate(
ValidateFeeRequest::newInstance()
->withFee( Euro::newFromString( '12.34' ) )
->withApplicantType( ValidateFeeRequest::PERSON_APPLICANT )
->withInterval( 0 )
);

$this->assertSame( ValidateFeeResult::ERROR_INTERVAL_INVALID, $response->getErrorCode() );
}

public function testGivenInvalidInterval_negative_validationFails() {
$useCase = $this->newUseCase();

$response = $useCase->validate(
ValidateFeeRequest::newInstance()
->withFee( Euro::newFromString( '12.34' ) )
->withApplicantType( ValidateFeeRequest::PERSON_APPLICANT )
->withInterval( -1 )
);

$this->assertSame( ValidateFeeResult::ERROR_INTERVAL_INVALID, $response->getErrorCode() );
}

}