Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Created May 8, 2011 03:15
Show Gist options
  • Save al-the-x/961063 to your computer and use it in GitHub Desktop.
Save al-the-x/961063 to your computer and use it in GitHub Desktop.
OrlandoPHP Coding Dojo -- May 5, 2011
<?php
class Key {
private isValid = false;
}
class Car
{
protected $door_opened = false;
public function open_door() {
// if door is open, return false
if( $this->door_opened === true ) {
return false;
} else {
$this->door_opened = true;
return true;
}
}
public function checkLock(){
return true;
}
function giveValidKey ( $key )
{
if ($key->isValid == false){
$key->isValid = true;
}
return $this;
}
}
<?php
require_once 'PHPUnit/Framework.php';
require_once 'main.php';
class Test extends PHPUnit_Framework_TestCase
{
public function test_basic()
{
$var = new Car();
$this->assertTrue($var instanceof Car, 'This is not a car' );
}
public function test_has_a_door()
{
$var= new Car();
$this->assertTrue ($var->open_door(), 'The Door did not open');
$this->assertFalse ($var->open_door(), 'The Door was already open');
}
public function test_door_is_locked()
{
$aCar= new Car();
$this->assertTrue($aCar->checkLock(), 'The door is not locked');
}
public function test_useKey()
{
$key = new Key;
$hisCar = new Car();
$this->assertEquals($hisCar, $hisCar->giveKey($key));
$this->assertTrue($hisCar->open_door());
$this->assertTrue($hisCar->giveValidKey($key)->open_door(),
'Once I give it a key, I can open the door?');
}
public function giveValidKey()
{
$hisCar = new Car();
$this->assertFalse($key->isValid);
$hisCar->giveValidKey($key);
$this->assertTrue($key->isValid);
}
}
@al-the-x
Copy link
Author

al-the-x commented May 8, 2011

Here's the result of our hard work on May 5th, 2011. You can see we rambled a little here and there... But it sure was a lot of fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment