/**
  * @param EntityManager $manager
  * @param array $addressData
  * @param AbstractDefaultTypedAddress $address
  */
 protected function addAddress(EntityManager $manager, array $addressData, AbstractDefaultTypedAddress $address)
 {
     $defaults = [];
     foreach ($addressData['types'] as $type => $isDefault) {
         /** @var AddressType $addressType */
         $addressType = $manager->getReference('Oro\\Bundle\\AddressBundle\\Entity\\AddressType', $type);
         $address->addType($addressType);
         if ($isDefault) {
             $defaults[] = $addressType;
         }
     }
     /** @var Country $country */
     $country = $manager->getReference('OroAddressBundle:Country', $addressData['country']);
     /** @var Region $region */
     $region = $manager->getReference('OroAddressBundle:Region', $addressData['country'] . '-' . $addressData['region']);
     $address->setDefaults($defaults);
     $address->setPrimary($addressData['primary'])->setStreet($addressData['street'])->setCity($addressData['city'])->setPostalCode($addressData['postalCode'])->setCountry($country)->setRegion($region);
     $manager->persist($address);
     $this->addReference($addressData['label'], $address);
 }
 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($this->addressEntityClass, $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());
 }
 /**
  * Constructor
  *
  * The real implementation of this method is auto generated.
  *
  * IMPORTANT: If the derived class has own constructor it must call parent constructor.
  */
 public function __construct()
 {
     parent::__construct();
 }