Skip to content

Commit

Permalink
update tests where exception is now thrown if no validation took place
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Jongsma authored and peterjaap committed Jan 27, 2021
1 parent fffde10 commit fea2bae
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions Test/Unit/Service/ValidateVatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Dutchento\Vatfallback\Test\Unit\Service;

use Dutchento\Vatfallback\Service\CleanNumberString;
use Dutchento\Vatfallback\Service\Exceptions\NoValidationException;
use Dutchento\Vatfallback\Service\Exceptions\ValidationDisabledException;
use Dutchento\Vatfallback\Service\Exceptions\ValidationFailedException;
use Dutchento\Vatfallback\Service\Exceptions\ValidationIgnoredException;
Expand Down Expand Up @@ -43,10 +44,9 @@ public function testByNumberAndCountryCallsCleanNumberStringWithoutValidators()
$cleanNumberString
);

$this->assertSame([
'result' => false,
'service' => 'None'
], $validateVat->byNumberAndCountry('123465', 'xx'));
$this->expectException(NoValidationException::class);

$validateVat->byNumberAndCountry('123465', 'xx');
}

public function testByNumberAndCountryExitAtFirstValidationIfInvalid()
Expand Down Expand Up @@ -155,6 +155,23 @@ public function testByNumberAndCountryFallback($result, $validators)
$this->assertSame($result, $validateVat->byNumberAndCountry('123456', 'xx'));
}

/**
* @param $result
* @param $validators
* @dataProvider dataProviderForFallbackWithExceptionScenarios
*/
public function testByNumberAndCountryFallbackWithException($result, $validators)
{
$validateVat = new ValidateVat(
$this->loggerInterfaceMock,
$this->cleanNumberStringMock,
$validators
);

$this->expectException(NoValidationException::class);
$validateVat->byNumberAndCountry('123456', 'xx');
}

/**
* Data provider for remote services test and offline
*
Expand Down Expand Up @@ -220,24 +237,34 @@ public function dataProviderForFallbackScenarios(): array
'regexp' => false
])
],
'R: [false, none]: 1: *, 2: -, 3: ?' => [
$this->createValidatorResult(false, 'None'),
'R: [false, vatlayer]: 1: *, 2: #, 3: ?' => [
$this->createValidatorResult(false, 'vatlayer'),
$this->createValidatorMock([
'vies' => $this->throwException(new ValidationDisabledException),
'vatlayer' => $this->throwException(new ValidationIgnoredException),
'vatlayer' => $this->throwException(new ValidationFailedException),
'regexp' => $this->throwException(new ValidationUnavailableException)
])
],
'R: [false, vatlayer]: 1: *, 2: #, 3: ?' => [
$this->createValidatorResult(false, 'vatlayer'),
];
}

/**
* Data provider for remote services test and offline where an exception is thrown
*
* @return array
*/
public function dataProviderForFallbackWithExceptionScenarios(): array
{
return [
'R: [false, none]: 1: *, 2: -, 3: ?' => [
$this->createValidatorResult(false, 'None'),
$this->createValidatorMock([
'vies' => $this->throwException(new ValidationDisabledException),
'vatlayer' => $this->throwException(new ValidationFailedException),
'vatlayer' => $this->throwException(new ValidationIgnoredException),
'regexp' => $this->throwException(new ValidationUnavailableException)
])
],
];

}

public function createValidatorResult($result, $service)
Expand Down

0 comments on commit fea2bae

Please sign in to comment.