symfony_example_app/tests/Validator/CurrencyValidatorTest.php
Ondrej Vlach 1437ce4558
feat: add CurrencyValidator
fix: add CurrencyValidator

CurrencyValidator

zarad
2024-01-17 19:11:44 +01:00

34 lines
1.1 KiB
PHP

<?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);
}
}