Permalink
Browse files

HelloWorld#addressSomeoneWithSalutation will attempt to address a per…

…son by looking at their gender. PhpSpec will complain because HelloWorld uses Person#isMale, but it has not been stubbed in the HelloWorldSpec
  • Loading branch information...
peterjmit committed May 1, 2013
1 parent 27e4316 commit d03dd5aae4dfb4611ff04c4f35664cfd67d82704
Showing with 57 additions and 0 deletions.
  1. +11 −0 spec/HelloWorldSpec.php
  2. +14 −0 spec/PersonSpec.php
  3. +14 −0 src/HelloWorld.php
  4. +18 −0 src/Person.php
View
@@ -26,4 +26,15 @@ function it_should_say_hello_to_someone($person)
$this->sayHelloToSomeone($person)->shouldReturn('Hello Steve');
}
/**
* @param Person $person
*/
function it_should_address_someone_with_a_gender_specific_salutation($person)
{
$person->getName()->willReturn('Jane');
$person->isFemale()->willReturn(true);
$this->addressSomeoneWithSalutation($person)->shouldReturn('Hello Ms Jane');
}
}
View
@@ -18,4 +18,18 @@ function it_should_have_a_name()
$this->getName()->shouldReturn('test');
}
function it_should_be_male()
{
$this->setGender('male');
$this->shouldBeMale();
}
function it_should_be_female()
{
$this->setGender('female');
$this->shouldBeFemale();
}
}
View
@@ -11,4 +11,18 @@ public function sayHelloToSomeone(Person $person)
{
return $this->sayHello() . ' ' . $person->getName();
}
public function addressSomeoneWithSalutation(Person $person)
{
if ($person->isMale()) {
$salutation = 'Mr. ';
} else if ($person->isFemale()) {
$salutation = 'Ms. ';
} else {
// gender in-specific salutation
$salutation = '';
}
return 'Dear ' . $salutation . $person->getName();
}
}
View
@@ -2,6 +2,9 @@
class Person
{
private $name;
private $gender;
public function setName($name)
{
$this->name = $name;
@@ -11,4 +14,19 @@ public function getName()
{
return $this->name;
}
public function setGender($gender)
{
$this->gender = $gender;
}
public function isMale()
{
return $this->gender === 'male';
}
public function isFemale()
{
return $this->gender === 'female';
}
}

0 comments on commit d03dd5a

Please sign in to comment.