Skip to content

Commit

Permalink
Update Fun Validators dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Abban committed Jun 4, 2020
1 parent 66455fc commit 48a7dca
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"wmde/email-address": "~1.0",
"wmde/euro": "~1.0",
"wmde/freezable-value-object": "~1.0",
"wmde/fun-validators": "~1.2",
"wmde/fundraising-payments": "@dev"
"wmde/fun-validators": "~2.0.0",
"wmde/fundraising-payments": "~1.0.1"
},
"repositories": [
{
Expand All @@ -27,6 +27,11 @@
"type": "vcs",
"url": "https://github.com/wmde/fundraisingstore",
"no-api": true
},
{
"type": "vcs",
"url": "https://github.com/wmde/fun-validators",
"no-api": true
}
],
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion tests/Data/ValidDonation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ValidDonation {
public const DONOR_COMPANY = 'Fluffy Beings Ltd.';

public const DONOR_CITY = 'Berlin';
public const DONOR_POSTAL_CODE = '1234';
public const DONOR_POSTAL_CODE = '12345';
public const DONOR_COUNTRY_CODE = 'DE';
public const DONOR_STREET_ADDRESS = 'Nyan Street';

Expand Down
17 changes: 17 additions & 0 deletions tests/Data/ValidatorPatterns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types = 1);

namespace WMDE\Fundraising\DonationContext\Tests\Data;

class ValidatorPatterns {
public const COUNTRY_POSTCODE = [
'DE' => '/^[0-9]{5}$/',
'AT' => '/^[0-9]{4}$/',
'CH' => '/^[0-9]{4}$/',
'BE' => '/^[0-9]{4}$/',
'IT' => '/^[0-9]{5}$/',
'LI' => '/^[0-9]{4}$/',
'LU' => '/^[0-9]{4}$/',
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use WMDE\Euro\Euro;
use WMDE\Fundraising\DonationContext\Domain\Model\DonorName;
use WMDE\Fundraising\DonationContext\Tests\Data\ValidAddDonationRequest;
use WMDE\Fundraising\DonationContext\Tests\Data\ValidatorPatterns;
use WMDE\Fundraising\DonationContext\Tests\Data\ValidDonation;
use WMDE\Fundraising\DonationContext\UseCases\AddDonation\AddDonationValidationResult;
use WMDE\Fundraising\DonationContext\UseCases\AddDonation\AddDonationValidator;
Expand Down Expand Up @@ -246,7 +247,7 @@ private function newEmptyIbanBlocklist(): IbanBlocklist {
}

private function newAddressValidator(): AddressValidator {
return new AddressValidator();
return new AddressValidator( ValidatorPatterns::COUNTRY_POSTCODE );
}

}
9 changes: 5 additions & 4 deletions tests/Unit/UseCases/UpdateDonor/UpdateDonorValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace WMDE\Fundraising\DonationContext\Tests\Unit\UseCases\UpdateDonor;

use WMDE\Fundraising\DonationContext\Domain\Model\DonorName;
use WMDE\Fundraising\DonationContext\Tests\Data\ValidatorPatterns;
use WMDE\Fundraising\DonationContext\UseCases\UpdateDonor\UpdateDonorRequest;
use WMDE\Fundraising\DonationContext\UseCases\UpdateDonor\UpdateDonorValidator;
use PHPUnit\Framework\TestCase;
Expand All @@ -21,7 +22,7 @@
class UpdateDonorValidatorTest extends TestCase {

public function testGivenAnonymousDonor_validationFails() {
$validator = new UpdateDonorValidator( new AddressValidator(), new SucceedingEmailValidator() );
$validator = new UpdateDonorValidator( new AddressValidator( ValidatorPatterns::COUNTRY_POSTCODE ), new SucceedingEmailValidator() );
$request = ( new UpdateDonorRequest() )->withType( DonorName::PERSON_ANONYMOUS );

$result = $validator->validateDonorData( $request );
Expand Down Expand Up @@ -57,7 +58,7 @@ public function testGivenFailingDonorValidator_validationFails() {

public function testgivenEmptyDonorRequestValues_validationFails() {
$validator = new UpdateDonorValidator(
new AddressValidator(),
new AddressValidator( ValidatorPatterns::COUNTRY_POSTCODE ),
new EmailValidator( new SucceedingDomainNameValidator() )
);
$result = $validator->validateDonorData( $this->newEmptyUpdateDonorRequest() );
Expand All @@ -75,7 +76,7 @@ public function testgivenEmptyDonorRequestValues_validationFails() {

public function testGivenInvalidCompanyDonor_validationFails() {
$validator = new UpdateDonorValidator(
new AddressValidator(),
new AddressValidator( ValidatorPatterns::COUNTRY_POSTCODE ),
new EmailValidator( new SucceedingDomainNameValidator() )
);
$result = $validator->validateDonorData( $this->newInvalidUpdateCompanyDonorRequest() );
Expand Down Expand Up @@ -108,7 +109,7 @@ private function newInvalidUpdateCompanyDonorRequest(): UpdateDonorRequest {
->withType( DonorName::PERSON_COMPANY )
->withCompanyName( str_repeat( 'TEST', 26 ) )
->withStreetAddress( str_repeat( 'TEST', 26 ) )
->withPostalCode( str_repeat( '1', 10 ) )
->withPostalCode( str_repeat( '1', 17 ) )
->withCity( str_repeat( 'TEST', 26 ) )
->withCountryCode( str_repeat( 'TEST', 26 ) )
->withEmailAddress( '' );
Expand Down

0 comments on commit 48a7dca

Please sign in to comment.