public function testSetDefaults()
 {
     $types = new ArrayCollection([$this->billingType, $this->shippingType]);
     $this->assertCount(0, $this->address->getDefaults());
     $this->address->setTypes($types);
     $this->assertCount(0, $this->address->getDefaults());
     $this->assertInstanceOf('OroB2B\\Bundle\\CustomerBundle\\Entity\\CustomerAddress', $this->address->setDefaults([$this->billingType]));
     $this->assertCount(1, $this->address->getDefaults());
     $this->address->setDefaults([$this->billingType, $this->shippingType]);
     $this->assertCount(2, $this->address->getDefaults());
     $this->address->setTypes(new ArrayCollection([$this->billingType]));
     $this->assertCount(0, $this->address->getDefaults());
     $this->address->setDefaults([$this->shippingType]);
     $this->assertCount(0, $this->address->getDefaults());
 }
 /**
  * Only one address must have one default address per type.
  *
  * @param CustomerAddress $address
  * @param CustomerAddress[] $allAddresses
  */
 protected function handleDefaultType(CustomerAddress $address, $allAddresses)
 {
     /** @var Collection|AddressType[] $addressDefaults */
     $addressDefaults = $address->getDefaults();
     foreach ($allAddresses as $otherAddresses) {
         if ($address === $otherAddresses) {
             continue;
         }
         $otherAddressDefaults = $otherAddresses->getDefaults();
         foreach ($addressDefaults as $addressDefaultType) {
             foreach ($otherAddressDefaults as $otherAddressDefault) {
                 if ($otherAddressDefault->getName() === $addressDefaultType->getName() && $otherAddressDefaults->contains($otherAddressDefault)) {
                     $otherAddressDefaults->removeElement($otherAddressDefault);
                 }
             }
         }
         $otherAddresses->setDefaults($otherAddressDefaults);
     }
 }