Last active
August 29, 2015 14:24
-
-
Save andrewrcollins/0dc35ff12e90b316b1b1 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* PHPUnit Tests. | |
**/ | |
/** | |
* @todo implement true autoloader | |
**/ | |
include 'PersonName.php'; |
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
<?php | |
/** | |
* First Code Sample. | |
* | |
* Make a class which you would pass the components of someone's name | |
* (first name, last name) to the constructor, and have two functions | |
* callable off of the object: | |
* | |
* 1. Simply print out the whole name, i.e. "John Smith" | |
* 2. Print out the name in phone book fashion, i.e. "Smith, John" | |
* | |
* (Don't worry about validating empty strings.) | |
**/ | |
/** | |
* PersonName represents a person's name. | |
* | |
* @author Andrew Collins <andrew@dripsandcastle.com> | |
**/ | |
class PersonName | |
{ | |
/** | |
* @var string Person's first name. | |
**/ | |
private $firstName; | |
/** | |
* @var string Person's last name. | |
**/ | |
private $lastName; | |
/** | |
* Create a new PersonName. | |
* | |
* @param string $firstName Person's first name. | |
* @param string $lastName Person's last name. | |
**/ | |
public function __construct($firstName, $lastName) | |
{ | |
$this->firstName = $firstName; | |
$this->lastName = $lastName; | |
} | |
/** | |
* Print out person's full name. | |
* | |
* Print out person's full name, i.e. "John Smith". | |
**/ | |
public function printFullName() | |
{ | |
$fullName = $this->firstName.' '.$this->lastName; | |
echo $fullName; | |
} | |
/** | |
* Print out person's name in phone book fashion. | |
* | |
* Print out person's name in phone book fashion, i.e. "Smith, John". | |
**/ | |
public function printPhoneBook() | |
{ | |
$phoneBook = $this->lastName.', '.$this->firstName; | |
echo $phoneBook; | |
} | |
} |
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
<?php | |
/** | |
* PHPUnit Tests. | |
**/ | |
/** | |
* PersonNameTest. | |
**/ | |
class PersonNameTest extends PHPUnit_Framework_TestCase | |
{ | |
/** | |
* Test printFullName(). | |
**/ | |
public function testFullName() | |
{ | |
$personName = new PersonName('Andrew', 'Collins'); | |
$fullName = $personName->printFullName(); | |
$this->assertEquals('Andrew Collins', $fullName); | |
} | |
/** | |
* Test printPhoneBook(). | |
**/ | |
public function testPhoneBook() | |
{ | |
$personName = new PersonName('Andrew', 'Collins'); | |
$phoneBook = $personName->printPhoneBook(); | |
$this->assertEquals('Collins, Andrew', $phoneBook); | |
} | |
} |
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
<phpunit bootstrap="bootstrap.php"></phpunit> |
Add PHPUnit tests. Though, current PersonName
class methods print strings rather than return strings.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Flesh out PersonName class.