. */ namespace App\Tests\Validator\Constraints; use App\Entity\Attachments\AttachmentType; use App\Validator\Constraints\Selectable; use App\Validator\Constraints\SelectableValidator; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Exception\UnexpectedValueException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; class SelectableValidatorTest extends ConstraintValidatorTestCase { protected function createValidator(): SelectableValidator { return new SelectableValidator(); } public function testNullIsValid(): void { $this->validator->validate(null, new Selectable()); $this->assertNoViolation(); } public function testExpectAbstractStructuralElement(): void { $this->expectException(UnexpectedValueException::class); $this->validator->validate('test', new Selectable()); } public function testWithSelectableObj(): void { $selectable_obj = new AttachmentType(); $selectable_obj->setNotSelectable(false); $this->validator->validate($selectable_obj, new Selectable()); $this->assertNoViolation(); } public function testWithNotSelectableObj(): void { $selectable_obj = new AttachmentType(); $selectable_obj->setNotSelectable(true); $selectable_obj->setName('Test'); $this->validator->validate($selectable_obj, new Selectable()); $this->buildViolation('validator.isSelectable') ->setParameter('{{ name }}', 'Test') ->setParameter('{{ full_path }}', 'Test') ->assertRaised(); } }