Ejemplo n.º 1
0
 /**
  *
  */
 public function testIncrementAge()
 {
     //Create an Object to test with.
     //We're creating an Animal object because the tested functionality is inherited by 'Dog' and 'Cat'
     $animal = new Animal('Animal', 1);
     //Speak once
     $animal->speak("test");
     //Our age should still be 1
     $this->assertEquals(1, $animal->age());
     //Speak twice
     $animal->speak("test");
     //Now our age should be 2
     $this->assertEquals(2, $animal->age());
 }
Ejemplo n.º 2
0
 /**
  *
  */
 public function testAverageLength()
 {
     //Create an Object with a random name to test with.
     $fakeName = substr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(0, 25), 1) . substr(md5(time()), 1);
     //We're creating an Animal object because the tested functionality is inherited by 'Dog' and 'Cat'
     $animal = new Animal('Named', 1);
     //Our average length should be 5
     $this->assertEquals(5, $animal->getAverageNameLength());
     //Get name with 7 characters
     $animal->setName('My Name');
     //Our average length should be 6
     $this->assertEquals(6, $animal->getAverageNameLength());
     //Get name with 9 characters
     $animal->setName('Long Name');
     //Our average length should be 15
     $this->assertEquals(7, $animal->getAverageNameLength());
 }