getConstraint(); $personHasCenter = (new Person())->setCenter(new Center()); $personNoCenter = new Person(); $this->validator->validate($personHasCenter, $constraint); $this->assertNoViolation(); $this->validator->validate($personNoCenter, $constraint); $this->buildViolation('msg') ->atPath('property.path.center') ->assertRaised(); } protected function getConstraint() { return new PersonHasCenter([ 'message' => 'msg' ]); } protected function createValidator() { $parameterBag = $this->createMock(ParameterBagInterface::class); $parameterBag ->method('get') ->with($this->equalTo('chill_person')) ->willReturn([ 'validation' => [ 'center_required' => true ] ]); $centerResolverDispatcher = $this->createMock(CenterResolverDispatcherInterface::class); return new PersonHasCenterValidator($parameterBag, $centerResolverDispatcher); } }