Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CS for Partner add tests and methods for payment profiles

  • Loading branch information...
commit 90aac07533095983a1cd569f36362769f69f42b7 1 parent 8a26ed8
@iampersistent iampersistent authored
View
113 lib/Vespolina/Entity/Partner/Partner.php
@@ -8,9 +8,8 @@
namespace Vespolina\Entity\Partner;
-use Doctrine\Common\Collections\ArrayCollection;
+use Vespolina\Entity\Partner\AddressInterface;
use Vespolina\Entity\Partner\PaymentProfileInterface;
-use ImmersiveLabs\CaraCore\Entity\User;
/**
* Implementation of PartnerInterface
@@ -21,11 +20,9 @@ class Partner implements PartnerInterface
{
const INDIVIDUAL = 'individual';
const ORGANISATION = 'organisation';
-
const ROLE_CUSTOMER = 'ROLE_CUSTOMER';
const ROLE_EMPLOYEE = 'ROLE_EMPLOYEE';
const ROLE_SUPPLIER = 'ROLE_SUPPLIER';
-
protected $addresses;
protected $currency;
protected $id;
@@ -36,18 +33,17 @@ class Partner implements PartnerInterface
protected $partnerId;
protected $partnerSince;
protected $paymentTerms;
+ protected $preferredPaymentProfile;
+ protected $paymentProfiles;
protected $personalDetails;
protected $primaryContact;
protected $roles;
protected $type;
- protected $preferredPaymentProfile;
- protected $paymentProfiles;
- protected $user;
public function __construct()
{
- $this->addresses = new ArrayCollection();
- $this->paymentProfiles = new ArrayCollection();
+ $this->addresses = array();
+ $this->paymentProfiles = array();
}
public function getId()
@@ -102,9 +98,9 @@ public function getRoles()
/**
* @inheritdoc
*/
- public function addRole($role)
+ public function setRoles($roles)
{
- $this->roles[] = $role;
+ $this->roles = $roles;
return $this;
}
@@ -112,9 +108,9 @@ public function addRole($role)
/**
* @inheritdoc
*/
- public function setRoles($roles)
+ public function addRole($role)
{
- $this->roles = $roles;
+ $this->roles[] = $role;
return $this;
}
@@ -248,7 +244,7 @@ public function setAddresses($addresses)
/**
* @inheritdoc
*/
- public function addAddress($address)
+ public function addAddress(AddressInterface $address)
{
$this->addresses[] = $address;
@@ -266,17 +262,17 @@ public function removeAddress($address)
/**
* @inheritdoc
*/
- public function getPrimaryContact()
+ public function getOrganisationDetails()
{
- return $this->primaryContact;
+ return $this->organisationDetails;
}
/**
* @inheritdoc
*/
- public function setPrimaryContact(ContactInterface $primaryContact)
+ public function setOrganisationDetails(OrganisationDetailsInterface $organisationDetails)
{
- $this->primaryContact = $primaryContact;
+ $this->organisationDetails = $organisationDetails;
return $this;
}
@@ -284,17 +280,17 @@ public function setPrimaryContact(ContactInterface $primaryContact)
/**
* @inheritdoc
*/
- public function getPersonalDetails()
+ public function getPaymentProfiles()
{
- return $this->personalDetails;
+ return $this->paymentProfiles;
}
/**
* @inheritdoc
*/
- public function setPersonalDetails($personalDetails)
+ public function setPaymentProfiles($paymentProfiles)
{
- $this->personalDetails = $personalDetails;
+ $this->paymentProfiles = $paymentProfiles;
return $this;
}
@@ -302,17 +298,20 @@ public function setPersonalDetails($personalDetails)
/**
* @inheritdoc
*/
- public function getOrganisationDetails()
+ public function addPaymentProfile($paymentProfile)
{
- return $this->organisationDetails;
+ $this->paymentProfiles[] = $paymentProfile;
+ $paymentProfile->setPartner($this);
+
+ return $this;
}
/**
* @inheritdoc
*/
- public function setOrganisationDetails($organisationDetails)
+ public function clearPaymentProfiles()
{
- $this->organisationDetails = $organisationDetails;
+ $this->paymentProfiles = array();
return $this;
}
@@ -320,67 +319,75 @@ public function setOrganisationDetails($organisationDetails)
/**
* @inheritdoc
*/
- public function getPaymentProfiles()
+ public function removePaymentProfile($paymentProfile)
{
- return $this->paymentProfiles;
+ foreach ($this->paymentProfiles as $key => $profile) {
+ if ($profile == $paymentProfile) {
+ unset($this->paymentProfiles[$key]);
+
+ return;
+ }
+ }
}
/**
* @inheritdoc
*/
- public function setPaymentProfiles($paymentProfiles)
+ public function setPreferredPaymentProfile(PaymentProfileInterface $paymentProfile)
{
- $this->paymentProfiles = $paymentProfiles;
+ $this->preferredPaymentProfile = $paymentProfile;
+ foreach ($this->paymentProfiles as $key => $profile) {
+ if ($profile == $paymentProfile) {
+
+ return $this;
+ }
+ }
+ $this->addPaymentProfile($paymentProfile);
return $this;
}
/**
- * @inheritdoc
+ * @return \Vespolina\Entity\Partner\PaymentProfileInterface
*/
- public function addPaymentProfile($paymentProfile)
+ public function getPreferredPaymentProfile()
{
- $this->paymentProfiles[] = $paymentProfile;
- $paymentProfile->setPartner($this);
-
- return $this;
+ return $this->preferredPaymentProfile;
}
/**
* @inheritdoc
*/
- public function removePaymentProfile($paymentProfile)
+ public function getPrimaryContact()
{
- unset($this->paymentProfiles[array_find($paymentProfile)]);
+ return $this->primaryContact;
}
- public function setPreferredPaymentProfile(PaymentProfileInterface $paymentProfile)
+ /**
+ * @inheritdoc
+ */
+ public function setPrimaryContact(ContactInterface $primaryContact)
{
- $this->preferredPaymentProfile = $paymentProfile;
+ $this->primaryContact = $primaryContact;
return $this;
}
/**
- * @return \Vespolina\Entity\Partner\PaymentProfileInterface
+ * @inheritdoc
*/
- public function getPreferredPaymentProfile()
- {
- return $this->preferredPaymentProfile;
- }
-
- public function setUser(User $user)
+ public function getPersonalDetails()
{
- $this->user = $user;
-
- return $this;
+ return $this->personalDetails;
}
/**
- * @return \ImmersiveLabs\CaraCore\Entity\User
+ * @inheritdoc
*/
- public function getUser()
+ public function setPersonalDetails($personalDetails)
{
- return $this->user;
+ $this->personalDetails = $personalDetails;
+
+ return $this;
}
}
View
221 lib/Vespolina/Entity/Partner/PartnerInterface.php
@@ -9,6 +9,7 @@
namespace Vespolina\Entity\Partner;
use Vespolina\Entity\Partner\ContactInterface;
+
/**
* Partner interface, define basic fields
*
@@ -17,149 +18,164 @@
interface PartnerInterface
{
/**
- * Sets the partnerId
+ * Sets the partners addresses
*
- * @param string $partnerId
+ * @param \Vespolina\Entity\Partner\Address[] $addresses
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function setPartnerId($partnerId);
+ function setAddresses($addresses);
/**
- * Functional partner id
+ * Adds a partners address
*
- * @return string
+ * @param \Vespolina\Entity\Partner\Address $address
+ * @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function getPartnerId();
+ function addAddress(AddressInterface $address);
/**
- * Date since when this partner joined
- * @param \DateTime $partnerSince
- * @return \Vespolina\Entity\Partner\PartnerInterface
+ * Addresses for this account
+ *
+ * @return \Vespolina\Entity\Partner\Address[]
*/
- function setPartnerSince(\DateTime $partnerSince);
-
+ function getAddresses();
+
/**
- * @return DateTime
+ * Sets the partners default currency (ISO-4217)
+ * @param string $currency
+ * @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function getPartnerSince();
+ function setCurrency($currency);
/**
- * THe role of the Partner (e.g. Customer, Supplier, Employee)
- * @return string
+ * Default currency for partner
+ *
+ * @return string - ISO-4217
*/
- function getRoles();
-
+ function getCurrency();
+
/**
- * Adds a role to the current Partner
- *
- * @param string $role
+ * Sets the partners default language
+ *
+ * @param string $language - IETF tag
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function addRole($role);
-
+ function setLanguage($language);
+
/**
- * Sets the roles of the partner
- *
- * @param array $roles
- * @return \Vespolina\Entity\Partner\PartnerInterface
+ * Default language for partner
+ *
+ * @return string - IETF tag
*/
- function setRoles($roles);
+ function getLanguage();
/**
* Sets the name of the partner
- *
+ *
* @param string $name
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
function setName($name);
-
+
/**
* Name for partner
- *
+ *
* @return string
*/
function getName();
/**
- * Sets the partners default currency (ISO-4217)
- * @param string $currency
+ * Sets the organisation details
+ *
+ * @param $organisationDetails
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function setCurrency($currency);
-
+ function setOrganisationDetails(OrganisationDetailsInterface $organisationDetails);
+
/**
- * Default currency for partner
- *
- * @return string - ISO-4217
+ * The organisation details for this partner (used for type organisation)
+ *
+ * @return \Vespolina\Entity\Partner\OrganisationDetailsInterface
*/
- function getCurrency();
-
+ function getOrganisationDetails();
+
/**
- * Sets the partners default language
- *
- * @param string $language - IETF tag
+ * Sets the partnerId
+ *
+ * @param string $partnerId
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function setLanguage($language);
-
+ function setPartnerId($partnerId);
+
/**
- * Default language for partner
- *
- * @return string - IETF tag
+ * Functional partner id
+ *
+ * @return string
*/
- function getLanguage();
-
+ function getPartnerId();
+
+ /**
+ * Date since when this partner joined
+ * @param \DateTime $partnerSince
+ * @return \Vespolina\Entity\Partner\PartnerInterface
+ */
+ function setPartnerSince(\DateTime $partnerSince);
+
+ /**
+ * @return \DateTime
+ */
+ function getPartnerSince();
+
/**
* Sets the default payment terms for customer
- *
+ *
* @param string $paymentTerms
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
function setPaymentTerms($paymentTerms);
-
+
/**
* Default payment terms for partner
*/
function getPaymentTerms();
-
+
/**
- * Sets the partners type
- *
- * @param string $type
+ * Sets the personal details for this partner
+ *
+ * @param $personalDetails
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function setType($type);
-
+ function setPersonalDetails($personalDetails);
+
/**
- * Discriminator field
- *
- * @return string
+ * Personal details of partner (used for type individual)
+ *
+ * @return \Vespolina\Entity\Partner\PersonalDetailsInterface
*/
- function getType();
-
+ function getPersonalDetails();
+
/**
- * Sets the partners addresses
- *
- * @param \Vespolina\Entity\Partner\Address[] $addresses
- * @return \Vespolina\Entity\Partner\PartnerInterface
+ * Clear all of the payment profiles
+ *
+ * @return $this
*/
- function setAddresses($addresses);
-
+ function clearPaymentProfiles();
+
/**
- * Adds a partners address
- *
- * @param \Vespolina\Entity\Partner\Address $address
- * @return \Vespolina\Entity\Partner\PartnerInterface
+ * Set the preferred payment profile
+ *
+ * @param \Vespolina\Entity\Partner\PaymentProfileInterface $paymentProfile
+ * @return $this
*/
- function addAddress($address);
-
+ function setPreferredPaymentProfile(PaymentProfileInterface $paymentProfile);
+
/**
- * Addresses for this account
- *
- * @return \Vespolina\Entity\Partner\Address[]
+ * Return the preferred payment profile
+ *
+ * @return \Vespolina\Entity\Partner\PaymentProfileInterface
*/
- function getAddresses();
-
+ function getPreferredPaymentProfile();
+
/**
* Sets the partners primary contact
*
@@ -174,34 +190,41 @@ function setPrimaryContact(ContactInterface $contact);
* @return \Vespolina\Entity\Partner\Contact
*/
function getPrimaryContact();
-
+
/**
- * Sets the personal details for this partner
- *
- * @param $personalDetails
+ * THe role of the Partner (e.g. Customer, Supplier, Employee)
+ * @return string
+ */
+ function getRoles();
+
+ /**
+ * Adds a role to the current Partner
+ *
+ * @param string $role
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function setPersonalDetails($personalDetails);
-
+ function addRole($role);
+
/**
- * Personal details of partner (used for type individual)
- *
- * @return \Vespolina\Entity\Partner\PersonalDetailsInterface
+ * Sets the roles of the partner
+ *
+ * @param array $roles
+ * @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function getPersonalDetails();
-
+ function setRoles($roles);
+
/**
- * Sets the organistaion details
- *
- * @param $organisationDetails
+ * Sets the partners type
+ *
+ * @param string $type
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function setOrganisationDetails($organisationDetails);
-
+ function setType($type);
+
/**
- * The organistaion details for this partner (used for type organisation)
- *
- * @return \Vespolina\Entity\Partner\OrganisationDetailsInterface
+ * Discriminator field
+ *
+ * @return string
*/
- function getOrganisationDetails();
+ function getType();
}
View
51 tests/Entity/Partner/PartnerTest.php
@@ -6,15 +6,60 @@
* with this source code in the file LICENSE.
*/
-use Vespolina\Entity\Partner\Partner;
use Vespolina\Entity\Partner\Address;
+use Vespolina\Entity\Partner\Partner;
+use Vespolina\Entity\Partner\PaymentProfile;
class PartnerTest extends \PHPUnit_Framework_TestCase
{
- // todo: payment profile (cc profile)
public function testPaymentProfileMethods()
{
- $this->markTestIncomplete('tests for payment profiles (including cc) need to be written and implemented');
+ $partner = new Partner();
+ $this->assertEmpty($partner->getPaymentProfiles(), 'make sure we start out empty');
+
+ $paymentProfile = new PaymentProfile();
+ $paymentProfile->setReference('ref');
+ $partner->addPaymentProfile($paymentProfile);
+ $this->assertContains($paymentProfile, $partner->getPaymentProfiles());
+ $this->assertCount(1, $partner->getPaymentProfiles());
+ $this->assertSame($partner, $paymentProfile->getPartner(), 'the partner should be set in the paymentProfile');
+
+ $paymentProfiles = array();
+ $paymentProfiles[] = new PaymentProfile();
+ $paymentProfiles[] = new PaymentProfile();
+
+ $partner->addPaymentProfile($paymentProfile);
+ $partner->setPaymentProfiles($paymentProfiles);
+ $this->assertNotContains($paymentProfile, $partner->getPaymentProfiles(), 'this should have been removed on setting a new array of paymentProfiles');
+ $this->assertCount(2, $partner->getPaymentProfiles());
+
+ $partner->removePaymentProfile($paymentProfile);
+ $this->assertNotContains($paymentProfile, $partner->getPaymentProfiles());
+ $this->assertCount(2, $partner->getPaymentProfiles());
+
+ $partner->clearPaymentProfiles();
+ $this->assertEmpty($partner->getPaymentProfiles());
+ }
+
+ public function testSetPreferredPaymentProfile()
+ {
+ $partner = new Partner();
+
+ $paymentProfile = new PaymentProfile();
+ $paymentProfile->setReference('profile1');
+ $partner->setPreferredPaymentProfile($paymentProfile);
+
+ $this->assertSame($paymentProfile, $partner->getPreferredPaymentProfile());
+ $this->assertContains($paymentProfile, $partner->getPaymentProfiles(), 'a profile should have been added to the collection of profiles');
+
+ $paymentProfile2 = new PaymentProfile();
+ $paymentProfile2->setReference('profile2');
+ $partner->addPaymentProfile($paymentProfile2);
+ $this->assertCount(2, $partner->getPaymentProfiles());
+
+ $partner->setPreferredPaymentProfile($paymentProfile2);
+ $this->assertSame($paymentProfile2, $partner->getPreferredPaymentProfile());
+ $this->assertCount(2, $partner->getPaymentProfiles());
}
public function testFluentInterface()
Please sign in to comment.
Something went wrong with that request. Please try again.