summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Recipient/Contact.php35
-rw-r--r--src/Recipient/Group.php10
-rw-r--r--tests/Recipient/ContactTest.php20
-rw-r--r--tests/Recipient/GroupTest.php14
4 files changed, 61 insertions, 18 deletions
diff --git a/src/Recipient/Contact.php b/src/Recipient/Contact.php
index 3fd5c3d..b9c5dba 100644
--- a/src/Recipient/Contact.php
+++ b/src/Recipient/Contact.php
@@ -116,65 +116,72 @@ class Contact implements ProcessableComponentInterface
}
/**
* @param string $firstName Sets the first name of the contact.
- * @return void
+ * @return self
*/
- public function setFirstName(string $firstName) :void
+ public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
+ return $this;
}
/**
* @param ?string $lastName Sets the last name of the contact.
- * @return void
+ * @return self
*/
- public function setLastName(?string $lastName): void
+ public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
+ return $this;
}
/**
* @param string $phoneNumber Sets the phone number of the contact.
- * @return void
+ * @return self
*/
- public function setPhoneNumber(string $phoneNumber): void
+ public function setPhoneNumber(string $phoneNumber): self
{
$this->phone = $phoneNumber;
+ return $this;
}
/**
* @param ?string $title Sets the title of the contact.
- * @return void
+ * @return self
*/
- public function setTitle(?string $title): void
+ public function setTitle(?string $title): self
{
$this->title = $title;
+ return $this;
}
/**
* @param ?string $organization Sets the contact company or other organization the contact belongs to.
- * @return void
+ * @return self
*/
- public function setOrganization(?string $organization): void
+ public function setOrganization(?string $organization): self
{
$this->organization = $organization;
+ return $this;
}
/**
* @param ?string $email Sets the email adress of the contact.
- * @return void
+ * @return self
*/
- public function setEmail(?string $email): void
+ public function setEmail(?string $email): self
{
$this->email = $email;
+ return $this;
}
/**
* @param ?string $notes Sets the notes of the contact.
- * @return void
+ * @return self
*/
- public function setNotes(?string $notes): void
+ public function setNotes(?string $notes): self
{
$this->notes = $notes;
+ return $this;
}
/**
* @return string The contacts first name.
diff --git a/src/Recipient/Group.php b/src/Recipient/Group.php
index 0a5de89..474f270 100644
--- a/src/Recipient/Group.php
+++ b/src/Recipient/Group.php
@@ -64,29 +64,31 @@ class Group implements ProcessableComponentInterface
/**
* Sets the Group's name to the given string.
* @param string $name Name that the Group should have.
+ * @return self
* @throws \InvalidArgumentException When $name is empty.
- * @return void
*/
- public function setName(string $name):void
+ public function setName(string $name): self
{
if (empty($name)) {
throw new \InvalidArgumentException("Group name can not be empty");
}
$this->name = $name;
+ return $this;
}
/**
* Sets the groups color.
* @param string $color A hexadecimal color code.
* @example #5E5E5E
- * @return void
+ * @return self
* @throws \InvalidArgumentException When $color isn't a valid hexadecimal color.
*/
- public function setColor(string $color): void
+ public function setColor(string $color): self
{
if (!preg_match("/^#([A-Fa-f0-9]{6})$/", $color)) {
throw new \InvalidArgumentException($color. " is not a valid hexadecimal color");
}
$this->color = $color;
+ return $this;
}
/**
* Serializes the object to a value that can be serialized natively by json_encode().
diff --git a/tests/Recipient/ContactTest.php b/tests/Recipient/ContactTest.php
index 529c0b6..b246750 100644
--- a/tests/Recipient/ContactTest.php
+++ b/tests/Recipient/ContactTest.php
@@ -104,6 +104,26 @@ class ContactTest extends TestCase
$this->assertEquals($this->completeContactStd->Organization, $contact->getOrganization());
$this->assertEquals($this->completeContactStd->Notes, $contact->getNotes());
}
+ public function testMethodChaining()
+ {
+ $contact = RecipientFactory::createContactFromJSON($this->minimalContactString);
+
+ $contact->setFirstName("Lorem")
+ ->setLastName("Ipsum")
+ ->setTitle("dolor")
+ ->setOrganization("sit")
+ ->setPhoneNumber("12025550148")
+ ->setEmail("amet")
+ ->setNotes("Facilis dolores mea ut.");
+ $this->addToAssertionCount(7);
+ $this->assertEquals("Lorem", $contact->getFirstName());
+ $this->assertEquals("Ipsum", $contact->getLastName());
+ $this->assertEquals("dolor", $contact->getTitle());
+ $this->assertEquals("sit", $contact->getOrganization());
+ $this->assertEquals("12025550148", $contact->getPhoneNumber());
+ $this->assertEquals("amet", $contact->getEmail());
+ $this->assertEquals("Facilis dolores mea ut.", $contact->getNotes());
+ }
public function testGettersWithMembersNotSet()
{
$contact = RecipientFactory::createContactFromJSON($this->minimalContactString);
diff --git a/tests/Recipient/GroupTest.php b/tests/Recipient/GroupTest.php
index a305125..5beef29 100644
--- a/tests/Recipient/GroupTest.php
+++ b/tests/Recipient/GroupTest.php
@@ -35,6 +35,20 @@ class GroupTest extends TestCase
$this->assertEquals($color, $group->getColor());
}
+ /**
+ * @dataProvider getValidGroupInputs
+ */
+ public function testMethodChaining($name, $color)
+ {
+ $group = new Group("Jack", "#ffddff");
+ $group->setName($name)
+ ->setColor($color)
+ ->setName($name);
+
+ $this->assertEquals($name, $group->getName());
+
+ $this->assertEquals($color, $group->getColor());
+ }
public function getValidGroupInputs(): array
{
return [