*/ #[CoversClass(\App\Validator\Constraints\Project::class)] #[CoversClass(ProjectValidator::class)] class ProjectValidatorTest extends ConstraintValidatorTestCase { protected function createValidator(): ProjectValidator { $loader = $this->createMock(ConfigLoaderInterface::class); $config = SystemConfigurationFactory::create($loader, []); $repository = $this->createMock(ProjectRepository::class); return new ProjectValidator($config, $repository); } public function testConstraintIsInvalid(): void { $this->expectException(UnexpectedTypeException::class); $this->validator->validate('foo', new NotBlank()); } public function testEndBeforeStartIsInvalid(): void { $begin = new \DateTime(); $end = new \DateTime('-1 hour'); $project = new Project(); $project->setStart($begin); $project->setEnd($end); $this->validator->validate($project, new ProjectConstraint()); $this->buildViolation('End date must not be earlier then start date.') ->atPath('property.path.end') ->setCode(ProjectConstraint::END_BEFORE_BEGIN_ERROR) ->assertRaised(); } public function testGetTargets(): void { $constraint = new ProjectConstraint(); self::assertEquals('class', $constraint->getTargets()); } }