-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from wmde/company-with-contact
Add CompanyContactName
- Loading branch information
Showing
10 changed files
with
155 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare( strict_types = 1 ); | ||
|
||
namespace WMDE\Fundraising\DonationContext\Domain\Model\Donor\Name; | ||
|
||
use WMDE\Fundraising\DonationContext\Domain\Model\DonorName; | ||
|
||
class CompanyContactName implements DonorName { | ||
|
||
public function __construct( | ||
private readonly string $companyName, | ||
private readonly string $firstName, | ||
private readonly string $lastName, | ||
private readonly string $salutation, | ||
private readonly string $title | ||
) { | ||
} | ||
|
||
public function getFullName(): string { | ||
$name = $this->companyName; | ||
|
||
if ( $this->title !== '' || $this->firstName !== '' || $this->lastName !== '' ) { | ||
$name .= ' - ' . implode( | ||
' ', | ||
array_filter( [ | ||
$this->title, | ||
$this->firstName, | ||
$this->lastName | ||
] ) | ||
); | ||
} | ||
|
||
return $name; | ||
} | ||
|
||
public function toArray(): array { | ||
return array_merge( [ | ||
'companyName' => $this->companyName, | ||
], | ||
array_filter( [ | ||
'salutation' => $this->salutation, | ||
'title' => $this->title, | ||
'firstName' => $this->firstName, | ||
'lastName' => $this->lastName | ||
] ) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace WMDE\Fundraising\DonationContext\Tests\Unit\Domain\Model; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use WMDE\Fundraising\DonationContext\Domain\Model\Donor\Name\CompanyContactName; | ||
|
||
/** | ||
* @covers \WMDE\Fundraising\DonationContext\Domain\Model\Donor\Name\CompanyContactName | ||
*/ | ||
class CompanyContactNameTest extends TestCase { | ||
|
||
public function testGivenCompanyNameOnly_getFullNameReturnsCompanyName(): void { | ||
$companyName = new CompanyContactName( 'Scrooge and Marley', '', '', '', '' ); | ||
|
||
$this->assertSame( 'Scrooge and Marley', $companyName->getFullName() ); | ||
} | ||
|
||
public function testGivenNameWithoutSalutation_getFullNameReturnsNameWithoutSalutation(): void { | ||
$companyName = new CompanyContactName( 'Scrooge and Marley', 'Ebenezer', 'Scrooge', '', '' ); | ||
|
||
$this->assertSame( 'Scrooge and Marley - Ebenezer Scrooge', $companyName->getFullName() ); | ||
} | ||
|
||
public function testGivenNameWithSalutation_getFullNameReturnsNameWithoutSalutation(): void { | ||
$companyName = new CompanyContactName( 'Scrooge and Marley', 'Ebenezer', 'Scrooge', 'Sir', '' ); | ||
|
||
$this->assertSame( 'Scrooge and Marley - Ebenezer Scrooge', $companyName->getFullName() ); | ||
} | ||
|
||
public function testGivenNameWithTitle_getFullNameReturnsNameWithTitle(): void { | ||
$companyName = new CompanyContactName( 'Scrooge and Marley', 'Ebenezer', 'Scrooge', '', 'Prof. Dr.' ); | ||
|
||
$this->assertSame( 'Scrooge and Marley - Prof. Dr. Ebenezer Scrooge', $companyName->getFullName() ); | ||
} | ||
|
||
public function testGivenNameWithTitleAndSalutation_getFullNameReturnsNameWithTitle(): void { | ||
$companyName = new CompanyContactName( 'Scrooge and Marley', 'Ebenezer', 'Scrooge', 'Herr', 'Prof. Dr.' ); | ||
|
||
$this->assertSame( 'Scrooge and Marley - Prof. Dr. Ebenezer Scrooge', $companyName->getFullName() ); | ||
} | ||
|
||
public function testGivenCompanyNameOnly_toArrayReturnsCompanyName(): void { | ||
$companyName = new CompanyContactName( 'Scrooge and Marley', '', '', '', '' ); | ||
|
||
$this->assertEquals( [ 'companyName' => 'Scrooge and Marley', ], $companyName->toArray() ); | ||
} | ||
|
||
public function testToArrayReturnsAllFields(): void { | ||
$companyName = new CompanyContactName( 'Scrooge and Marley', 'Ebenezer', 'Scrooge', 'Herr', 'Prof. Dr.' ); | ||
|
||
$this->assertEquals( | ||
[ | ||
'companyName' => 'Scrooge and Marley', | ||
'salutation' => 'Herr', | ||
'title' => 'Prof. Dr.', | ||
'firstName' => 'Ebenezer', | ||
'lastName' => 'Scrooge' | ||
], | ||
$companyName->toArray() | ||
); | ||
} | ||
|
||
} |