private function assertBindingValid(BindingDescriptor $bindingDescriptor) { if ($bindingDescriptor->isTypeNotFound() || $bindingDescriptor->isTypeNotEnabled()) { return; } foreach ($bindingDescriptor->getViolations() as $violation) { switch ($violation->getCode()) { case ConstraintViolation::NO_SUCH_PARAMETER: throw NoSuchParameterException::forParameterName($violation->getParameterName(), $violation->getTypeName()); case ConstraintViolation::MISSING_PARAMETER: throw MissingParameterException::forParameterName($violation->getParameterName(), $violation->getTypeName()); } } }
public function testParametersNotValidatedIfTypeNotEnabled() { $type = new BindingTypeDescriptor('vendor/type', null, array(new BindingParameterDescriptor('param', BindingParameterDescriptor::REQUIRED))); $type->load($this->package); $type->markDuplicate(true); // Parameter is missing $binding = new BindingDescriptor('/path', 'vendor/type'); $binding->load($this->package, $type); $this->assertSame(BindingState::TYPE_NOT_ENABLED, $binding->getState()); $this->assertCount(0, $binding->getViolations()); }