/**
  * Checks if the passed value is valid.
  *
  * @param FileDescriptor|ClassDescriptor|InterfaceDescriptor|TraitDescriptor $value      The value that should
  *     be validated.
  * @param Constraint                                                         $constraint The constraint for
  *     the validation.
  *
  * @throws ConstraintDefinitionException if this is not a constraint on a PropertyDescriptor object.
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof FileDescriptor && !$value instanceof ClassDescriptor && !$value instanceof InterfaceDescriptor && !$value instanceof TraitDescriptor) {
         throw new ConstraintDefinitionException('The HasPackageWithSubpackageValidator validator may only be used on files, classes, ' . 'interfaces and traits');
     }
     if ($value->getTags()->get('subpackage', new Collection())->count() > 0 && !$value->getPackage()) {
         $this->context->addViolationAt('package', $constraint->message);
     }
 }
 /**
  * @covers phpDocumentor\Descriptor\TraitDescriptor::setPackage
  */
 public function testSettingAndGettingPackage()
 {
     $package = new \phpDocumentor\Descriptor\PackageDescriptor();
     $mockPropertyDescriptor = m::mock('phpDocumentor\\Descriptor\\PropertyDescriptor');
     $mockPropertyDescriptor->shouldReceive('setPackage')->with($package);
     $mockMethodDescriptor = m::mock('phpDocumentor\\Descriptor\\MethodDescriptor');
     $mockMethodDescriptor->shouldReceive('setPackage')->with($package);
     $propertyCollection = new Collection(array($mockPropertyDescriptor));
     $methodCollection = new Collection(array($mockMethodDescriptor));
     $this->fixture->setProperties($propertyCollection);
     $this->fixture->setMethods($methodCollection);
     $this->fixture->setPackage($package);
     $this->assertSame($package, $this->fixture->getPackage());
 }