Just take a look at the FormValidatorTest:
For the class
/**
* Provides validation of form submissions.
*/
class FormValidator implements FormValidatorInterface {
use StringTranslationTrait;
public function __construct(RequestStack $request_stack, TranslationInterface $string_translation, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, FormErrorHandlerInterface $form_error_handler) {
$this->requestStack = $request_stack;
$this->stringTranslation = $string_translation;
$this->csrfToken = $csrf_token;
$this->logger = $logger;
$this->formErrorHandler = $form_error_handler;
}
This is the test
/**
* Tests the 'validation_complete' $form_state flag.
*
* @covers ::validateForm
* @covers ::finalizeValidation
*/
public function testValidationComplete() {
$form_validator = $this->getMockBuilder('Drupal\Core\Form\FormValidator')
->setConstructorArgs([new RequestStack(), $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $this->formErrorHandler])
->setMethods(NULL)
->getMock();
$form = [];
$form_state = new FormState();
$this->assertFalse($form_state->isValidationComplete());
$form_validator->validateForm('test_form_id', $form, $form_state);
$this->assertTrue($form_state->isValidationComplete());
}
You can use as constructor param $this->getStringTranslationStub()