objectManager->get(SettingsValidator::class)->validate(new TestObject()); $this->assertTrue($result->hasErrors()); $this->assertCount(1, $result->getFlattenedErrors()); $this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors()); } /** * @test * @throws InvalidValidationConfigurationException * @throws InvalidValidationOptionsException * @throws NoSuchValidatorException */ public function conjunctionValidationWorksAsExpected(): void { $result = $this->objectManager ->get(ValidatorResolver::class) ->getBaseValidatorConjunction(TestObject::class) ->validate(new TestObject()); $this->assertTrue($result->hasErrors()); $this->assertCount(1, $result->getFlattenedErrors()); } /** * @test * @throws InvalidValidationOptionsException */ public function defaultValidationGroupWorks(): void { $result = $this->objectManager ->get(SettingsValidator::class, ['validationGroups' => ['Default']]) ->validate(new TestValidationGroupsDefaultObject()); $this->assertTrue($result->hasErrors(), 'No errors for validation group "Default"'); $this->assertCount(1, $result->getFlattenedErrors(), 'Got a non expected number of errors for group "Default"'); $this->assertCount(1, $result->forProperty('shouldBeTrue')->getErrors(), 'Got no error for property'); } /** * @test * @throws InvalidValidationOptionsException */ public function customValidationGroupWorks(): void { $result = $this->objectManager ->get(SettingsValidator::class, ['validationGroups' => ['Custom']]) ->validate(new TestValidationGroupsCustomObject()); $this->assertTrue($result->hasErrors(), 'No errors for validation group "Custom"'); $this->assertCount(1, $result->getFlattenedErrors(), 'Got a non expected number of errors for group "Custom"'); $this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors(), 'Got no error for property'); } }