feat: add CurrencyValidator
fix: add CurrencyValidator CurrencyValidator zarad
This commit is contained in:
33
tests/Validator/CurrencyValidatorTest.php
Normal file
33
tests/Validator/CurrencyValidatorTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Validator;
|
||||
|
||||
use App\Service\CurrencyListerInterface;
|
||||
use App\Validator\Currency;
|
||||
use App\Validator\CurrencyValidator;
|
||||
|
||||
class CurrencyValidatorTest extends ValidatorTestCase
|
||||
{
|
||||
public function testSuccess(): void {
|
||||
$currencyValidator = $this->createCurrencyValidator();
|
||||
$currencyValidator->initialize($this->createExecutionContext(false));
|
||||
|
||||
$currencyValidator->validate('USD', new Currency(['message' => 'foo']));
|
||||
}
|
||||
|
||||
public function testFailure(): void {
|
||||
$currencyValidator = $this->createCurrencyValidator();
|
||||
$currencyValidator->initialize($this->createExecutionContext(true));
|
||||
$currencyValidator->validate('EUR', new Currency(['message' => 'foo']));
|
||||
}
|
||||
|
||||
private function createCurrencyValidator(): CurrencyValidator {
|
||||
$mock = $this->createMock(CurrencyListerInterface::class);
|
||||
$mock->expects($this->once())
|
||||
->method('getCurrencies')
|
||||
->will($this->returnValue(['USD', 'CZK']));
|
||||
|
||||
return new CurrencyValidator($mock);
|
||||
}
|
||||
}
|
||||
19
tests/Validator/ValidatorTestCase.php
Normal file
19
tests/Validator/ValidatorTestCase.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Validator;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
abstract class ValidatorTestCase extends TestCase
|
||||
{
|
||||
protected function createExecutionContext(bool $violation): ExecutionContextInterface {
|
||||
$expected = $violation ? $this->once() : $this->never();
|
||||
|
||||
$context = $this->createMock(ExecutionContextInterface::class);
|
||||
$context->expects($expected)
|
||||
->method('buildViolation');
|
||||
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user