ebs/tests/Functional/ChoiceFormFieldTrait.php
2023-12-21 08:49:38 +01:00

27 lines
594 B
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Functional;
use Symfony\Component\DomCrawler\Field\ChoiceFormField;
use Symfony\Component\DomCrawler\Form;
trait ChoiceFormFieldTrait
{
public function tick(Form $form, string $fieldName, bool $tick = true): self
{
$field = $form[$fieldName] ?? null;
if (!$field instanceof ChoiceFormField) {
throw new \InvalidArgumentException('Invalid choice field.');
}
if ($tick) {
$field->tick();
} else {
$field->untick();
}
return $this;
}
}